diff --git a/src/GeoTools-Tests/AbsoluteCoordinatesTest.class.st b/src/GeoTools-Tests/AbsoluteCoordinatesTest.class.st index 9923629..97ef472 100644 --- a/src/GeoTools-Tests/AbsoluteCoordinatesTest.class.st +++ b/src/GeoTools-Tests/AbsoluteCoordinatesTest.class.st @@ -271,21 +271,29 @@ AbsoluteCoordinatesTest >> testFromStringLatitudeLongitude [ ] { #category : #tests } -AbsoluteCoordinatesTest >> testZero [ +AbsoluteCoordinatesTest >> testIsLatLonZero [ | coord | - coord := AbsoluteCoordinates zero. + coord := AbsoluteCoordinates zeroLatLon. self assert: coord latitudeInDegrees equals: 0. self assert: coord longitudeInDegrees equals: 0. - self assert: coord altitudeInMeters equals: 0 + self assert: coord altitudeInMeters isNil. + self assert: coord isLatLonZero. + self assert: coord isZero. + + coord altitudeInMeters: 20. + self assert: coord isLatLonZero. + self deny: coord isZero. ] { #category : #tests } -AbsoluteCoordinatesTest >> testZeroLatLon [ +AbsoluteCoordinatesTest >> testIsZero [ | coord | - coord := AbsoluteCoordinates zeroLatLon. + coord := AbsoluteCoordinates zero. self assert: coord latitudeInDegrees equals: 0. self assert: coord longitudeInDegrees equals: 0. - self assert: coord altitudeInMeters isNil + self assert: coord altitudeInMeters equals: 0. + self assert: coord isLatLonZero. + self assert: coord isZero. ] diff --git a/src/GeoTools-Tests/GeoToolsBoundingBoxTest.class.st b/src/GeoTools-Tests/GeoToolsBoundingBoxTest.class.st new file mode 100644 index 0000000..02d09ab --- /dev/null +++ b/src/GeoTools-Tests/GeoToolsBoundingBoxTest.class.st @@ -0,0 +1,277 @@ +" +A TGeoBoundingBoxTest is a test class for testing the behavior of TGeoBoundingBox +" +Class { + #name : #GeoToolsBoundingBoxTest, + #superclass : #TestCase, + #instVars : [ + 'boundingBox' + ], + #category : #'GeoTools-Tests-Coordinates' +} + +{ #category : #running } +GeoToolsBoundingBoxTest >> setUp [ + + super setUp. + + boundingBox := GeoToolsBoundingBox new +] + +{ #category : #running } +GeoToolsBoundingBoxTest >> setUpBottomCenterSmallBox [ + + boundingBox + topLatitudeInDegrees: -1; + rightLongitudeInDegrees: 1; + bottomLatitudeInDegrees: -2; + leftLongitudeInDegrees: -1 +] + +{ #category : #running } +GeoToolsBoundingBoxTest >> setUpBottomLeftSmallBox [ + + boundingBox + topLatitudeInDegrees: -1; + rightLongitudeInDegrees: -1; + bottomLatitudeInDegrees: -2; + leftLongitudeInDegrees: -2 +] + +{ #category : #running } +GeoToolsBoundingBoxTest >> setUpSmallBox [ + + boundingBox + topLatitudeInDegrees: 1; + rightLongitudeInDegrees: 1; + bottomLatitudeInDegrees: -1; + leftLongitudeInDegrees: -1 +] + +{ #category : #running } +GeoToolsBoundingBoxTest >> setUpTopCenterSmallBox [ + + boundingBox + topLatitudeInDegrees: 2; + rightLongitudeInDegrees: 1; + bottomLatitudeInDegrees: 1; + leftLongitudeInDegrees: -1 +] + +{ #category : #running } +GeoToolsBoundingBoxTest >> setUpTopRightSmallBox [ + + boundingBox + topLatitudeInDegrees: 2; + rightLongitudeInDegrees: 2; + bottomLatitudeInDegrees: 1; + leftLongitudeInDegrees: 1 +] + +{ #category : #running } +GeoToolsBoundingBoxTest >> setUpZeroBox [ + + boundingBox + topLatitudeInDegrees: 0; + rightLongitudeInDegrees: 0; + bottomLatitudeInDegrees: 0; + leftLongitudeInDegrees: 0 +] + +{ #category : #tests } +GeoToolsBoundingBoxTest >> testBottomLatitudeInDegrees [ + + self assert: boundingBox bottomLatitudeInDegrees isNil. + + boundingBox bottomLatitudeInDegrees: -1. + self assert: boundingBox bottomLatitudeInDegrees equals: -1. +] + +{ #category : #tests } +GeoToolsBoundingBoxTest >> testBottomLeftAbsoluteCoordinates [ + + self assert: boundingBox bottomLeftAbsoluteCoordinates isValid not. + + self setUpZeroBox. + self assert: boundingBox bottomLeftAbsoluteCoordinates isValid. + + self setUpSmallBox. + self assert: boundingBox bottomLeftAbsoluteCoordinates isValid. + + boundingBox bottomLeftAbsoluteCoordinates: AbsoluteCoordinates zero. + self assert: boundingBox bottomLeftAbsoluteCoordinates isValid. + self assert: boundingBox bottomLeftAbsoluteCoordinates isZero. +] + +{ #category : #tests } +GeoToolsBoundingBoxTest >> testBottomRightAbsoluteCoordinates [ + + self assert: boundingBox bottomRightAbsoluteCoordinates isValid not. + + self setUpZeroBox. + self assert: boundingBox bottomRightAbsoluteCoordinates isValid. + + self setUpSmallBox. + self assert: boundingBox bottomRightAbsoluteCoordinates isValid. + + boundingBox bottomRightAbsoluteCoordinates: AbsoluteCoordinates zero. + self assert: boundingBox bottomRightAbsoluteCoordinates isValid. + self assert: boundingBox bottomRightAbsoluteCoordinates isZero. +] + +{ #category : #tests } +GeoToolsBoundingBoxTest >> testCenterAbsoluteCoordinates [ + + self assert: boundingBox centerAbsoluteCoordinates isValid not. + + self setUpZeroBox. + self assert: boundingBox centerAbsoluteCoordinates isValid. + self assert: boundingBox centerAbsoluteCoordinates isZero. + + self setUpSmallBox. + self assert: boundingBox centerAbsoluteCoordinates isValid. + self assert: boundingBox centerAbsoluteCoordinates isZero. + + self setUpTopRightSmallBox. + self assert: boundingBox centerAbsoluteCoordinates isValid. + self assert: boundingBox centerAbsoluteCoordinates latitudeInDegrees equals: 1.5. + self assert: boundingBox centerAbsoluteCoordinates longitudeInDegrees equals: 1.5. + + self setUpBottomLeftSmallBox. + self assert: boundingBox centerAbsoluteCoordinates isValid. + self assert: boundingBox centerAbsoluteCoordinates latitudeInDegrees equals: -1.5. + self assert: boundingBox centerAbsoluteCoordinates longitudeInDegrees equals: -1.5. + + self setUpTopCenterSmallBox. + self assert: boundingBox centerAbsoluteCoordinates isValid. + self assert: boundingBox centerAbsoluteCoordinates latitudeInDegrees equals: 1.5. + self assert: boundingBox centerAbsoluteCoordinates longitudeInDegrees equals: 0. + + self setUpBottomCenterSmallBox. + self assert: boundingBox centerAbsoluteCoordinates isValid. + self assert: boundingBox centerAbsoluteCoordinates latitudeInDegrees equals: -1.5. + self assert: boundingBox centerAbsoluteCoordinates longitudeInDegrees equals: 0. +] + +{ #category : #tests } +GeoToolsBoundingBoxTest >> testLeftLongitudeInDegrees [ + + self assert: boundingBox leftLongitudeInDegrees isNil. + + boundingBox leftLongitudeInDegrees: 1. + self assert: boundingBox leftLongitudeInDegrees equals: 1. +] + +{ #category : #tests } +GeoToolsBoundingBoxTest >> testMaxLatitudeInDegrees [ + + self assert: boundingBox maxLatitudeInDegrees isNil. + + self setUpZeroBox. + self assert: boundingBox maxLatitudeInDegrees equals: 0. + + self setUpSmallBox. + self assert: boundingBox maxLatitudeInDegrees equals: 1. +] + +{ #category : #tests } +GeoToolsBoundingBoxTest >> testMaxLongitudeInDegrees [ + + self assert: boundingBox maxLongitudeInDegrees isNil. + + self setUpZeroBox. + self assert: boundingBox maxLongitudeInDegrees equals: 0. + + self setUpSmallBox. + self assert: boundingBox maxLongitudeInDegrees equals: 1. +] + +{ #category : #tests } +GeoToolsBoundingBoxTest >> testMinLatitudeInDegrees [ + + self assert: boundingBox minLatitudeInDegrees isNil. + + self setUpZeroBox. + self assert: boundingBox minLatitudeInDegrees equals: 0. + + self setUpSmallBox. + self assert: boundingBox minLatitudeInDegrees equals: -1. +] + +{ #category : #tests } +GeoToolsBoundingBoxTest >> testMinLongitudeInDegrees [ + + self assert: boundingBox minLongitudeInDegrees isNil. + + self setUpZeroBox. + self assert: boundingBox minLongitudeInDegrees equals: 0. + + self setUpSmallBox. + self assert: boundingBox minLongitudeInDegrees equals: -1. +] + +{ #category : #tests } +GeoToolsBoundingBoxTest >> testOriginCorner [ + + | box | + box := GeoToolsBoundingBox origin: AbsoluteCoordinates zero corner: AbsoluteCoordinates frParis. + self assert: box centerAbsoluteCoordinates isValid. +] + +{ #category : #tests } +GeoToolsBoundingBoxTest >> testRightLongitudeInDegrees [ + + self assert: boundingBox rightLongitudeInDegrees isNil. + + boundingBox rightLongitudeInDegrees: 1. + self assert: boundingBox rightLongitudeInDegrees equals: 1. +] + +{ #category : #tests } +GeoToolsBoundingBoxTest >> testTopLatitudeInDegrees [ + + self assert: boundingBox topLatitudeInDegrees isNil. + + boundingBox topLatitudeInDegrees: 1. + self assert: boundingBox topLatitudeInDegrees equals: 1. +] + +{ #category : #tests } +GeoToolsBoundingBoxTest >> testTopLeftAbsoluteCoordinates [ + + self assert: boundingBox topLeftAbsoluteCoordinates isValid not. + + self setUpZeroBox. + self assert: boundingBox topLeftAbsoluteCoordinates isValid. + + self setUpSmallBox. + self assert: boundingBox topLeftAbsoluteCoordinates isValid. + + boundingBox topLeftAbsoluteCoordinates: AbsoluteCoordinates zero. + self assert: boundingBox topLeftAbsoluteCoordinates isValid. + self assert: boundingBox topLeftAbsoluteCoordinates isZero. +] + +{ #category : #tests } +GeoToolsBoundingBoxTest >> testTopLeftBottomRight [ + + | box | + box := GeoToolsBoundingBox topLeft: AbsoluteCoordinates zero bottomRight: AbsoluteCoordinates frParis. + self assert: box centerAbsoluteCoordinates isValid. +] + +{ #category : #tests } +GeoToolsBoundingBoxTest >> testTopRightAbsoluteCoordinates [ + + self assert: boundingBox topRightAbsoluteCoordinates isValid not. + + self setUpZeroBox. + self assert: boundingBox topRightAbsoluteCoordinates isValid. + + self setUpSmallBox. + self assert: boundingBox topRightAbsoluteCoordinates isValid. + + boundingBox topRightAbsoluteCoordinates: AbsoluteCoordinates zero. + self assert: boundingBox topRightAbsoluteCoordinates isValid. + self assert: boundingBox topRightAbsoluteCoordinates isZero. +] diff --git a/src/GeoTools/AbsoluteCoordinates.class.st b/src/GeoTools/AbsoluteCoordinates.class.st index 31b0e4c..e0b3634 100644 --- a/src/GeoTools/AbsoluteCoordinates.class.st +++ b/src/GeoTools/AbsoluteCoordinates.class.st @@ -590,12 +590,25 @@ AbsoluteCoordinates >> isEmpty [ ^ self latitudeInDegrees isNil and: [ self longitudeInDegrees isNil and: [ self altitudeInMeters isNil ] ] ] +{ #category : #testing } +AbsoluteCoordinates >> isLatLonZero [ + + ^ self latitudeInDegrees = 0 and: [ self longitudeInDegrees = 0 ] +] + { #category : #accessing } AbsoluteCoordinates >> isValid [ ^ self latitudeInDegrees notNil and: [ self longitudeInDegrees notNil ] ] +{ #category : #testing } +AbsoluteCoordinates >> isZero [ + + ^ self isLatLonZero and: [ + self altitudeInMeters = 0 or: [ self altitudeInMeters isNil ] ] +] + { #category : #accessing } AbsoluteCoordinates >> latitude [ diff --git a/src/GeoTools/GeoToolsBoundingBox.class.st b/src/GeoTools/GeoToolsBoundingBox.class.st new file mode 100644 index 0000000..f55b0c2 --- /dev/null +++ b/src/GeoTools/GeoToolsBoundingBox.class.st @@ -0,0 +1,7 @@ +Class { + #name : #GeoToolsBoundingBox, + #superclass : #Object, + #traits : 'TGeoToolsBoundingBox', + #classTraits : 'TGeoToolsBoundingBox classTrait', + #category : #'GeoTools-Coordinates' +} diff --git a/src/GeoTools/TGeoToolsBoundingBox.trait.st b/src/GeoTools/TGeoToolsBoundingBox.trait.st new file mode 100644 index 0000000..39156e0 --- /dev/null +++ b/src/GeoTools/TGeoToolsBoundingBox.trait.st @@ -0,0 +1,181 @@ +Trait { + #name : #TGeoToolsBoundingBox, + #instVars : [ + 'topLatitudeInDegrees', + 'rightLongitudeInDegrees', + 'bottomLatitudeInDegrees', + 'leftLongitudeInDegrees' + ], + #category : #'GeoTools-Coordinates' +} + +{ #category : #constructor } +TGeoToolsBoundingBox classSide >> origin: aFromAbsolutePosition corner: aToAbsolutePostion [ + + ^ self topLeft: aFromAbsolutePosition bottomRight: aToAbsolutePostion +] + +{ #category : #constructor } +TGeoToolsBoundingBox classSide >> topLeft: aFromAbsolutePosition bottomRight: aToAbsolutePostion [ + + | box | + box := self new. + box topLeftAbsoluteCoordinates: aFromAbsolutePosition. + box bottomRightAbsoluteCoordinates: aToAbsolutePostion. + ^ box +] + +{ #category : #accessing } +TGeoToolsBoundingBox >> bottomLatitudeInDegrees [ + + ^ bottomLatitudeInDegrees +] + +{ #category : #accessing } +TGeoToolsBoundingBox >> bottomLatitudeInDegrees: anObject [ + + bottomLatitudeInDegrees := anObject +] + +{ #category : #points } +TGeoToolsBoundingBox >> bottomLeftAbsoluteCoordinates [ + + ^ AbsoluteCoordinates + latitudeInDegrees: self bottomLatitudeInDegrees + longitudeInDegrees: self leftLongitudeInDegrees +] + +{ #category : #points } +TGeoToolsBoundingBox >> bottomLeftAbsoluteCoordinates: anAbsoluteCoordinates [ + + self bottomLatitudeInDegrees: anAbsoluteCoordinates latitudeInDegrees. + self leftLongitudeInDegrees: anAbsoluteCoordinates longitudeInDegrees +] + +{ #category : #points } +TGeoToolsBoundingBox >> bottomRightAbsoluteCoordinates [ + + ^ AbsoluteCoordinates + latitudeInDegrees: self bottomLatitudeInDegrees + longitudeInDegrees: self rightLongitudeInDegrees +] + +{ #category : #points } +TGeoToolsBoundingBox >> bottomRightAbsoluteCoordinates: anAbsoluteCoordinates [ + + self bottomLatitudeInDegrees: anAbsoluteCoordinates latitudeInDegrees. + self rightLongitudeInDegrees: anAbsoluteCoordinates longitudeInDegrees +] + +{ #category : #points } +TGeoToolsBoundingBox >> centerAbsoluteCoordinates [ + + | latitude longitude | + latitude := (self topLatitudeInDegrees isNil or: [ + self bottomLatitudeInDegrees isNil ]) + ifTrue: [ nil ] + ifFalse: [ + self topLatitudeInDegrees + + self bottomLatitudeInDegrees / 2 ]. + + longitude := (self leftLongitudeInDegrees isNil or: [ + self rightLongitudeInDegrees isNil ]) + ifTrue: [ nil ] + ifFalse: [ + self leftLongitudeInDegrees + + self rightLongitudeInDegrees / 2 ]. + + ^ AbsoluteCoordinates + latitudeInDegrees: latitude + longitudeInDegrees: longitude +] + +{ #category : #accessing } +TGeoToolsBoundingBox >> leftLongitudeInDegrees [ + + ^ leftLongitudeInDegrees +] + +{ #category : #accessing } +TGeoToolsBoundingBox >> leftLongitudeInDegrees: anObject [ + + leftLongitudeInDegrees := anObject +] + +{ #category : #'limits ' } +TGeoToolsBoundingBox >> maxLatitudeInDegrees [ + + ^ self topLatitudeInDegrees +] + +{ #category : #'limits ' } +TGeoToolsBoundingBox >> maxLongitudeInDegrees [ + + ^ self rightLongitudeInDegrees +] + +{ #category : #'limits ' } +TGeoToolsBoundingBox >> minLatitudeInDegrees [ + + ^ self bottomLatitudeInDegrees +] + +{ #category : #'limits ' } +TGeoToolsBoundingBox >> minLongitudeInDegrees [ + + ^ self leftLongitudeInDegrees +] + +{ #category : #accessing } +TGeoToolsBoundingBox >> rightLongitudeInDegrees [ + + ^ rightLongitudeInDegrees +] + +{ #category : #accessing } +TGeoToolsBoundingBox >> rightLongitudeInDegrees: anObject [ + + rightLongitudeInDegrees := anObject +] + +{ #category : #accessing } +TGeoToolsBoundingBox >> topLatitudeInDegrees [ + + ^ topLatitudeInDegrees +] + +{ #category : #accessing } +TGeoToolsBoundingBox >> topLatitudeInDegrees: anObject [ + + topLatitudeInDegrees := anObject +] + +{ #category : #points } +TGeoToolsBoundingBox >> topLeftAbsoluteCoordinates [ + + ^ AbsoluteCoordinates + latitudeInDegrees: self topLatitudeInDegrees + longitudeInDegrees: self leftLongitudeInDegrees +] + +{ #category : #points } +TGeoToolsBoundingBox >> topLeftAbsoluteCoordinates: anAbsoluteCoordinates [ + + self topLatitudeInDegrees: anAbsoluteCoordinates latitudeInDegrees. + self leftLongitudeInDegrees: anAbsoluteCoordinates longitudeInDegrees +] + +{ #category : #points } +TGeoToolsBoundingBox >> topRightAbsoluteCoordinates [ + + ^ AbsoluteCoordinates + latitudeInDegrees: self topLatitudeInDegrees + longitudeInDegrees: self rightLongitudeInDegrees +] + +{ #category : #points } +TGeoToolsBoundingBox >> topRightAbsoluteCoordinates: anAbsoluteCoordinates [ + + self topLatitudeInDegrees: anAbsoluteCoordinates latitudeInDegrees. + self rightLongitudeInDegrees: anAbsoluteCoordinates longitudeInDegrees +]