Skip to content

Commit

Permalink
Fix check angle
Browse files Browse the repository at this point in the history
  • Loading branch information
LANDAISB committed Mar 1, 2024
1 parent 5068888 commit 56c7338
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 16 deletions.
56 changes: 56 additions & 0 deletions GeoView-Tests/GeodesicUtilitiesTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,41 @@ Class {
#category : #'GeoView-Tests-MapProjection'
}

{ #category : #tests }
GeodesicUtilitiesTest >> testCheckAngleIsBetweenTwoOthers [

| result |
result := GeodesicUtilities checkAngle: 0 isBetween: 340 degreesToRadians and: 15 degreesToRadians.
self assert: result equals: true.
result := GeodesicUtilities checkAngle: 14 degreesToRadians isBetween: 340 degreesToRadians and: 15 degreesToRadians.
self assert: result equals: true.
result := GeodesicUtilities checkAngle: 341 degreesToRadians isBetween: 340 degreesToRadians and: 15 degreesToRadians.
self assert: result equals: true.
result := GeodesicUtilities checkAngle: 15 degreesToRadians isBetween: 340 degreesToRadians and: 15 degreesToRadians.
self assert: result equals: true.
result := GeodesicUtilities checkAngle: 340 degreesToRadians isBetween: 340 degreesToRadians and: 15 degreesToRadians.
self assert: result equals: true.
result := GeodesicUtilities checkAngle: 16 degreesToRadians isBetween: 340 degreesToRadians and: 15 degreesToRadians.
self assert: result equals: false.

result := GeodesicUtilities checkAngle: 55 degreesToRadians isBetween: 15 degreesToRadians and: 91 degreesToRadians.
self assert: result equals: true.
result := GeodesicUtilities checkAngle: 155 degreesToRadians isBetween: 15 degreesToRadians and: 91 degreesToRadians.
self assert: result equals: false.
result := GeodesicUtilities checkAngle: 155 degreesToRadians isBetween: 91 degreesToRadians and: 180 degreesToRadians.
self assert: result equals: true.

result := GeodesicUtilities checkAngle: 180 degreesToRadians isBetween: 175 degreesToRadians and: 180 degreesToRadians.
self assert: result equals: true.
result := GeodesicUtilities checkAngle: -40 degreesToRadians isBetween: 225 degreesToRadians and: 321 degreesToRadians.
self assert: result equals: true.
result := GeodesicUtilities checkAngle: 345 degreesToRadians isBetween: 215 degreesToRadians and: 321 degreesToRadians.
self assert: result equals: false.

result := GeodesicUtilities checkAngle: -45 degreesToRadians isBetween: 26.21 degreesToRadians and: 89.969 degreesToRadians.
self assert: result equals: false.
]

{ #category : #tests }
GeodesicUtilitiesTest >> testConvertGeodesicToAzimuthInRadiansFromTwoPoints [

Expand Down Expand Up @@ -105,3 +140,24 @@ GeodesicUtilitiesTest >> testIsAzimuthTowardsArea [


]

{ #category : #tests }
GeodesicUtilitiesTest >> testIsAzimuthTowardsRectangleArea [

| originPointAbsCoord isAzTowardsArea listPointsArea headingInDegree|

originPointAbsCoord := AbsoluteCoordinates latitudeInDegrees: 48.20146040354154 longitudeInDegrees: -4.492.

listPointsArea := OrderedCollection new.
listPointsArea add: (AbsoluteCoordinates latitudeInDegrees: 48.20998 longitudeInDegrees: -4.493).
listPointsArea add: (AbsoluteCoordinates latitudeInDegrees: 48.20998 longitudeInDegrees: -4.491).
listPointsArea add: (AbsoluteCoordinates latitudeInDegrees: 48.208 longitudeInDegrees: -4.491).
listPointsArea add: (AbsoluteCoordinates latitudeInDegrees: 48.208 longitudeInDegrees: -4.493).

headingInDegree := 0.

isAzTowardsArea := GeodesicUtilities isAzimuthTowardsAreaFrom: originPointAbsCoord azimuth: headingInDegree area: listPointsArea.

self assert: isAzTowardsArea equals: true.

]
49 changes: 33 additions & 16 deletions GeoView/GeodesicUtilities.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,22 @@ GeodesicUtilities class >> absoluteCoordinatesFrom: anAbsoluteCoordinates distan
^absoluteCoordinates
]

{ #category : #tools }
GeodesicUtilities class >> checkAngle: anAngleInRad isBetween: aStartValueInRad and: anEndValueInRad [

| end middle |

(anAngleInRad closeTo: aStartValueInRad precision: 1e-7) ifTrue:[^true].

end := anEndValueInRad - aStartValueInRad.
end negative ifTrue:[ end := end + (2*Float pi)].

middle := anAngleInRad - aStartValueInRad.
middle negative ifTrue:[ middle := middle + (2*Float pi)].

^middle <= end
]

{ #category : #private }
GeodesicUtilities class >> computeECEFXYZ: anOriginAbsoluteCoordinates fromLocalXYZ: aLocalCartesianCoordinates [

Expand Down Expand Up @@ -269,26 +285,27 @@ GeodesicUtilities class >> isAzimuthTowardsAreaFrom: anAbsCoordOrigin azimuth: a

"Compute angles between origin position and vertices of area"
listAngles := (aListOfAbsoluteCoords collect: [ :absCoord |
self convertGeodesicToAzimuthInRadiansFrom: anAbsCoordOrigin to: absCoord ]
) asOrderedCollection.
self convertGeodesicToAzimuthInRadiansFrom: anAbsCoordOrigin to: absCoord ]) asOrderedCollection.
listAngles add: listAngles first.

azRad := anAzimuthInDegree degreesToRadians.

isPointingArea := false.
listAngles withIndexDo:[:a :i | | nextAngle |
isPointingArea := isPointingArea or:[ azRad closeTo: a precision: 1e-3 ].

i < listAngles size ifTrue:[
nextAngle := listAngles at: i+1.
nextAngle - a <= Float pi ifTrue:[
isPointingArea := isPointingArea or:[ azRad between: a and: nextAngle ]
] ifFalse:[
isPointingArea := isPointingArea or:[ azRad between: nextAngle and: a ]
listAngles withIndexDo: [ :a :i |
| nextAngle |
isPointingArea := isPointingArea or: [ azRad closeTo: a precision: 1e-3 ].

i < listAngles size ifTrue: [ | diff |
nextAngle := listAngles at: i + 1.
diff := nextAngle - a.
diff negative ifTrue:[ diff := diff + (2 * Float pi)].
isPointingArea := (diff <= Float pi)
ifTrue: [ isPointingArea or: [ self checkAngle: azRad isBetween: a and: nextAngle ] ]
ifFalse: [ isPointingArea or: [ self checkAngle: azRad isBetween: nextAngle and: a ]
].
isPointingArea := isPointingArea or:[ azRad closeTo: nextAngle precision: 1e-3 ].
]
].
isPointingArea := isPointingArea or: [ azRad closeTo: nextAngle precision: 1e-3 ]
]
].

^ isPointingArea
]
Expand Down

0 comments on commit 56c7338

Please sign in to comment.