ModraUp Ruby API Documentation Ruby API Reference

Class: Geom::BoundingBox

Inherits:
Object
  • Object
show all

Overview

Axis-aligned bounding box. Obtained from drawing elements such as ModraUp::Face#bounds.

Examples:

box = ModraUp.active_model.entities.add_line([0, 0, 0], [1, 0, 0]).bounds
box.center

Constants # collapse

Geom::BoundingBox::CORNER_LEFT_FRONT_BOTTOM

CORNER_LEFT_FRONT_BOTTOM = 0

#corner left front bottom.

Returns:

  • (Integer)
Geom::BoundingBox::CORNER_RIGHT_FRONT_BOTTOM

CORNER_RIGHT_FRONT_BOTTOM = 1

#corner right front bottom.

Returns:

  • (Integer)
Geom::BoundingBox::CORNER_LEFT_BACK_BOTTOM

CORNER_LEFT_BACK_BOTTOM = 2

#corner left back bottom.

Returns:

  • (Integer)
Geom::BoundingBox::CORNER_RIGHT_BACK_BOTTOM

CORNER_RIGHT_BACK_BOTTOM = 3

#corner The right back bottom corner.

Returns:

  • (Integer)
Geom::BoundingBox::CORNER_LEFT_FRONT_TOP

CORNER_LEFT_FRONT_TOP = 4

#corner left front top.

Returns:

  • (Integer)
Geom::BoundingBox::CORNER_RIGHT_FRONT_TOP

CORNER_RIGHT_FRONT_TOP = 5

#corner right front top.

Returns:

  • (Integer)
Geom::BoundingBox::CORNER_LEFT_BACK_TOP

CORNER_LEFT_BACK_TOP = 6

#corner left back top.

Returns:

  • (Integer)
Geom::BoundingBox::CORNER_RIGHT_BACK_TOP

CORNER_RIGHT_BACK_TOP = 7

#corner The right back top corner.

Returns:

  • (Integer)

Class Method Summary # collapse

Instance Method Summary # collapse

Class Method Details

BoundingBox.new ⇒ bounds

An empty bounding box. Use #add to join points.

Returns:

  • (Geom::BoundingBox)

Examples:

box = Geom::BoundingBox.new
box.add(Geom::Point3d.new(0, 0, 0), Geom::Point3d.new(1, 2, 3))
box.center.to_a  #=> [0.5, 1.0, 1.5]

Instance Method Details

bounds.add(point, ...) ⇒ selfbounds.add(points) ⇒ selfbounds.add(other_bounds) ⇒ self

Merge a point, array of points, vertices, or another bounding box into it.

Parameters:

  • point (Geom::Point3d, Geom::BoundingBox, ModraUp::Vertex, Array)

Returns:

  • (Geom::BoundingBox)

Examples:

Geom::BoundingBox.new.add([0, 0, 0], [1, 0, 0]).max.to_a
  #=> [1.0, 0.0, 0.0]

Array of points

pts = [Geom::Point3d.new(0, 0, 0), Geom::Point3d.new(1, 2, 3)]
Geom::BoundingBox.new.add(pts).max.to_a  #=> [1.0, 2.0, 3.0]

bounds.min ⇒ Geom::Point3d

Minimum corner point.

Returns:

  • (Geom::Point3d)

Examples:

ModraUp.active_model.entities.add_line([0, 0, 0], [1, 0, 0]).bounds.min

bounds.max ⇒ Geom::Point3d

Maximum corner point.

Returns:

  • (Geom::Point3d)

Examples:

ModraUp.active_model.entities.add_line([0, 0, 0], [1, 0, 0]).bounds.max

bounds.center ⇒ Geom::Point3d

Center point.

Returns:

  • (Geom::Point3d)

Examples:

ModraUp.active_model.entities.add_line([0, 0, 0], [2, 0, 0]).bounds.center.to_a

bounds.clear ⇒ self

Clear the bounding box, making #empty? return true.

Returns:

  • (Geom::BoundingBox)

Examples:

box = Geom::BoundingBox.new.add([0, 0, 0], [1, 0, 0])
box.clear.empty?  #=> true

bounds.contains?(point) ⇒ Booleanbounds.contains?(other_bounds) ⇒ Boolean

Does a point or another bounding box completely fall within this box.

Parameters:

  • point (Geom::Point3d, Geom::BoundingBox, Array<Numeric>)

Returns:

  • (Boolean)

Examples:

Geom::BoundingBox.new.add([0, 0, 0], [2, 2, 2]).contains?([1, 1, 1])

bounds.corner(index) ⇒ Geom::Point3d

One of the eight corner points. index ranges from 0..7, or can be a constant like CORNER_LEFT_FRONT_BOTTOM.

Parameters:

  • index (Integer)

Returns:

  • (Geom::Point3d)

Examples:

box = Geom::BoundingBox.new.add([0, 0, 0], [1, 2, 3])
box.corner(Geom::BoundingBox::CORNER_LEFT_FRONT_BOTTOM).to_a
  #=> [0.0, 0.0, 0.0]

bounds.width ⇒ Length

X-direction dimension, returns Length.

Returns:

  • (Length)

Examples:

Geom::BoundingBox.new.add([0, 0, 0], [4, 0, 0]).width == 4.inch

bounds.height ⇒ Length

The height in the Y direction (along the green axis), returns Length.

Returns:

  • (Length)

Examples:

Geom::BoundingBox.new.add([0, 0, 0], [0, 5, 0]).height == 5.inch

bounds.depth ⇒ Length

Depth in the Z direction (along the blue axis), returns Length.

Returns:

  • (Length)

Examples:

Geom::BoundingBox.new.add([0, 0, 0], [0, 0, 6]).depth == 6.inch

bounds.diagonal ⇒ Length

The length of the space diagonal, returns Length.

Returns:

  • (Length)

Examples:

Geom::BoundingBox.new.add([0, 0, 0], [3, 4, 0]).diagonal == 5.inch

bounds.empty? ⇒ Boolean

If no points have been added, it returns true. Opposite of #valid?.

Returns:

  • (Boolean)

Examples:

Geom::BoundingBox.new.empty?  #=> true

bounds.valid? ⇒ Boolean

Returns true if it contains at least one point.

Returns:

  • (Boolean)

Examples:

Geom::BoundingBox.new.add([0, 0, 0]).valid?

bounds.intersect(other) ⇒ Geom::BoundingBox

Intersection with another bounding box. Returns an empty box if they do not intersect.

Parameters:

  • other (Geom::BoundingBox)

Returns:

  • (Geom::BoundingBox)

Examples:

a = Geom::BoundingBox.new.add([0, 0, 0], [2, 2, 2])
b = Geom::BoundingBox.new.add([1, 1, 1], [3, 3, 3])
a.intersect(b).min.to_a  #=> [1.0, 1.0, 1.0]