Class: Geom::BoundingBox

Inherits:
Object show all
Defined in:
lib/boundingbox.rb

Overview

Note:

The bounding box returned for Face Me components is the center of its entire range of motion. This behavior changed in SketchUp 7.1. In 7.0 and earlier, the Sketchup::Drawingelement.#bounds method would return the bounds around the Face Me component's current, visible center.

Bounding boxes are three-dimensional boxes (eight corners), aligned with the global axes, that surround entities within your model. There is a default bounding box for any new model that will surround all entities, including all groups and components. Additionally, there are bounding boxes for Sketchup::Drawingelement objects, including components and groups. Bounding boxes are only large enough to exactly bound the entities within your model, group, or component.

You can also create arbitrary BoundingBox objects by calling BoundingBox.new.

Examples:

# You can get the bounding box on a model.
model = Sketchup.active_model
model_bb = model.bounds

# Or you can get the bounding box on any Drawingelement object.
first_entity = model.entities[0]
first_entity_bb = first_entity.bounds

# Or you can create an empty bounding box of your own.
bounding_box = Geom::BoundingBox.new

See Also:

Since:

  • SketchUp 6.0

Instance Method Summary collapse

Constructor Details

#initializeBoundingBox

Create a new, empty, bounding box.

Examples:

bounding_box = Geom::BoundingBox.new

Since:

  • SketchUp 6.0



40
41
# File 'lib/boundingbox.rb', line 40

def initialize
end

Instance Method Details

#add(*args) ⇒ Geom::BoundingBox

Add a point, vertex, or other bounding boxes to the bounding box. The size of the bounding box will increase as necessary to accommodate the new items.

Adding one point to an empty bounding box does not increase the size of the bounding box. You must add at least two points before methods such as BoundingBox.#diagonal will return a size greater than zero.

Examples:

model = Sketchup.active_model
bounding_box = model.bounds
point1 = Geom::Point3d.new(100, 200, 300)
point2 = Geom::Point3d.new(200, 400, 200)
bounding_box.add(point1, point2)

Parameters:

Returns:

Since:

  • SketchUp 6.0



63
64
# File 'lib/boundingbox.rb', line 63

def add(*args)
end

#centerGeom::Point3d

Get the center point of the bounding box.

Examples:

bounding_box = Geom::BoundingBox.new
bounding_box.add([100, 200, -400], [200, 400, 100])
# This will return a point Point3d(150, 300, -150).
point = bounding_box.center

Returns:

Since:

  • SketchUp 6.0



75
76
# File 'lib/boundingbox.rb', line 75

def center
end

#clearGeom::BoundingBox

Remove all points from the bounding box. A cleared BoundingBox does not have an points; therefore, the size is zero.

Examples:

bounding_box = Geom::BoundingBox.new
bounding_box.add([100, 200, -400], [200, 400, 100])

# This will return false.
bounding_box.empty?

bounding_box.clear

# This will return true.
bounding_box.empty?

Returns:

Since:

  • SketchUp 6.0



94
95
# File 'lib/boundingbox.rb', line 94

def clear
end

#contains?(thing) ⇒ Boolean

Determine if the current bounding box contains a specific Point3d or Geom::BoundingBox object.

Examples:

bounding_box = Geom::BoundingBox.new
bounding_box.add([100, 200, -400], [200, 400, 100])
# This will return false.
bounding_box.contains?([300, 100, 400])
# This will return true.
bounding_box.contains?([150, 300, -200])

Parameters:

Returns:

  • (Boolean)

    +true+ if the bounding box contains the specified thing or +false+ if not.

Since:

  • SketchUp 6.0



112
113
# File 'lib/boundingbox.rb', line 112

def contains?(thing)
end

#corner(n) ⇒ Geom::Point3d

Get point at specified corner of the bounding box.

There are 8 corners to a bounding box, identified by the numbers 0..7. Points are returned in the currently set units (inches by default).

These are which index refers to which corner: 0 = 0, 0, 0 1 = 1, 0, 0 2 = 0, 1, 0 3 = 1, 1, 0 4 = 0, 0, 1 5 = 1, 0, 1 6 = 0, 1, 1 7 = 1, 1, 1

Examples:

bounding_box = Geom::BoundingBox.new
bounding_box.add([100, 200, -400], [200, 400, 100])
# This will return Point3d(100, 200, -400).
bounding_box.corner(0)
# This will return Point3d(100, 200, -400).
bounding_box.corner(6)

Parameters:

  • n (Fixnum)

    A number between 0 and 7.

Returns:

Since:

  • SketchUp 6.0



141
142
# File 'lib/boundingbox.rb', line 141

def corner(n)
end

#depthLength

Get the depth of the bounding box.

The depth is returned in the currently set units (inches by default).

Examples:

bounding_box = Geom::BoundingBox.new
bounding_box.add([100, 200, -400], [200, 400, 100])
# This will return a Length of 500.0".
length = bounding_box.depth

