Class: Rays::Polygon

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Polygon.



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

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

Class Method Details

.bezier(*points, loop: false, nsegment: nil) ⇒ Object



86
87
88
# File 'lib/rays/polygon.rb', line 86

def self.bezier(*points, loop: false, nsegment: nil)
  bezier! points, loop, nsegment
end

.curve(*points, loop: false, nsegment: nil) ⇒ Object



82
83
84
# File 'lib/rays/polygon.rb', line 82

def self.curve(*points, loop: false, nsegment: nil)
  curve! points, loop, nsegment
end

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



75
76
77
78
79
80
# File 'lib/rays/polygon.rb', line 75

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

  ellipse! args, center, radius, hole, from, to, nsegment
end

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



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

def self.line(*points, loop: false)
  line! points, loop
end

.lines(*points) ⇒ Object



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

def self.lines(*points)
  lines! points
end

.points(*points) ⇒ Object



36
37
38
# File 'lib/rays/polygon.rb', line 36

def self.points(*points)
  points! points
end

.quad_strip(*points, colors: nil, texcoords: nil) ⇒ Object



71
72
73
# File 'lib/rays/polygon.rb', line 71

def self.quad_strip(*points, colors: nil, texcoords: nil)
  quad_strip! points, colors, texcoords
end

.quads(*points, loop: true, colors: nil, texcoords: nil) ⇒ Object



67
68
69
# File 'lib/rays/polygon.rb', line 67

def self.quads(*points, loop: true, colors: nil, texcoords: nil)
  quads! points, loop, colors, texcoords
end

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



60
61
62
63
64
65
# File 'lib/rays/polygon.rb', line 60

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

  rect! args, round, lt, rt, lb, rb, nsegment
end

.triangle_fan(*points, colors: nil, texcoords: nil) ⇒ Object



56
57
58
# File 'lib/rays/polygon.rb', line 56

def self.triangle_fan(*points, colors: nil, texcoords: nil)
  triangle_fan! points, colors, texcoords
end

.triangle_strip(*points, colors: nil, texcoords: nil) ⇒ Object



52
53
54
# File 'lib/rays/polygon.rb', line 52

def self.triangle_strip(*points, colors: nil, texcoords: nil)
  triangle_strip! points, colors, texcoords
end

.triangles(*points, loop: true, colors: nil, texcoords: nil) ⇒ Object



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

def self.triangles(*points, loop: true, colors: nil, texcoords: nil)
  triangles! points, loop, colors, texcoords
end

Instance Method Details

#<=>(o) ⇒ Object



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

def <=>(o)
  (size <=> o.size).then {|cmp|                return cmp if cmp != 0}
  to_a.zip(o.to_a).each {|a, b| cmp = a <=> b; return cmp if cmp != 0}
  0
end

#inspectObject



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

def inspect()
  "#<Rays::Polygon [#{map {|polyline| polyline.inspect}.join ', '}]>"
end

#intersects(obj) ⇒ Object



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

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

#transform(&block) ⇒ Object



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

def transform(&block)
  polylines = block.call to_a
  self.class.new(*polylines)
end