-
Notifications
You must be signed in to change notification settings - Fork 165
/
cartesian_analysis_test.rb
165 lines (138 loc) · 4.65 KB
/
cartesian_analysis_test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# frozen_string_literal: true
# -----------------------------------------------------------------------------
#
# Tests for basic GeoJSON usage
#
# -----------------------------------------------------------------------------
require_relative "test_helper"
class CartesianAnalysisTest < Minitest::Test # :nodoc:
class Fixtures
def initialize(factory)
@factory = factory
end
def clockwise_triangle
p1 = @factory.point(1, 1)
p2 = @factory.point(2, 4)
p3 = @factory.point(5, 2)
@factory.line_string([p1, p2, p3, p1])
end
def counterclockwise_triangle
p1 = @factory.point(1, 1)
p2 = @factory.point(2, 4)
p3 = @factory.point(5, 2)
@factory.line_string([p1, p3, p2, p1])
end
def clockwise_puckered_quad
p1 = @factory.point(1, 1)
p2 = @factory.point(2, 6)
p3 = @factory.point(3, 3)
p4 = @factory.point(5, 2)
@factory.line_string([p1, p2, p3, p4, p1])
end
def counterclockwise_puckered_quad
p1 = @factory.point(1, 1)
p2 = @factory.point(2, 6)
p3 = @factory.point(3, 3)
p4 = @factory.point(5, 2)
@factory.line_string([p1, p4, p3, p2, p1])
end
def clockwise_hat
p1 = @factory.point(1, 2)
p2 = @factory.point(2, 3)
p3 = @factory.point(3, 2)
p4 = @factory.point(2, 1)
p5 = @factory.point(2, 0)
p6 = @factory.point(0, 2)
@factory.line_string([p1, p2, p3, p4, p5, p6, p1])
end
def counterclockwise_hat
p1 = @factory.point(2, 1)
p2 = @factory.point(3, 2)
p3 = @factory.point(2, 3)
p4 = @factory.point(1, 2)
p5 = @factory.point(0, 2)
p6 = @factory.point(2, 0)
@factory.line_string([p1, p2, p3, p4, p5, p6, p1])
end
def counterclockwise_near_circle
p1 = @factory.point(0, -3)
p2 = @factory.point(2, -2)
p3 = @factory.point(3, 0)
p4 = @factory.point(2, 2)
p5 = @factory.point(0, 3)
p6 = @factory.point(-2, 2)
p7 = @factory.point(-3, 0)
p8 = @factory.point(-2, -2)
@factory.line_string([p1, p2, p3, p4, p5, p6, p7, p8, p1])
end
end
def setup
@fixtures = Fixtures.new(RGeo::Cartesian.simple_factory)
end
# --------------------------------------------- RGeo::Cartesian::Analysis.ccw?
def test_ccw_p_clockwise_triangle
ring = @fixtures.clockwise_triangle
assert_equal(
false,
RGeo::Cartesian::Analysis.ccw?(ring),
"falls back to ring_direction"
)
end
def test_ccw_p_counterclockwise_triangle
ring = @fixtures.counterclockwise_triangle
assert_equal(
true,
RGeo::Cartesian::Analysis.ccw?(ring),
"falls back to ring_direction"
)
end
def test_ccw_p_clockwise_puckered_quad
ring = @fixtures.clockwise_puckered_quad
assert_equal(false, RGeo::Cartesian::Analysis.ccw?(ring))
end
def test_ccw_p_counterclockwise_puckered_quad
ring = @fixtures.counterclockwise_puckered_quad
assert_equal(true, RGeo::Cartesian::Analysis.ccw?(ring))
end
def test_ccw_p_clockwise_hat
ring = @fixtures.clockwise_hat
assert_equal(false, RGeo::Cartesian::Analysis.ccw?(ring))
end
def test_ccw_p_counterclockwise_hat
ring = @fixtures.counterclockwise_hat
assert_equal(true, RGeo::Cartesian::Analysis.ccw?(ring))
end
def test_ccw_p_counterclockwise_near_circle
ring = @fixtures.counterclockwise_near_circle
assert_equal(true, RGeo::Cartesian::Analysis.ccw?(ring))
end
# ----------------------------------- RGeo::Cartesian::Analysis.ring_direction
def test_ring_direction_clockwise_triangle
ring = @fixtures.clockwise_triangle
assert_equal(-1, RGeo::Cartesian::Analysis.ring_direction(ring))
end
def test_ring_direction_counterclockwise_triangle
ring = @fixtures.counterclockwise_triangle
assert_equal(1, RGeo::Cartesian::Analysis.ring_direction(ring))
end
def test_ring_direction_clockwise_puckered_quad
ring = @fixtures.clockwise_puckered_quad
assert_equal(-1, RGeo::Cartesian::Analysis.ring_direction(ring))
end
def test_ring_direction_counterclockwise_puckered_quad
ring = @fixtures.counterclockwise_puckered_quad
assert_equal(1, RGeo::Cartesian::Analysis.ring_direction(ring))
end
def test_ring_direction_clockwise_hat
ring = @fixtures.clockwise_hat
assert_equal(-1, RGeo::Cartesian::Analysis.ring_direction(ring))
end
def test_ring_direction_counterclockwise_hat
ring = @fixtures.counterclockwise_hat
assert_equal(1, RGeo::Cartesian::Analysis.ring_direction(ring))
end
def test_ring_direction_counterclockwise_near_circle
ring = @fixtures.counterclockwise_near_circle
assert_equal(1, RGeo::Cartesian::Analysis.ring_direction(ring))
end
end