Class: Contrek::Concurrent::Polyline
- Inherits:
-
Object
- Object
- Contrek::Concurrent::Polyline
- Includes:
- Partitionable
- Defined in:
- lib/contrek/finder/concurrent/polyline.rb
Defined Under Namespace
Classes: Bounds
Constant Summary collapse
- TRACKED_OUTER =
1 << 0
- TRACKED_INNER =
1 << 1
Instance Attribute Summary collapse
-
#max_y ⇒ Object
readonly
Returns the value of attribute max_y.
-
#min_y ⇒ Object
readonly
Returns the value of attribute min_y.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#next_tile_eligible_shapes ⇒ Object
readonly
Returns the value of attribute next_tile_eligible_shapes.
-
#raw ⇒ Object
readonly
Returns the value of attribute raw.
-
#shape ⇒ Object
Returns the value of attribute shape.
-
#tile ⇒ Object
Returns the value of attribute tile.
Attributes included from Partitionable
Instance Method Summary collapse
- #boundary? ⇒ Boolean
- #clear! ⇒ Object
- #empty? ⇒ Boolean
- #info ⇒ Object
-
#initialize(tile:, polygon:, shape: nil) ⇒ Polyline
constructor
A new instance of Polyline.
- #inspect ⇒ Object
- #intersection(other) ⇒ Object
- #on?(flag) ⇒ Boolean
-
#precalc! ⇒ Object
Pre-detects, for the current polyline, adjacent ones in the neighboring tile that vertically intersect.
- #turn_off(flag) ⇒ Object
- #turn_on(flag) ⇒ Object
- #vert_intersect?(other) ⇒ Boolean
- #width ⇒ Object
Methods included from Partitionable
#add_part, #find_first_part_by_position, #inspect_parts, #partition!, #sew!
Constructor Details
#initialize(tile:, polygon:, shape: nil) ⇒ Polyline
Returns a new instance of Polyline.
13 14 15 16 17 18 19 20 |
# File 'lib/contrek/finder/concurrent/polyline.rb', line 13 def initialize(tile:, polygon:, shape: nil) @tile = tile @name = tile.shapes.count @raw = polygon @shape = shape @flags = 0 find_boundary end |
Instance Attribute Details
#max_y ⇒ Object (readonly)
Returns the value of attribute max_y.
10 11 12 |
# File 'lib/contrek/finder/concurrent/polyline.rb', line 10 def max_y @max_y end |
#min_y ⇒ Object (readonly)
Returns the value of attribute min_y.
10 11 12 |
# File 'lib/contrek/finder/concurrent/polyline.rb', line 10 def min_y @min_y end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
10 11 12 |
# File 'lib/contrek/finder/concurrent/polyline.rb', line 10 def name @name end |
#next_tile_eligible_shapes ⇒ Object (readonly)
Returns the value of attribute next_tile_eligible_shapes.
10 11 12 |
# File 'lib/contrek/finder/concurrent/polyline.rb', line 10 def next_tile_eligible_shapes @next_tile_eligible_shapes end |
#raw ⇒ Object (readonly)
Returns the value of attribute raw.
10 11 12 |
# File 'lib/contrek/finder/concurrent/polyline.rb', line 10 def raw @raw end |
#shape ⇒ Object
Returns the value of attribute shape.
11 12 13 |
# File 'lib/contrek/finder/concurrent/polyline.rb', line 11 def shape @shape end |
#tile ⇒ Object
Returns the value of attribute tile.
11 12 13 |
# File 'lib/contrek/finder/concurrent/polyline.rb', line 11 def tile @tile end |
Instance Method Details
#boundary? ⇒ Boolean
50 51 52 |
# File 'lib/contrek/finder/concurrent/polyline.rb', line 50 def boundary? @tile.tg_border?({x: @min_x}) || @tile.tg_border?({x: @max_x}) end |
#clear! ⇒ Object
54 55 56 |
# File 'lib/contrek/finder/concurrent/polyline.rb', line 54 def clear! @raw = [] end |
#empty? ⇒ Boolean
46 47 48 |
# File 'lib/contrek/finder/concurrent/polyline.rb', line 46 def empty? @raw.empty? end |
#info ⇒ Object
26 27 28 |
# File 'lib/contrek/finder/concurrent/polyline.rb', line 26 def info "w#{@tile.name} S#{@name}" end |
#inspect ⇒ Object
22 23 24 |
# File 'lib/contrek/finder/concurrent/polyline.rb', line 22 def inspect "#{self.class}[b#{@tile.name} S#{@name} #{"B" if boundary?}] (#{raw.count} => #{raw.inspect})" end |
#intersection(other) ⇒ Object
42 43 44 |
# File 'lib/contrek/finder/concurrent/polyline.rb', line 42 def intersection(other) (@raw.compact & other.raw.compact) end |
#on?(flag) ⇒ Boolean
38 39 40 |
# File 'lib/contrek/finder/concurrent/polyline.rb', line 38 def on?(flag) (@flags & flag) != 0 end |
#precalc! ⇒ Object
Pre-detects, for the current polyline, adjacent ones in the neighboring tile that vertically intersect.
69 70 71 72 73 74 75 76 |
# File 'lib/contrek/finder/concurrent/polyline.rb', line 69 def precalc! @next_tile_eligible_shapes = @tile .circular_next.boundary_shapes .select { |s| !s.outer_polyline.on?(Polyline::TRACKED_OUTER) && vert_intersect?(s.outer_polyline) } end |
#turn_off(flag) ⇒ Object
34 35 36 |
# File 'lib/contrek/finder/concurrent/polyline.rb', line 34 def turn_off(flag) @flags &= ~flag end |
#turn_on(flag) ⇒ Object
30 31 32 |
# File 'lib/contrek/finder/concurrent/polyline.rb', line 30 def turn_on(flag) @flags |= flag end |
#vert_intersect?(other) ⇒ Boolean
58 59 60 |
# File 'lib/contrek/finder/concurrent/polyline.rb', line 58 def vert_intersect?(other) !(@max_y < other.min_y || other.max_y < @min_y) end |
#width ⇒ Object
62 63 64 65 |
# File 'lib/contrek/finder/concurrent/polyline.rb', line 62 def width return 0 if empty? @max_x - @min_x end |