Class: Rays::Polyline

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

Instance Method Summary collapse

Constructor Details

#initialize(*points, loop: false, fill: nil, colors: nil, texcoords: nil, hole: false) ⇒ Polyline

Returns a new instance of Polyline.



12
13
14
15
16
# File 'lib/rays/polyline.rb', line 12

def initialize(
  *points, loop: false, fill: nil, colors: nil, texcoords: nil, hole: false)

  setup points, loop, (fill != nil ? fill : loop), colors, texcoords, hole
end

Instance Method Details

#<=>(o) ⇒ Object



56
57
58
59
60
61
62
63
64
# File 'lib/rays/polyline.rb', line 56

def <=>(o)
  (size  <=> o.size) .then {|cmp|                        return cmp if cmp != 0}
  (loop? <=> o.loop?).then {|cmp|                        return cmp if cmp != 0}
  (fill? <=> o.fill?).then {|cmp|                        return cmp if cmp != 0}
  points   .zip(o.points)   .each {|a, b| cmp = a <=> b; return cmp if cmp != 0}
  colors   .zip(o.colors)   .each {|a, b| cmp = a <=> b; return cmp if cmp != 0}
  texcoords.zip(o.texcoords).each {|a, b| cmp = a <=> b; return cmp if cmp != 0}
  0
end

#colorsObject



34
35
36
# File 'lib/rays/polyline.rb', line 34

def colors()
  each_color.to_a
end

#each_color(&block) ⇒ Object



46
47
48
# File 'lib/rays/polyline.rb', line 46

def each_color(&block)
  block ? each_color!(&block) : enum_for(:each_color!)
end

#each_point(&block) ⇒ Object Also known as: each



42
43
44
# File 'lib/rays/polyline.rb', line 42

def each_point(&block)
  block ? each_point!(&block) : enum_for(:each_point!)
end

#each_texcoord(&block) ⇒ Object



50
51
52
# File 'lib/rays/polyline.rb', line 50

def each_texcoord(&block)
  block ? each_texcoord!(&block) : enum_for(:each_texcoord!)
end

#inspectObject



66
67
68
69
70
# File 'lib/rays/polyline.rb', line 66

def inspect()
  p    = points.map {|o| o.to_a.join ','}.join ', '
  c, t = colors.size, texcoords.size
  "#<Rays::Polyline [#{p}] loop:#{loop?} fill:#{fill?} hole:#{hole?} colors:#{c} texcoords:#{t}>"
end

#pointsObject



30
31
32
# File 'lib/rays/polyline.rb', line 30

def points()
  each_point.to_a
end

#texcoordsObject



38
39
40
# File 'lib/rays/polyline.rb', line 38

def texcoords()
  each_texcoord.to_a
end

#with(**kwargs) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/rays/polyline.rb', line 18

def with(**kwargs)
  points_, loop_, fill_, colors_, texcoords_, hole_ =
    kwargs.values_at :points, :loop, :fill, :colors, :texcoords, :hole
  self.class.new(
             *(points_    || (points?    ? points    : [])),
    loop:      loop_ != nil ? loop_ : loop?,
    fill:      fill_ != nil ? fill_ : fill?,
    colors:    colors_    || (colors?    ? colors    : nil),
    texcoords: texcoords_ || (texcoords? ? texcoords : nil),
    hole:      hole_ != nil ? hole_ : hole?)
end