Skip to content

Commit

Permalink
Refactoring + robutness
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre Laborde committed Dec 15, 2023
1 parent b75de9b commit 905e213
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 33 deletions.
60 changes: 41 additions & 19 deletions GeoTools/AbsoluteCoordinates.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ AbsoluteCoordinates class >> usaSeattle [

{ #category : #'instance creation' }
AbsoluteCoordinates class >> zero [
^self latitudeInDegrees: 0 longitudeInDegrees: 0 altitudeInMeters: 0

^ self latitudeInDegrees: 0 longitudeInDegrees: 0 altitudeInMeters: 0
]

{ #category : #comparing }
Expand All @@ -166,41 +167,46 @@ AbsoluteCoordinates >> = anAbsoluteCoordinates [

{ #category : #accessing }
AbsoluteCoordinates >> altitude [
self altitudeInMeters ifNil:[^nil].

self altitudeInMeters ifNil: [ ^ nil ].
^ self altitudeInMeters units: #meters
]

{ #category : #accessing }
AbsoluteCoordinates >> altitudeInMeters [

^ altitudeInMeters
]

{ #category : #accessing }
AbsoluteCoordinates >> altitudeInMeters: aNumber [

altitudeInMeters := aNumber
]

{ #category : #converting }
AbsoluteCoordinates >> asLatLonDegreesPoint [
self latitudeInDegrees ifNil:[^nil].
self longitudeInDegrees ifNil:[^nil].
^self latitudeInDegrees @ self longitudeInDegrees

self isValid ifFalse: [ ^ nil ].
^ self latitudeInDegrees @ self longitudeInDegrees
]

{ #category : #converting }
AbsoluteCoordinates >> asLatLonRadiansPoint [
self latitudeInDegrees ifNil:[^nil].
self longitudeInDegrees ifNil:[^nil].
^self latitudeInRadians @ self longitudeInRadians

self isValid ifFalse: [ ^ nil ].
^ self latitudeInRadians @ self longitudeInRadians
]

{ #category : #converting }
AbsoluteCoordinates >> asPoint [
^self asLatLonDegreesPoint

^ self asLatLonDegreesPoint
]

{ #category : #copying }
AbsoluteCoordinates >> copy [

| copy |
copy := super copy.
copy altitudeInMeters: self altitudeInMeters.
Expand All @@ -210,69 +216,84 @@ AbsoluteCoordinates >> copy [
]

{ #category : #accessing }
AbsoluteCoordinates >> isEmpty [
^self latitudeInDegrees isNil and:[self longitudeInDegrees isNil and:[self altitudeInMeters isNil]]
AbsoluteCoordinates >> isEmpty [

^ self latitudeInDegrees isNil and: [ self longitudeInDegrees isNil and: [ self altitudeInMeters isNil ] ]
]

{ #category : #accessing }
AbsoluteCoordinates >> isValid [
^self latitudeInDegrees notNil and:[self longitudeInDegrees notNil]
AbsoluteCoordinates >> isValid [

^ self latitudeInDegrees notNil and: [ self longitudeInDegrees notNil ]
]

{ #category : #accessing }
AbsoluteCoordinates >> latitude [
self latitudeInDegrees ifNil:[^nil].

self latitudeInDegrees ifNil: [ ^ nil ].
^ self latitudeInDegrees units: #arcdegree
]

{ #category : #accessing }
AbsoluteCoordinates >> latitudeInDegrees [

^ latitudeInDegrees
]

{ #category : #accessing }
AbsoluteCoordinates >> latitudeInDegrees: anObject [
latitudeInDegrees := self normalizeLatitudeInDegrees: anObject.

latitudeInDegrees := self normalizeLatitudeInDegrees: anObject
]

{ #category : #accessing }
AbsoluteCoordinates >> latitudeInRadians [
^ latitudeInDegrees degreesToRadians

^ latitudeInDegrees ifNotNil:[ :e | e degreesToRadians ]
]

{ #category : #accessing }
AbsoluteCoordinates >> latitudeInRadians: anObject [

anObject ifNil:[ latitudeInDegrees := nil. ^ self ].
self latitudeInDegrees: anObject radiansToDegrees
]

{ #category : #accessing }
AbsoluteCoordinates >> longitude [
self longitudeInDegrees ifNil:[^nil].

self longitudeInDegrees ifNil: [ ^ nil ].
^ self longitudeInDegrees units: #arcdegree
]

{ #category : #accessing }
AbsoluteCoordinates >> longitudeInDegrees [

^ longitudeInDegrees
]

{ #category : #accessing }
AbsoluteCoordinates >> longitudeInDegrees: anObject [

longitudeInDegrees := self wrapLongitude: anObject
]

{ #category : #accessing }
AbsoluteCoordinates >> longitudeInRadians [
^ longitudeInDegrees degreesToRadians

^ longitudeInDegrees ifNotNil:[ :e | e degreesToRadians ]
]

{ #category : #accessing }
AbsoluteCoordinates >> longitudeInRadians: anObject [
self longitudeInDegrees: anObject radiansToDegrees

anObject ifNil:[ longitudeInDegrees := nil. ^ self ].
self longitudeInDegrees: anObject radiansToDegrees
]

{ #category : #accessing }
AbsoluteCoordinates >> normalizeLatitudeInDegrees: aValueInDegrees [

aValueInDegrees ifNil: [ ^aValueInDegrees ].
aValueInDegrees > 90 ifTrue: [ ^ 90 ].
aValueInDegrees < -90 ifTrue: [ ^ -90 ].
Expand All @@ -290,6 +311,7 @@ AbsoluteCoordinates >> printOn: aStream [

{ #category : #accessing }
AbsoluteCoordinates >> wrapLongitude: aValueInDegrees [

| result |
aValueInDegrees ifNil: [ ^aValueInDegrees ].
result := aValueInDegrees.
Expand Down
27 changes: 18 additions & 9 deletions GeoTools/CartesianCoordinates.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ CartesianCoordinates class >> xInMeters: aXMeters yInMeters: aYMeters zInMeters:

{ #category : #'instance creation' }
CartesianCoordinates class >> zero [
^self xInMeters: 0 yInMeters: 0 zInMeters: 0

^ self xInMeters: 0 yInMeters: 0 zInMeters: 0
]

{ #category : #comparing }
Expand All @@ -48,14 +49,14 @@ CartesianCoordinates >> = aCartesianCoordinates [

{ #category : #copying }
CartesianCoordinates >> asPoint [
self xInMeters ifNil:[^nil].
self yInMeters ifNil:[^nil].
^self xInMeters @ self yInMeters


self isValid ifFalse: [ ^ nil ].
^ self xInMeters @ self yInMeters
]

{ #category : #copying }
CartesianCoordinates >> copy [

| copy |
copy := super copy.
copy xInMeters: self xInMeters.
Expand All @@ -65,13 +66,15 @@ CartesianCoordinates >> copy [
]

{ #category : #testing }
CartesianCoordinates >> isEmpty [
^self xInMeters isNil and:[self yInMeters isNil and:[self zInMeters isNil]]
CartesianCoordinates >> isEmpty [

^ self xInMeters isNil and: [ self yInMeters isNil and: [ self zInMeters isNil ] ]
]

{ #category : #testing }
CartesianCoordinates >> isValid [
^self xInMeters notNil and:[self yInMeters notNil]
CartesianCoordinates >> isValid [

^ self xInMeters notNil and: [ self yInMeters notNil ]
]

{ #category : #printing }
Expand All @@ -86,30 +89,36 @@ CartesianCoordinates >> printOn: aStream [

{ #category : #accessing }
CartesianCoordinates >> xInMeters [

^ xInMeters
]

{ #category : #accessing }
CartesianCoordinates >> xInMeters: anObject [

xInMeters := anObject
]

{ #category : #accessing }
CartesianCoordinates >> yInMeters [

^ yInMeters
]

{ #category : #accessing }
CartesianCoordinates >> yInMeters: anObject [

yInMeters := anObject
]

{ #category : #accessing }
CartesianCoordinates >> zInMeters [

^ zInMeters
]

{ #category : #accessing }
CartesianCoordinates >> zInMeters: anObject [

zInMeters := anObject
]
33 changes: 28 additions & 5 deletions GeoTools/PolarCoordinates.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ PolarCoordinates class >> azimuthInRadians: anAzimuth distanceInMeters: aDistanc

{ #category : #'instance creation' }
PolarCoordinates class >> zero [
^self azimuthInRadians: 0 distanceInMeters: 0 elevationInMeters: 0

^ self azimuthInRadians: 0 distanceInMeters: 0 elevationInMeters: 0
]

{ #category : #comparing }
Expand All @@ -52,18 +53,34 @@ PolarCoordinates >> asCartesianCoordinates [
zInMeters: self azimuthInRadians sin * self distanceInMeters
]

{ #category : #testing }
PolarCoordinates >> asPoint [

self isValid ifFalse:[ ^ nil ].
^ self azimuthInDegrees @ self distanceInMeters
]

{ #category : #accessing }
PolarCoordinates >> azimuthInDegrees [

^ azimuthInRadians ifNotNil: [ :e | e radiansToDegrees ]
]

{ #category : #accessing }
PolarCoordinates >> azimuthInRadians [

^ azimuthInRadians
]

{ #category : #accessing }
PolarCoordinates >> azimuthInRadians: anObject [

azimuthInRadians := anObject
]

{ #category : #copying }
PolarCoordinates >> copy [

| copy |
copy := super copy.
copy azimuthInRadians: self azimuthInRadians.
Expand All @@ -74,32 +91,38 @@ PolarCoordinates >> copy [

{ #category : #accessing }
PolarCoordinates >> distanceInMeters [

^ distanceInMeters
]

{ #category : #accessing }
PolarCoordinates >> distanceInMeters: anObject [

distanceInMeters := anObject
]

{ #category : #accessing }
PolarCoordinates >> elevationInMeters [

^ elevationInMeters
]

{ #category : #accessing }
PolarCoordinates >> elevationInMeters: anObject [

elevationInMeters := anObject
]

{ #category : #testing }
PolarCoordinates >> isEmpty [
^self azimuthInRadians isNil and:[self distanceInMeters isNil and:[self elevationInMeters isNil]]
PolarCoordinates >> isEmpty [

^ self azimuthInRadians isNil and: [ self distanceInMeters isNil and: [ self elevationInMeters isNil ] ]
]

{ #category : #testing }
PolarCoordinates >> isValid [
^self azimuthInRadians notNil and:[self distanceInMeters notNil]
PolarCoordinates >> isValid [

^ self azimuthInRadians notNil and: [ self distanceInMeters notNil ]
]

{ #category : #copying }
Expand Down

0 comments on commit 905e213

Please sign in to comment.