Skip to content

Commit

Permalink
update test for valid destination point (#1840)
Browse files Browse the repository at this point in the history
  • Loading branch information
panaaj authored Dec 2, 2024
1 parent 7dda8bc commit d7aca71
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/api/course/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,14 +208,26 @@ export class CourseApi {
})
}

/** Test for valid Signal K position */
private isValidPosition(position: Position): boolean {
return (
typeof position?.latitude === 'number' &&
typeof position?.latitude === 'number' &&
position?.latitude >= -90 &&
position?.latitude <= 90 &&
position?.longitude >= -180 &&
position?.longitude <= 180
)
}

/** Process stream value and take action
* @param cmdSource Object describing the source of the update
* @param pos Destination location value in the update
*/
private async parseStreamValue(cmdSource: CommandSource, pos: Position) {
if (!this.cmdSource) {
// New source
if (!pos) {
if (!this.isValidPosition(pos)) {
return
}
debug('parseStreamValue:', 'Setting Destination...')
Expand Down Expand Up @@ -805,7 +817,7 @@ export class CourseApi {
throw new Error(`Invalid href! (${dest.href})`)
}
} else if ('position' in dest) {
if (isValidCoordinate(dest.position)) {
if (this.isValidPosition(dest.position)) {
newCourse.nextPoint = {
position: dest.position,
type: Location
Expand Down

0 comments on commit d7aca71

Please sign in to comment.