Changeset 18130 in josm


Ignore:
Timestamp:
2021-08-09T22:08:44+02:00 (3 years ago)
Author:
Don-vip
Message:

see #21131 - fix direction computation: take into account next waypoint instead of previous one

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/gpx/GpxImageCorrelation.java

    r18123 r18130  
    8181            boolean firstSegment = true;
    8282            for (List<WayPoint> wps : segs) {
    83                 for (int i = 0; i < wps.size(); i++) {
     83                int size = wps.size();
     84                for (int i = 0; i < size; i++) {
    8485                    final WayPoint curWp = wps.get(i);
    8586                    // Interpolate timestamps in the segment, if one or more waypoints miss them
     
    9091                            double totalDist = 0;
    9192                            List<Pair<Double, WayPoint>> nextWps = new ArrayList<>();
    92                             for (int j = i; j < wps.size(); j++) {
     93                            for (int j = i; j < size; j++) {
    9394                                totalDist += wps.get(j - 1).getCoor().greatCircleDistance(wps.get(j).getCoor());
    9495                                nextWps.add(new Pair<>(totalDist, wps.get(j)));
     
    139140                        }
    140141                    }
    141                     ret += matchPoints(images, prevWp, prevWpTime, curWp, curWpTime, offset, interpolate, tagTime, false, dirpos);
     142                    WayPoint nextWp = i < size - 1 ? wps.get(i + 1) : null;
     143                    ret += matchPoints(images, prevWp, prevWpTime, curWp, curWpTime, offset, interpolate, tagTime, nextWp, dirpos);
    142144                    prevWp = curWp;
    143145                    prevWpTime = curWpTime;
     
    146148        }
    147149        if (trkTag && prevWp != null) {
    148             ret += matchPoints(images, prevWp, prevWpTime, prevWp, prevWpTime, offset, false, trkTagTime, true, dirpos);
     150            ret += matchPoints(images, prevWp, prevWpTime, prevWp, prevWpTime, offset, false, trkTagTime, null, dirpos);
    149151        }
    150152        return ret;
     
    207209
    208210    private static int matchPoints(List<? extends GpxImageEntry> images, WayPoint prevWp, long prevWpTime, WayPoint curWp, long curWpTime,
    209             long offset, boolean interpolate, int tagTime, boolean isLast, GpxImageDirectionPositionSettings dirpos) {
     211            long offset, boolean interpolate, int tagTime, WayPoint nextWp, GpxImageDirectionPositionSettings dirpos) {
    210212
    211213        int ret = 0;
     214        final boolean isLast = nextWp == null;
    212215
    213216        // i is the index of the timewise last photo that has the same or earlier EXIF time
     
    254257                    } else {
    255258                        curTmp.setPos(curWp.getCoor());
     259                    }
     260                    if (nextWp != null && dirpos.isSetImageDirection()) {
     261                        double direction = curWp.getCoor().bearing(nextWp.getCoor());
     262                        curTmp.setExifImgDir(computeDirection(direction, dirpos.getImageDirectionAngleOffset()));
    256263                    }
    257264                    curTmp.setGpsTime(curImg.getExifInstant().minusMillis(offset));
     
    280287                    final LatLon curCoor = curWp.getCoor();
    281288                    LatLon position = prevCoor.interpolate(curCoor, timeDiff);
    282                     if (shiftXY || dirpos.isSetImageDirection()) {
    283                         double direction = prevCoor.bearing(curCoor);
     289                    if (nextWp != null && (shiftXY || dirpos.isSetImageDirection())) {
     290                        double direction = curCoor.bearing(nextWp.getCoor());
    284291                        if (dirpos.isSetImageDirection()) {
    285                             curTmp.setExifImgDir((Utils.toDegrees(direction) + dirpos.getImageDirectionAngleOffset()) % 360d);
     292                            curTmp.setExifImgDir(computeDirection(direction, dirpos.getImageDirectionAngleOffset()));
    286293                        }
    287294                        if (shiftXY) {
     
    310317        }
    311318        return ret;
     319    }
     320
     321    private static double computeDirection(double direction, double angleOffset) {
     322        return (Utils.toDegrees(direction) + angleOffset) % 360d;
    312323    }
    313324
Note: See TracChangeset for help on using the changeset viewer.