Class: Rays::Polygon

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/rays/polygon.rb,
lib/rays/polygon_line.rb

Defined Under Namespace

Classes: Line

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args, loop: true) ⇒ Polygon

Returns a new instance of Polygon.



12
13
14
# File 'lib/rays/polygon.rb', line 12

def initialize(*args, loop: true)
  setup args, loop
end

Class Method Details

.bezier(*args, loop: false) ⇒ Object



48
49
50
# File 'lib/rays/polygon.rb', line 48

def self.bezier(*args, loop: false)
  create_bezier args, loop
end

.curve(*args, loop: false) ⇒ Object



44
45
46
# File 'lib/rays/polygon.rb', line 44

def self.curve(*args, loop: false)
  create_curve args, loop
end

.ellipse(*args, center: nil, radius: nil, hole: nil, from: nil, to: nil, nsegment: nil) ⇒ Object



37
38
39
40
41
42
# File 'lib/rays/polygon.rb', line 37

def self.ellipse(
  *args, center: nil, radius: nil, hole: nil, from: nil, to: nil,
  nsegment: nil)

  create_ellipse args, center, radius, hole, from, to, nsegment
end

.line(*args, loop: false) ⇒ Object



27
28
29
# File 'lib/rays/polygon.rb', line 27

def self.line(*args, loop: false)
  new(*args, loop: loop)
end

.rect(*args, round: nil, lt: nil, rt: nil, lb: nil, rb: nil, nsegment: nil) ⇒ Object



31
32
33
34
35
# File 'lib/rays/polygon.rb', line 31

def self.rect(
  *args, round: nil, lt: nil, rt: nil, lb: nil, rb: nil, nsegment: nil)

  create_rect args, round, lt, rt, lb, rb, nsegment
end

Instance Method Details

#intersects(obj) ⇒ Object



23
24
25
# File 'lib/rays/polygon.rb', line 23

def intersects(obj)
  !(self & obj).empty?
end

#transform(matrix = nil, &block) ⇒ Object



16
17
18
19
20
21
# File 'lib/rays/polygon.rb', line 16

def transform(matrix = nil, &block)
  lines = to_a
  lines = lines.map {|line| line.transform matrix} if matrix
  lines = block.call lines if block
  self.class.new(*lines)
end