Class: Contrek::Concurrent::Polyline

Inherits:
Object
  • Object
show all
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

Attributes included from Partitionable

#parts

Instance Method Summary collapse

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_yObject (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_yObject (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

#nameObject (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_shapesObject (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

#rawObject (readonly)

Returns the value of attribute raw.



10
11
12
# File 'lib/contrek/finder/concurrent/polyline.rb', line 10

def raw
  @raw
end

#shapeObject

Returns the value of attribute shape.



11
12
13
# File 'lib/contrek/finder/concurrent/polyline.rb', line 11

def shape
  @shape
end

#tileObject

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

Returns:

  • (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

Returns:

  • (Boolean)


46
47
48
# File 'lib/contrek/finder/concurrent/polyline.rb', line 46

def empty?
  @raw.empty?
end

#infoObject



26
27
28
# File 'lib/contrek/finder/concurrent/polyline.rb', line 26

def info
  "w#{@tile.name} S#{@name}"
end

#inspectObject



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

Returns:

  • (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

Returns:

  • (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

#widthObject



62
63
64
65
# File 'lib/contrek/finder/concurrent/polyline.rb', line 62

def width
  return 0 if empty?
  @max_x - @min_x
end