Class: Sevgi::Geometry::Rect

Inherits:
Object
  • Object
show all
Defined in:
lib/sevgi/geometry/elements/rect.rb

Direct Known Subclasses

Square

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.[](width, height, position: Origin) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/sevgi/geometry/elements/rect.rb', line 18

def self.[](width, height, position: Origin)
  new_by_segments(
    Segment.horizontal(width),
    Segment.vertical(height),
    Segment.horizontal!(width),
    Segment.vertical!(height),
    position:
  )
end

.call(top_left, bottom_right) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/sevgi/geometry/elements/rect.rb', line 6

def self.call(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

Instance Method Details

#draw!(node) ⇒ Object



28
# File 'lib/sevgi/geometry/elements/rect.rb', line 28

def draw!(node, **) = node.rect(x: position.x, y: position.y, width: width, height: height, **)

#heightObject



30
# File 'lib/sevgi/geometry/elements/rect.rb', line 30

def height = @height ||= segments[1].length

#widthObject



32
# File 'lib/sevgi/geometry/elements/rect.rb', line 32

def width = @width ||= segments[0].length