From 506888859bf90b717b570da6c6042b641228a9f2 Mon Sep 17 00:00:00 2001 From: Brendan Date: Fri, 1 Mar 2024 09:57:38 +0100 Subject: [PATCH] Corrections method check azimuth towards area (+test) --- GeoView-Tests/GeodesicUtilitiesTest.class.st | 26 +++++++++++++++++--- GeoView/GeodesicUtilities.class.st | 25 +++++++++++++------ 2 files changed, 41 insertions(+), 10 deletions(-) diff --git a/GeoView-Tests/GeodesicUtilitiesTest.class.st b/GeoView-Tests/GeodesicUtilitiesTest.class.st index 390b74a..8c6f4a6 100644 --- a/GeoView-Tests/GeodesicUtilitiesTest.class.st +++ b/GeoView-Tests/GeodesicUtilitiesTest.class.st @@ -58,7 +58,7 @@ GeodesicUtilitiesTest >> testIsAzimuthTowardsArea [ listPointsArea add: (AbsoluteCoordinates latitudeInDegrees: 48.3117 longitudeInDegrees: -4.60466). listPointsArea add: (AbsoluteCoordinates latitudeInDegrees: 48.29603 longitudeInDegrees: -4.62295). - "headingInDegree := 45. + headingInDegree := 45. isAzTowardsArea := GeodesicUtilities isAzimuthTowardsAreaFrom: originPointAbsCoord azimuth: headingInDegree area: listPointsArea. @@ -74,14 +74,34 @@ GeodesicUtilitiesTest >> testIsAzimuthTowardsArea [ isAzTowardsArea := GeodesicUtilities isAzimuthTowardsAreaFrom: originPointAbsCoord azimuth: headingInDegree area: listPointsArea. - self assert: isAzTowardsArea equals: false." - originPointAbsCoord latitudeInDegrees: 48.29603. + self assert: isAzTowardsArea equals: false. + headingInDegree := 90. isAzTowardsArea := GeodesicUtilities isAzimuthTowardsAreaFrom: originPointAbsCoord azimuth: headingInDegree area: listPointsArea. self assert: isAzTowardsArea equals: true. + originPointAbsCoord := AbsoluteCoordinates latitudeInDegrees: 48.34 longitudeInDegrees: -4.62. + headingInDegree := 225. + + isAzTowardsArea := GeodesicUtilities isAzimuthTowardsAreaFrom: originPointAbsCoord azimuth: headingInDegree area: listPointsArea. + + self assert: isAzTowardsArea equals: true. + + headingInDegree := 180. + + isAzTowardsArea := GeodesicUtilities isAzimuthTowardsAreaFrom: originPointAbsCoord azimuth: headingInDegree area: listPointsArea. + + self assert: isAzTowardsArea equals: true. + + originPointAbsCoord := AbsoluteCoordinates latitudeInDegrees: 48.01 longitudeInDegrees: -4.62. + headingInDegree := 45. + + isAzTowardsArea := GeodesicUtilities isAzimuthTowardsAreaFrom: originPointAbsCoord azimuth: headingInDegree area: listPointsArea. + + self assert: isAzTowardsArea equals: false. + ] diff --git a/GeoView/GeodesicUtilities.class.st b/GeoView/GeodesicUtilities.class.st index 7117a4b..f8dd2b7 100644 --- a/GeoView/GeodesicUtilities.class.st +++ b/GeoView/GeodesicUtilities.class.st @@ -270,14 +270,25 @@ 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. - - listAngles := listAngles sort: [ :a :b | a < b ]. - + ) asOrderedCollection. + listAngles add: listAngles first. + azRad := anAzimuthInDegree degreesToRadians. - isPointingArea := azRad between: listAngles first and: listAngles last. - isPointingArea := isPointingArea or:[ azRad closeTo: listAngles first precision: 1e-3 ]. - isPointingArea := isPointingArea or:[ azRad closeTo: listAngles last precision: 1e-3 ]. + + 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 ] + ]. + isPointingArea := isPointingArea or:[ azRad closeTo: nextAngle precision: 1e-3 ]. + ] + ]. ^ isPointingArea ]