Skip to content

Commit 9291d9c

Browse files
Merge pull request #26 from ThalesGroup/dev-pla
add bounding box utils
2 parents 94169d0 + ca28aaf commit 9291d9c

5 files changed

Lines changed: 492 additions & 6 deletions

File tree

src/GeoTools-Tests/AbsoluteCoordinatesTest.class.st

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -271,21 +271,29 @@ AbsoluteCoordinatesTest >> testFromStringLatitudeLongitude [
271271
]
272272

273273
{ #category : #tests }
274-
AbsoluteCoordinatesTest >> testZero [
274+
AbsoluteCoordinatesTest >> testIsLatLonZero [
275275

276276
| coord |
277-
coord := AbsoluteCoordinates zero.
277+
coord := AbsoluteCoordinates zeroLatLon.
278278
self assert: coord latitudeInDegrees equals: 0.
279279
self assert: coord longitudeInDegrees equals: 0.
280-
self assert: coord altitudeInMeters equals: 0
280+
self assert: coord altitudeInMeters isNil.
281+
self assert: coord isLatLonZero.
282+
self assert: coord isZero.
283+
284+
coord altitudeInMeters: 20.
285+
self assert: coord isLatLonZero.
286+
self deny: coord isZero.
281287
]
282288

283289
{ #category : #tests }
284-
AbsoluteCoordinatesTest >> testZeroLatLon [
290+
AbsoluteCoordinatesTest >> testIsZero [
285291

286292
| coord |
287-
coord := AbsoluteCoordinates zeroLatLon.
293+
coord := AbsoluteCoordinates zero.
288294
self assert: coord latitudeInDegrees equals: 0.
289295
self assert: coord longitudeInDegrees equals: 0.
290-
self assert: coord altitudeInMeters isNil
296+
self assert: coord altitudeInMeters equals: 0.
297+
self assert: coord isLatLonZero.
298+
self assert: coord isZero.
291299
]
Lines changed: 277 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,277 @@
1+
"
2+
A TGeoBoundingBoxTest is a test class for testing the behavior of TGeoBoundingBox
3+
"
4+
Class {
5+
#name : #GeoToolsBoundingBoxTest,
6+
#superclass : #TestCase,
7+
#instVars : [
8+
'boundingBox'
9+
],
10+
#category : #'GeoTools-Tests-Coordinates'
11+
}
12+
13+
{ #category : #running }
14+
GeoToolsBoundingBoxTest >> setUp [
15+
16+
super setUp.
17+
18+
boundingBox := GeoToolsBoundingBox new
19+
]
20+
21+
{ #category : #running }
22+
GeoToolsBoundingBoxTest >> setUpBottomCenterSmallBox [
23+
24+
boundingBox
25+
topLatitudeInDegrees: -1;
26+
rightLongitudeInDegrees: 1;
27+
bottomLatitudeInDegrees: -2;
28+
leftLongitudeInDegrees: -1
29+
]
30+
31+
{ #category : #running }
32+
GeoToolsBoundingBoxTest >> setUpBottomLeftSmallBox [
33+
34+
boundingBox
35+
topLatitudeInDegrees: -1;
36+
rightLongitudeInDegrees: -1;
37+
bottomLatitudeInDegrees: -2;
38+
leftLongitudeInDegrees: -2
39+
]
40+
41+
{ #category : #running }
42+
GeoToolsBoundingBoxTest >> setUpSmallBox [
43+
44+
boundingBox
45+
topLatitudeInDegrees: 1;
46+
rightLongitudeInDegrees: 1;
47+
bottomLatitudeInDegrees: -1;
48+
leftLongitudeInDegrees: -1
49+
]
50+
51+
{ #category : #running }
52+
GeoToolsBoundingBoxTest >> setUpTopCenterSmallBox [
53+
54+
boundingBox
55+
topLatitudeInDegrees: 2;
56+
rightLongitudeInDegrees: 1;
57+
bottomLatitudeInDegrees: 1;
58+
leftLongitudeInDegrees: -1
59+
]
60+
61+
{ #category : #running }
62+
GeoToolsBoundingBoxTest >> setUpTopRightSmallBox [
63+
64+
boundingBox
65+
topLatitudeInDegrees: 2;
66+
rightLongitudeInDegrees: 2;
67+
bottomLatitudeInDegrees: 1;
68+
leftLongitudeInDegrees: 1
69+
]
70+
71+
{ #category : #running }
72+
GeoToolsBoundingBoxTest >> setUpZeroBox [
73+
74+
boundingBox
75+
topLatitudeInDegrees: 0;
76+
rightLongitudeInDegrees: 0;
77+
bottomLatitudeInDegrees: 0;
78+
leftLongitudeInDegrees: 0
79+
]
80+
81+
{ #category : #tests }
82+
GeoToolsBoundingBoxTest >> testBottomLatitudeInDegrees [
83+
84+
self assert: boundingBox bottomLatitudeInDegrees isNil.
85+
86+
boundingBox bottomLatitudeInDegrees: -1.
87+
self assert: boundingBox bottomLatitudeInDegrees equals: -1.
88+
]
89+
90+
{ #category : #tests }
91+
GeoToolsBoundingBoxTest >> testBottomLeftAbsoluteCoordinates [
92+
93+
self assert: boundingBox bottomLeftAbsoluteCoordinates isValid not.
94+
95+
self setUpZeroBox.
96+
self assert: boundingBox bottomLeftAbsoluteCoordinates isValid.
97+
98+
self setUpSmallBox.
99+
self assert: boundingBox bottomLeftAbsoluteCoordinates isValid.
100+
101+
boundingBox bottomLeftAbsoluteCoordinates: AbsoluteCoordinates zero.
102+
self assert: boundingBox bottomLeftAbsoluteCoordinates isValid.
103+
self assert: boundingBox bottomLeftAbsoluteCoordinates isZero.
104+
]
105+
106+
{ #category : #tests }
107+
GeoToolsBoundingBoxTest >> testBottomRightAbsoluteCoordinates [
108+
109+
self assert: boundingBox bottomRightAbsoluteCoordinates isValid not.
110+
111+
self setUpZeroBox.
112+
self assert: boundingBox bottomRightAbsoluteCoordinates isValid.
113+
114+
self setUpSmallBox.
115+
self assert: boundingBox bottomRightAbsoluteCoordinates isValid.
116+
117+
boundingBox bottomRightAbsoluteCoordinates: AbsoluteCoordinates zero.
118+
self assert: boundingBox bottomRightAbsoluteCoordinates isValid.
119+
self assert: boundingBox bottomRightAbsoluteCoordinates isZero.
120+
]
121+
122+
{ #category : #tests }
123+
GeoToolsBoundingBoxTest >> testCenterAbsoluteCoordinates [
124+
125+
self assert: boundingBox centerAbsoluteCoordinates isValid not.
126+
127+
self setUpZeroBox.
128+
self assert: boundingBox centerAbsoluteCoordinates isValid.
129+
self assert: boundingBox centerAbsoluteCoordinates isZero.
130+
131+
self setUpSmallBox.
132+
self assert: boundingBox centerAbsoluteCoordinates isValid.
133+
self assert: boundingBox centerAbsoluteCoordinates isZero.
134+
135+
self setUpTopRightSmallBox.
136+
self assert: boundingBox centerAbsoluteCoordinates isValid.
137+
self assert: boundingBox centerAbsoluteCoordinates latitudeInDegrees equals: 1.5.
138+
self assert: boundingBox centerAbsoluteCoordinates longitudeInDegrees equals: 1.5.
139+
140+
self setUpBottomLeftSmallBox.
141+
self assert: boundingBox centerAbsoluteCoordinates isValid.
142+
self assert: boundingBox centerAbsoluteCoordinates latitudeInDegrees equals: -1.5.
143+
self assert: boundingBox centerAbsoluteCoordinates longitudeInDegrees equals: -1.5.
144+
145+
self setUpTopCenterSmallBox.
146+
self assert: boundingBox centerAbsoluteCoordinates isValid.
147+
self assert: boundingBox centerAbsoluteCoordinates latitudeInDegrees equals: 1.5.
148+
self assert: boundingBox centerAbsoluteCoordinates longitudeInDegrees equals: 0.
149+
150+
self setUpBottomCenterSmallBox.
151+
self assert: boundingBox centerAbsoluteCoordinates isValid.
152+
self assert: boundingBox centerAbsoluteCoordinates latitudeInDegrees equals: -1.5.
153+
self assert: boundingBox centerAbsoluteCoordinates longitudeInDegrees equals: 0.
154+
]
155+
156+
{ #category : #tests }
157+
GeoToolsBoundingBoxTest >> testLeftLongitudeInDegrees [
158+
159+
self assert: boundingBox leftLongitudeInDegrees isNil.
160+
161+
boundingBox leftLongitudeInDegrees: 1.
162+
self assert: boundingBox leftLongitudeInDegrees equals: 1.
163+
]
164+
165+
{ #category : #tests }
166+
GeoToolsBoundingBoxTest >> testMaxLatitudeInDegrees [
167+
168+
self assert: boundingBox maxLatitudeInDegrees isNil.
169+
170+
self setUpZeroBox.
171+
self assert: boundingBox maxLatitudeInDegrees equals: 0.
172+
173+
self setUpSmallBox.
174+
self assert: boundingBox maxLatitudeInDegrees equals: 1.
175+
]
176+
177+
{ #category : #tests }
178+
GeoToolsBoundingBoxTest >> testMaxLongitudeInDegrees [
179+
180+
self assert: boundingBox maxLongitudeInDegrees isNil.
181+
182+
self setUpZeroBox.
183+
self assert: boundingBox maxLongitudeInDegrees equals: 0.
184+
185+
self setUpSmallBox.
186+
self assert: boundingBox maxLongitudeInDegrees equals: 1.
187+
]
188+
189+
{ #category : #tests }
190+
GeoToolsBoundingBoxTest >> testMinLatitudeInDegrees [
191+
192+
self assert: boundingBox minLatitudeInDegrees isNil.
193+
194+
self setUpZeroBox.
195+
self assert: boundingBox minLatitudeInDegrees equals: 0.
196+
197+
self setUpSmallBox.
198+
self assert: boundingBox minLatitudeInDegrees equals: -1.
199+
]
200+
201+
{ #category : #tests }
202+
GeoToolsBoundingBoxTest >> testMinLongitudeInDegrees [
203+
204+
self assert: boundingBox minLongitudeInDegrees isNil.
205+
206+
self setUpZeroBox.
207+
self assert: boundingBox minLongitudeInDegrees equals: 0.
208+
209+
self setUpSmallBox.
210+
self assert: boundingBox minLongitudeInDegrees equals: -1.
211+
]
212+
213+
{ #category : #tests }
214+
GeoToolsBoundingBoxTest >> testOriginCorner [
215+
216+
| box |
217+
box := GeoToolsBoundingBox origin: AbsoluteCoordinates zero corner: AbsoluteCoordinates frParis.
218+
self assert: box centerAbsoluteCoordinates isValid.
219+
]
220+
221+
{ #category : #tests }
222+
GeoToolsBoundingBoxTest >> testRightLongitudeInDegrees [
223+
224+
self assert: boundingBox rightLongitudeInDegrees isNil.
225+
226+
boundingBox rightLongitudeInDegrees: 1.
227+
self assert: boundingBox rightLongitudeInDegrees equals: 1.
228+
]
229+
230+
{ #category : #tests }
231+
GeoToolsBoundingBoxTest >> testTopLatitudeInDegrees [
232+
233+
self assert: boundingBox topLatitudeInDegrees isNil.
234+
235+
boundingBox topLatitudeInDegrees: 1.
236+
self assert: boundingBox topLatitudeInDegrees equals: 1.
237+
]
238+
239+
{ #category : #tests }
240+
GeoToolsBoundingBoxTest >> testTopLeftAbsoluteCoordinates [
241+
242+
self assert: boundingBox topLeftAbsoluteCoordinates isValid not.
243+
244+
self setUpZeroBox.
245+
self assert: boundingBox topLeftAbsoluteCoordinates isValid.
246+
247+
self setUpSmallBox.
248+
self assert: boundingBox topLeftAbsoluteCoordinates isValid.
249+
250+
boundingBox topLeftAbsoluteCoordinates: AbsoluteCoordinates zero.
251+
self assert: boundingBox topLeftAbsoluteCoordinates isValid.
252+
self assert: boundingBox topLeftAbsoluteCoordinates isZero.
253+
]
254+
255+
{ #category : #tests }
256+
GeoToolsBoundingBoxTest >> testTopLeftBottomRight [
257+
258+
| box |
259+
box := GeoToolsBoundingBox topLeft: AbsoluteCoordinates zero bottomRight: AbsoluteCoordinates frParis.
260+
self assert: box centerAbsoluteCoordinates isValid.
261+
]
262+
263+
{ #category : #tests }
264+
GeoToolsBoundingBoxTest >> testTopRightAbsoluteCoordinates [
265+
266+
self assert: boundingBox topRightAbsoluteCoordinates isValid not.
267+
268+
self setUpZeroBox.
269+
self assert: boundingBox topRightAbsoluteCoordinates isValid.
270+
271+
self setUpSmallBox.
272+
self assert: boundingBox topRightAbsoluteCoordinates isValid.
273+
274+
boundingBox topRightAbsoluteCoordinates: AbsoluteCoordinates zero.
275+
self assert: boundingBox topRightAbsoluteCoordinates isValid.
276+
self assert: boundingBox topRightAbsoluteCoordinates isZero.
277+
]

src/GeoTools/AbsoluteCoordinates.class.st

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,12 +590,25 @@ AbsoluteCoordinates >> isEmpty [
590590
^ self latitudeInDegrees isNil and: [ self longitudeInDegrees isNil and: [ self altitudeInMeters isNil ] ]
591591
]
592592
593+
{ #category : #testing }
594+
AbsoluteCoordinates >> isLatLonZero [
595+
596+
^ self latitudeInDegrees = 0 and: [ self longitudeInDegrees = 0 ]
597+
]
598+
593599
{ #category : #accessing }
594600
AbsoluteCoordinates >> isValid [
595601
596602
^ self latitudeInDegrees notNil and: [ self longitudeInDegrees notNil ]
597603
]
598604
605+
{ #category : #testing }
606+
AbsoluteCoordinates >> isZero [
607+
608+
^ self isLatLonZero and: [
609+
self altitudeInMeters = 0 or: [ self altitudeInMeters isNil ] ]
610+
]
611+
599612
{ #category : #accessing }
600613
AbsoluteCoordinates >> latitude [
601614
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Class {
2+
#name : #GeoToolsBoundingBox,
3+
#superclass : #Object,
4+
#traits : 'TGeoToolsBoundingBox',
5+
#classTraits : 'TGeoToolsBoundingBox classTrait',
6+
#category : #'GeoTools-Coordinates'
7+
}

0 commit comments

Comments
 (0)