Class: Sevgi::Geometry::Rect
- Inherits:
-
RectBase
- Object
- Sevgi::Geometry::Rect
- Defined in:
- lib/sevgi/geometry/elements/rect.rb
Overview
Closed four-sided rectangle aligned to the screen axes.
Direct Known Subclasses
Class Method Summary collapse
-
.[](width, height, position: Origin) ⇒ Sevgi::Geometry::Rect
Builds a rectangle from size and top-left position.
-
.call(top_left, bottom_right) ⇒ Sevgi::Geometry::Rect
Builds a rectangle from two opposite corners.
-
.from_corners(top_left, bottom_right) ⇒ Sevgi::Geometry::Rect
Builds a rectangle from two opposite corners.
-
.from_size(width, height, position: Origin) ⇒ Sevgi::Geometry::Rect
Builds a rectangle from size and top-left position.
Instance Method Summary collapse
-
#draw!(node) ⇒ Object
Draws the rectangle into a graphics node.
-
#height ⇒ Float
Returns rectangle height.
-
#width ⇒ Float
Returns rectangle width.
Class Method Details
.[](width, height, position: Origin) ⇒ Sevgi::Geometry::Rect
19 |
# File 'lib/sevgi/geometry/elements/rect.rb', line 19 def self.[](...) = from_size(...) |
.call(top_left, bottom_right) ⇒ Sevgi::Geometry::Rect
27 |
# File 'lib/sevgi/geometry/elements/rect.rb', line 27 def self.call(...) = from_corners(...) |
.from_corners(top_left, bottom_right) ⇒ Sevgi::Geometry::Rect
Builds a rectangle from two opposite corners.
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/sevgi/geometry/elements/rect.rb', line 34 def self.from_corners(top_left, bottom_right) top_left, bottom_right = Tuples[Point, top_left, bottom_right] width = (bottom_right.x - top_left.x).abs new_by_points( top_left, top_left.translate(width, 0.0), bottom_right, bottom_right.translate(-width, 0.0) ) end |
.from_size(width, height, position: Origin) ⇒ Sevgi::Geometry::Rect
Builds a rectangle from size and top-left position.
52 53 54 55 56 57 58 59 60 |
# File 'lib/sevgi/geometry/elements/rect.rb', line 52 def self.from_size(width, height, position: Origin) new_by_segments( Segment.rightward(width), Segment.downward(height), Segment.leftward(width), Segment.upward(height), position: ) end |
Instance Method Details
#draw!(node) ⇒ Object
Draws the rectangle into a graphics node.
65 |
# File 'lib/sevgi/geometry/elements/rect.rb', line 65 def draw!(node, **) = node.rect(x: position.x, y: position.y, width: width, height: height, **) |
#height ⇒ Float
Returns rectangle height.
69 |
# File 'lib/sevgi/geometry/elements/rect.rb', line 69 def height = @height ||= segments[1].length |
#width ⇒ Float
Returns rectangle width.
73 |
# File 'lib/sevgi/geometry/elements/rect.rb', line 73 def width = @width ||= segments[0].length |