Skip to content

Commit

Permalink
Fixed: find the index of the snapped point corresponding to the obser…
Browse files Browse the repository at this point in the history
…vation point
  • Loading branch information
laurent-chriqui committed Jul 9, 2024
1 parent 86ba284 commit da0ed55
Showing 1 changed file with 6 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -202,35 +202,21 @@ public Response match(
int i = 0;
assert matchResult.getEdgeMatches().size() == responsePath.getPathDetails().get("edge_key").size();
for (EdgeMatch em : matchResult.getEdgeMatches()) {
DistanceCalc distanceCalc = new DistancePlaneProjection();
// DistanceCalc distanceCalc = new DistancePlaneProjection();
if (em.getStates().size() > 0) {
for (State state : em.getStates()) {
GHPoint point = state.getEntry().getPoint();
GHPoint3D snappedPoint = state.getSnap().getSnappedPoint();
int snappedEdgeStartPointIdx = responsePath.getPathDetails().get("edge_key").get(i).getFirst();
GHPoint3D snappedEdgeStartPoint = responsePath.getPoints().get(snappedEdgeStartPointIdx);
int snappedEdgeLastPointIdx = responsePath.getPathDetails().get("edge_key").get(i).getLast();
double distanceToStart = distanceCalc.calcDist(
snappedPoint.getLat(), snappedPoint.getLon(),
snappedEdgeStartPoint.getLat(), snappedEdgeStartPoint.getLon()
);
double minDistance = distanceToStart;
int bestCandidateIdx = snappedEdgeStartPointIdx;
for (int j = snappedEdgeStartPointIdx + 1; j <= snappedEdgeLastPointIdx; j++) {
int bestCandidateIdx = -1;
for (int j = snappedEdgeStartPointIdx; j <= snappedEdgeLastPointIdx; j++) {
GHPoint3D candidate = responsePath.getPoints().get(j);
double distance = distanceCalc.calcDist(
snappedPoint.getLat(), snappedPoint.getLon(), candidate.getLat(), candidate.getLon());
if (distance < minDistance) {
if (candidate.getLat() == snappedPoint.getLat() && candidate.getLon() == snappedPoint.getLon()) {
bestCandidateIdx = j;
minDistance = distance;
} else break;
break;
}
}
// GHPoint3D snappedEdgeLastPoint = responsePath.getPoints().get(snappedEdgeLastPointIdx);
// double distanceToLast = distanceCalc.calcDist(
// point.getLat(), point.getLon(),
// snappedEdgeLastPoint.getLat(), snappedEdgeLastPoint.getLon()
// );
// TODO put the index and edgeKey in better data structure
observationIndexes.add(new ArrayList<Integer>(Arrays.asList(point.index, bestCandidateIdx)));
}
}
Expand Down

0 comments on commit da0ed55

Please sign in to comment.