Returns:

  • (Length)

    The depth of the bounding box in currently set units.

Since:

  • SketchUp 6.0



155
156
# File 'lib/boundingbox.rb', line 155

def depth
end

#diagonalLength

Get the length of the diagonal of the bounding box.

The diagonal is returned in the currently set units (inches by default).

Examples:

bounding_box = Geom::BoundingBox.new
bounding_box.add([100, 200, -400], [200, 400, 100])
# This will return a Length of ~547.72".
length = bounding_box.diagonal

Returns:

  • (Length)

    The diagonal of the bounding box in currently set units.

Since:

  • SketchUp 6.0



169
170
# File 'lib/boundingbox.rb', line 169

def diagonal
end

#empty?Boolean

Determine if the bounding box is empty, such as if the bounds have not been set. This is the opposite of the #valid? method.

Examples:

bounding_box = Geom::BoundingBox.new
bounding_box.add([100, 200, -400], [200, 400, 100])
# This will return false.
bounding_box.empty?

Returns:

  • (Boolean)

    +true+ if the bounding box is empty or +false+ if filed.

Since:

  • SketchUp 6.0



182
183
# File 'lib/boundingbox.rb', line 182

def empty?
end

#heightLength

Get the height of the bounding box.

The height is returned in the currently set units (inches, by default).

Examples:

bounding_box = Geom::BoundingBox.new
bounding_box.add([100, 200, -400], [200, 400, 100])
# This will return a Length of 200.0".
length = bounding_box.height

Returns:

  • (Length)

    The height of the bounding box in currently set units.

Since:

  • SketchUp 6.0



196
197
# File 'lib/boundingbox.rb', line 196

def height
end

#intersect(other_bounding_box) ⇒ Geom::BoundingBox

Note:

Prior to SU2015 this method would return incorrect result in some cases. For correct result in these versions you must first check if the bounding boxes actually overlap - then call this to get the resulting bounding box.

Intersect this bounding box with another bounding box. This method returns a new bounding box object rather than modifying the current one.

Examples:

boundingbox1 = Geom::BoundingBox.new
boundingbox1.add([100, 200, -400], [200, 400, 300])
boundingbox2 = Geom::BoundingBox.new
boundingbox2.add([150, 350, 100], [200, 400, 500])
# The returned boundingbox is a result of the intersection of the two.
boundingbox = boundingbox1.intersect(boundingbox2)

Parameters:

  • other_bounding_box (Geom::BoundingBox)

    THe other bounding box, which might intersect with this bounding box.

Returns:

Since:

  • SketchUp 6.0



219
220
# File 'lib/boundingbox.rb', line 219

def intersect(other_bounding_box)
end

#maxGeom::Point3d

Note:

If you attempt to call this method on an empty bounding box, you will receive a point consisting of very large negative numbers.

Get the maximum point in the bounding box.

Examples:

bounding_box = Geom::BoundingBox.new
bounding_box.add([100, 200, -400], [700, 900, 800], [200, 400, 100])
# This will return a point Point3d(700, 900, 800).
point = bounding_box.max

Returns:

  • (Geom::Point3d)

    The point where x, y, and z are the maximum in the bounding box.

Since:

  • SketchUp 6.0



235
236
# File 'lib/boundingbox.rb', line 235

def max
end

#minGeom::Point3d

Note:

If you attempt to call this method on an empty bounding box, you will receive a point consisting of very large negative numbers.

Get the minimum point in the bounding box.

Examples:

bounding_box = Geom::BoundingBox.new
bounding_box.add([100, 200, -400], [700, 900, 800], [200, 400, 100])
# This will return a point Point3d(100, 200, -400).
point = bounding_box.min

Returns:

  • (Geom::Point3d)

    The point where x, y, and z are the minimum in the bounding box.

Since:

  • SketchUp 6.0



251
252
# File 'lib/boundingbox.rb', line 251

def min
end

#valid?Boolean

Determine if the bounding box is valid (contains points). This method is the opposite of the #empty? method.

Examples:

bounding_box = Geom::BoundingBox.new
bounding_box.add([100, 200, -400], [200, 400, 100])
# This will return true.
bounding_box.valid?

Returns:

  • (Boolean)

    +true+ if filled or +false+ if empty.

Since:

  • SketchUp 6.0



264
265
# File 'lib/boundingbox.rb', line 264

def valid?
end

#widthLength

Get the width of the bounding box.

The width is returned in the currently set units (inches by default).

Examples:

bounding_box = Geom::BoundingBox.new
bounding_box.add([100, 200, -400], [200, 400, 100])
# This will return a Length of 100.0".
length = bounding_box.width

Returns:

  • (Length)

    The width of the bounding box in currently set units.

Since:

  • SketchUp 6.0



278
279
# File 'lib/boundingbox.rb', line 278

def width
end