Class: Contrek::Concurrent::Polyline
- Inherits:
-
Object
- Object
- Contrek::Concurrent::Polyline
show all
- Includes:
- Partitionable
- Defined in:
- lib/contrek/finder/concurrent/polyline.rb
Constant Summary
collapse
- TRACKED_OUTER =
1 << 0
Instance Attribute Summary collapse
#parts
Class Method Summary
collapse
Instance Method Summary
collapse
#add_part, #inspect_parts, #partition!
Constructor Details
#initialize(tile:, polygon:, shape: nil, bounds: nil, force_named: nil) ⇒ Polyline
Returns a new instance of Polyline.
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/contrek/finder/concurrent/polyline.rb', line 11
def initialize(tile:, polygon:, shape: nil, bounds: nil, force_named: nil)
@tile = tile
@name = tile.shapes.count
@named = force_named
@raw = polygon
@shape = shape
@flags = 0
@any_ancients = false
@inside_inner_polyline = nil
if bounds.nil?
find_boundary
else
@min_x = bounds[:min_x]
@max_x = bounds[:max_x]
@min_y = bounds[:min_y]
@max_y = bounds[:max_y]
end
end
|
Instance Attribute Details
#any_ancients ⇒ Object
Returns the value of attribute any_ancients.
9
10
11
|
# File 'lib/contrek/finder/concurrent/polyline.rb', line 9
def any_ancients
@any_ancients
end
|
#inside_inner_polyline ⇒ Object
Returns the value of attribute inside_inner_polyline.
9
10
11
|
# File 'lib/contrek/finder/concurrent/polyline.rb', line 9
def inside_inner_polyline
@inside_inner_polyline
end
|
#max_y ⇒ Object
Returns the value of attribute max_y.
8
9
10
|
# File 'lib/contrek/finder/concurrent/polyline.rb', line 8
def max_y
@max_y
end
|
#min_y ⇒ Object
Returns the value of attribute min_y.
8
9
10
|
# File 'lib/contrek/finder/concurrent/polyline.rb', line 8
def min_y
@min_y
end
|
#name ⇒ Object
Returns the value of attribute name.
8
9
10
|
# File 'lib/contrek/finder/concurrent/polyline.rb', line 8
def name
@name
end
|
#raw ⇒ Object
Returns the value of attribute raw.
8
9
10
|
# File 'lib/contrek/finder/concurrent/polyline.rb', line 8
def raw
@raw
end
|
#shape ⇒ Object
Returns the value of attribute shape.
9
10
11
|
# File 'lib/contrek/finder/concurrent/polyline.rb', line 9
def shape
@shape
end
|
#tile ⇒ Object
Returns the value of attribute tile.
9
10
11
|
# File 'lib/contrek/finder/concurrent/polyline.rb', line 9
def tile
@tile
end
|
Class Method Details
.is_within?(test_seq, container_seq) ⇒ Boolean
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
# File 'lib/contrek/finder/concurrent/polyline.rb', line 110
def self.is_within?(test_seq, container_seq)
target = test_seq.first
return false unless target
tx, ty = target[:x], target[:y]
inside = false
j = container_seq.length - 1
container_seq.each_with_index do |p_i, i|
p_j = container_seq[j]
if (p_i[:y] > ty) != (p_j[:y] > ty)
intersect_x = (p_j[:x] - p_i[:x]) * (ty - p_i[:y]).to_f / (p_j[:y] - p_i[:y]) + p_i[:x]
if tx < intersect_x
inside = !inside
end
end
j = i
end
inside
end
|
Instance Method Details
#boundary? ⇒ Boolean
59
60
61
|
# File 'lib/contrek/finder/concurrent/polyline.rb', line 59
def boundary?
@tile.tg_border?({x: @min_x}) || @tile.tg_border?({x: @max_x})
end
|
#clear! ⇒ Object
63
64
65
|
# File 'lib/contrek/finder/concurrent/polyline.rb', line 63
def clear!
@raw = []
end
|
#empty? ⇒ Boolean
55
56
57
|
# File 'lib/contrek/finder/concurrent/polyline.rb', line 55
def empty?
@raw.empty?
end
|
#get_bounds ⇒ Object
103
104
105
106
107
108
|
# File 'lib/contrek/finder/concurrent/polyline.rb', line 103
def get_bounds
{min_x: @min_x,
max_x: @max_x,
min_y: @min_y,
max_y: @max_y}
end
|
#inspect ⇒ Object
31
32
33
|
# File 'lib/contrek/finder/concurrent/polyline.rb', line 31
def inspect
"#{self.class}#{named} (#{raw.count} => #{raw.inspect})"
end
|
#named ⇒ Object
35
36
37
|
# File 'lib/contrek/finder/concurrent/polyline.rb', line 35
def named
@named || "t#{@tile.name}s#{@name}#{"B" if boundary?}"
end
|
#numpy_raw ⇒ Object
39
40
41
|
# File 'lib/contrek/finder/concurrent/polyline.rb', line 39
def numpy_raw
raw.flat_map { |p| [p[:x], p[:y]] }
end
|
#on?(flag) ⇒ Boolean
51
52
53
|
# File 'lib/contrek/finder/concurrent/polyline.rb', line 51
def on?(flag)
(@flags & flag) != 0
end
|
#turn_off(flag) ⇒ Object
47
48
49
|
# File 'lib/contrek/finder/concurrent/polyline.rb', line 47
def turn_off(flag)
@flags &= ~flag
end
|
#turn_on(flag) ⇒ Object
43
44
45
|
# File 'lib/contrek/finder/concurrent/polyline.rb', line 43
def turn_on(flag)
@flags |= flag
end
|
#vert_bounds_intersect?(vertical_bounds) ⇒ Boolean
76
77
78
|
# File 'lib/contrek/finder/concurrent/polyline.rb', line 76
def vert_bounds_intersect?(vertical_bounds)
!(@max_y < vertical_bounds[:min] || vertical_bounds[:max] < @min_y)
end
|
#vert_intersect?(other) ⇒ Boolean
72
73
74
|
# File 'lib/contrek/finder/concurrent/polyline.rb', line 72
def vert_intersect?(other)
!(@max_y < other.min_y || other.max_y < @min_y)
end
|
#width ⇒ Object
67
68
69
70
|
# File 'lib/contrek/finder/concurrent/polyline.rb', line 67
def width
return 0 if empty?
@max_x - @min_x
end
|
#within?(raw_coords) ⇒ Boolean
verifies if enclosed in the given sequence (raycasting technique)
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
# File 'lib/contrek/finder/concurrent/polyline.rb', line 81
def within?(raw_coords)
is_within = false
self_y = raw.first[:y]
self_x = raw.first[:x]
last_node = raw_coords.last
return false if last_node.nil?
lx = last_node[:x]
ly = last_node[:y]
raw_coords.each do |pos|
cx = pos[:x]
cy = pos[:y]
if (cy > self_y) != (ly > self_y)
intersect_x = lx + (self_y - ly).to_f * (cx - lx) / (cy - ly)
if self_x < intersect_x
is_within = !is_within
end
end
lx, ly = cx, cy
end
is_within
end
|