flightpathr

Tools to analyze aircraft and flight path data.
git clone https://git.eamoncaddigan.net/flightpathr.git
Log | Files | Refs | README | LICENSE

commit 52ba6c6c844aff0316ffaf68a4a139b9afe6221a
parent 267ca24c627d39bec6637054a1d65895df3004f1
Author: eamoncaddigan <eamon.caddigan@gmail.com>
Date:   Tue, 19 Apr 2016 09:24:30 -0400

Handling non-co-altitude waypoints in path.

Diffstat:
MR/distanceFromPath.R | 12++++++++----
Mtests/testthat/test_distanceFromPath.R | 18++++++++++++++++++
2 files changed, 26 insertions(+), 4 deletions(-)

diff --git a/R/distanceFromPath.R b/R/distanceFromPath.R @@ -36,11 +36,15 @@ distanceFromPath <- function(trajectory, path) { # If the waypoints are at the same altitude, just calculate the deviation # from this altitude. Easy. - # XXX - Not actually handling the case where they don't match. - if (!isTRUE(all.equal(pathCoords[legIdx, 3], pathCoords[legIdx+1, 3]))) { - warning("Pretending that waypoint altitudes match when they don't") + if (isTRUE(all.equal(pathCoords[legIdx, 3], pathCoords[legIdx+1, 3]))) { + vDistanceToLeg[, legIdx] <- trajectoryCoords[, 3] - pathCoords[legIdx, 3] + } else { + vDistanceToLeg[, legIdx] <- 0 + deviationAbove <- trajectoryCoords[, 3] - max(pathCoords[c(legIdx, legIdx+1), 3]) + deviationBelow <- trajectoryCoords[, 3] - min(pathCoords[c(legIdx, legIdx+1), 3]) + vDistanceToLeg[deviationAbove > 0, legIdx] <- deviationAbove[deviationAbove > 0] + vDistanceToLeg[deviationBelow < 0, legIdx] <- deviationBelow[deviationBelow > 0] } - vDistanceToLeg[, legIdx] <- trajectoryCoords[, 3] - pathCoords[legIdx, 3] # Squared euclidean distance slantToLeg[, legIdx] <- hDistanceToLeg[, legIdx]^2 + vDistanceToLeg[, legIdx]^2 diff --git a/tests/testthat/test_distanceFromPath.R b/tests/testthat/test_distanceFromPath.R @@ -44,3 +44,21 @@ test_that("small deviations look OK", { # left of course expect_lt(trajectoryDistance[farthestPoint], 0) }) + +test_that("simple altitude deviation is handled", { + flownPath1 <- cbind(path, alt = 3500) + flownPath2 <- cbind(path, alt = c(3500, 4500, 3500)) + flownPath3 <- cbind(path, alt = c(3500, 5500, 3500)) + flownTrajectory <- cbind(fakeTrajectory(path), + alt = c(seq(3500, 5500, length.out = numPoints+2), + seq(5500, 3500, + length.out = nrow(trajectory)-(numPoints+2)))) + + + expect_equal(max(distanceFromPath(flownTrajectory, flownPath1)$vertical), + 2000.0) + expect_equal(max(distanceFromPath(flownTrajectory, flownPath2)$vertical), + 1000.0) + expect_equal(max(distanceFromPath(flownTrajectory, flownPath3)$vertical), + 0) +})