Class: SkippyLib::BoundingBox

Inherits:
Object
  • Object
show all
Includes:
BoundingBoxConstants, ObjectUtils
Defined in:
modules/boundingbox.rb

Overview

This class is different from Geom::BoundingBox because it represent the orientation in model space. The visible boundingbox one see in the viewport.

Since:

  • 3.0.0

Constant Summary

Constants included from BoundingBoxConstants

SkippyLib::BoundingBoxConstants::BOTTOM_BACK_LEFT, SkippyLib::BoundingBoxConstants::BOTTOM_BACK_RIGHT, SkippyLib::BoundingBoxConstants::BOTTOM_FRONT_LEFT, SkippyLib::BoundingBoxConstants::BOTTOM_FRONT_RIGHT, SkippyLib::BoundingBoxConstants::TOP_BACK_LEFT, SkippyLib::BoundingBoxConstants::TOP_BACK_RIGHT, SkippyLib::BoundingBoxConstants::TOP_FRONT_LEFT, SkippyLib::BoundingBoxConstants::TOP_FRONT_RIGHT

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(points) ⇒ BoundingBox

Returns a new instance of BoundingBox.

Parameters:

  • points (Array<Geom::Point3d>)

    0, 4 or 8 3d points.

Since:

  • 3.0.0



21
22
23
24
25
26
27
# File 'modules/boundingbox.rb', line 21

def initialize(points)
  unless [0, 4, 8].include?(points.size)
    raise ArgumentError, "Expected 0, 4 or 8 points (#{points.size} given)"
  end

  @points = points
end

Instance Attribute Details

#pointsObject (readonly)

Since:

  • 3.0.0



17
18
19
# File 'modules/boundingbox.rb', line 17

def points
  @points
end

Instance Method Details

#depthObject

Since:

  • 3.0.0



69
70
71
# File 'modules/boundingbox.rb', line 69

def depth
  z_axis.length
end

#draw(view) ⇒ Object

Since:

  • 3.0.0



97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'modules/boundingbox.rb', line 97

def draw(view)
  view.draw(GL_LINE_LOOP, @points[0..3])
  if is_3d?
    view.draw(GL_LINE_LOOP, @points[4..7])
    connectors = [
      @points[0], @points[4],
      @points[1], @points[5],
      @points[2], @points[6],
      @points[3], @points[7],
    ]
    view.draw(GL_LINES, connectors)
  end
end

#empty?Boolean

Returns:

  • (Boolean)

Since:

  • 3.0.0



31
32
33
# File 'modules/boundingbox.rb', line 31

def empty?
  @points.empty?
end

#have_area?Boolean

Returns:

  • (Boolean)

Since:

  • 3.0.0



48
49
50
# File 'modules/boundingbox.rb', line 48

def have_area? # rubocop:disable Naming/PredicateName
  x_axis.valid? && y_axis.valid?
end

#have_volume?Boolean

Returns:

  • (Boolean)

Since:

  • 3.0.0



53
54
55
# File 'modules/boundingbox.rb', line 53

def have_volume? # rubocop:disable Naming/PredicateName
  x_axis.valid? && y_axis.valid? && z_axis.valid?
end

#heightObject

Since:

  • 3.0.0



64
65
66
# File 'modules/boundingbox.rb', line 64

def height
  y_axis.length
end

#is_2d?Boolean

Returns:

  • (Boolean)

Since:

  • 3.0.0



37
38
39
# File 'modules/boundingbox.rb', line 37

def is_2d?
  @points.size == 4
end

#is_3d?Boolean

Returns:

  • (Boolean)

Since:

  • 3.0.0



42
43
44
# File 'modules/boundingbox.rb', line 42

def is_3d?
  @points.size == 8
end

#originObject

Since:

  • 3.0.0



75
76
77
# File 'modules/boundingbox.rb', line 75

def origin
  @points[BOTTOM_FRONT_LEFT]
end

#widthObject

Since:

  • 3.0.0



59
60
61
# File 'modules/boundingbox.rb', line 59

def width
  x_axis.length
end

#x_axisObject

Since:

  • 3.0.0



81
82
83
# File 'modules/boundingbox.rb', line 81

def x_axis
  @points[BOTTOM_FRONT_LEFT].vector_to(@points[BOTTOM_FRONT_RIGHT])
end

#y_axisObject

Since:

  • 3.0.0



86
87
88
# File 'modules/boundingbox.rb', line 86

def y_axis
  @points[BOTTOM_FRONT_LEFT].vector_to(@points[BOTTOM_BACK_LEFT])
end

#z_axisObject

Since:

  • 3.0.0



91
92
93
# File 'modules/boundingbox.rb', line 91

def z_axis
  @points[BOTTOM_FRONT_LEFT].vector_to(@points[TOP_FRONT_LEFT])
end