Skip to content

Commit

Permalink
Merge branch 'master' into rzr-trk-width
Browse files Browse the repository at this point in the history
  • Loading branch information
RZR-UA committed Jan 16, 2025
2 parents 4559bc7 + 3b1026a commit e64d549
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import kotlin.test.assertTrue

class OBDTest {

@Test
// @Test
fun testOBDComputer() = runBlocking {
val widget = OBDDataComputer.registerWidget(OBDDataComputer.OBDTypeWidget.FUEL_CONSUMPTION_RATE_PERCENT_HOUR, 15)
val coef = 0.05
Expand All @@ -21,7 +21,7 @@ class OBDTest {
var time: Long = currentTimeMillis()
for (i in 0 .. 600) {
val map = HashMap<OBDCommand, OBDDataField<Any>>()
map[OBDCommand.OBD_FUEL_LEVEL_COMMAND] = OBDDataField(fuelLevel.toString())
map[OBDCommand.OBD_FUEL_LEVEL_COMMAND] = OBDDataField(fuelLevel)
OBDDataComputer.acceptValue(map)
val now = currentTimeMillis()
fuelLevel = fuelLevelStart - coef / (1000 / delay) * i
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,25 +306,19 @@ public boolean hasTimestamps() {
}

public boolean isAddNewSegmentAllowed() {
return beforeSegments.size() > 0 && beforeSegments.get(beforeSegments.size() - 1).getPoints().size() >= 2;
return !beforeSegments.isEmpty() && beforeSegments.get(beforeSegments.size() - 1).getPoints().size() >= 2;
}

public void clearSnappedToRoadPoints() {
roadSegmentData.clear();
}

List<TrkSegment> getBeforeTrkSegmentLine() {
if (beforeSegmentsForSnap != null) {
return beforeSegmentsForSnap;
}
return beforeSegments;
return beforeSegmentsForSnap != null ? beforeSegmentsForSnap : beforeSegments;
}

List<TrkSegment> getAfterTrkSegmentLine() {
if (afterSegmentsForSnap != null) {
return afterSegmentsForSnap;
}
return afterSegments;
return afterSegmentsForSnap != null ? afterSegmentsForSnap : afterSegments;
}

public List<TrkSegment> getBeforeSegments() {
Expand Down Expand Up @@ -750,7 +744,7 @@ private ApplicationMode getPointAppMode(int pointPosition) {
}

public void scheduleRouteCalculateIfNotEmpty() {
if (application == null || (before.getPoints().size() == 0 && after.getPoints().size() == 0)) {
if (application == null || (before.getPoints().isEmpty() && after.getPoints().isEmpty())) {
return;
}
RoutingHelper routingHelper = application.getRoutingHelper();
Expand Down Expand Up @@ -791,7 +785,8 @@ private List<Pair<WptPt, WptPt>> getOrderedRoadSegmentDataKeys() {
return keys;
}

private void recreateSegments(List<TrkSegment> segments, List<TrkSegment> segmentsForSnap, List<WptPt> points, boolean calculateIfNeeded) {
private void recreateSegments(List<TrkSegment> segments, List<TrkSegment> segmentsForSnap,
List<WptPt> points, boolean calculateIfNeeded) {
List<Integer> roadSegmentIndexes = new ArrayList<>();
TrkSegment s = new TrkSegment();
segments.add(s);
Expand Down Expand Up @@ -829,21 +824,27 @@ private void recreateSegments(List<TrkSegment> segments, List<TrkSegment> segmen
if (!segments.isEmpty()) {
for (TrkSegment segment : segments) {
TrkSegment segmentForSnap = new TrkSegment();
for (int i = 0; i < segment.getPoints().size() - 1; i++) {
Pair<WptPt, WptPt> pair = new Pair<>(segment.getPoints().get(i), segment.getPoints().get(i + 1));
RoadSegmentData data = this.roadSegmentData.get(pair);
List<WptPt> segmentPoints = segment.getPoints();
List<WptPt> segmentForSnapPoints = segmentForSnap.getPoints();
for (int i = 0; i < segmentPoints.size() - 1; i++) {
WptPt point = segmentPoints.get(i);
WptPt nextPoint = segmentPoints.get(i + 1);
RoadSegmentData data = this.roadSegmentData.get(new Pair<>(point, nextPoint));
List<WptPt> pts = data != null ? data.getPoints() : null;
if (pts != null) {
segmentForSnap.getPoints().addAll(pts);
segmentForSnapPoints.addAll(pts);
} else {
if (calculateIfNeeded && roadSegmentIndexes.contains(segmentsForSnap.size())) {
scheduleRouteCalculateIfNotEmpty();
}
segmentForSnap.getPoints().addAll(Arrays.asList(pair.first, pair.second));
if (segmentForSnapPoints.isEmpty()) {
segmentForSnapPoints.add(point);
}
segmentForSnapPoints.add(nextPoint);
}
}
if (segmentForSnap.getPoints().isEmpty()) {
segmentForSnap.getPoints().addAll(segment.getPoints());
if (segmentForSnapPoints.isEmpty()) {
segmentForSnapPoints.addAll(segmentPoints);
}
segmentsForSnap.add(segmentForSnap);
}
Expand Down Expand Up @@ -876,18 +877,18 @@ void addPoints() {
addPoints(segment.getPoints());
}
} else {
for (int si = 0; si < segments.size(); si++) {
TrkSegment segment = segments.get(si);
for (int i = 0; i < segments.size(); i++) {
TrkSegment segment = segments.get(i);
if (segment.hasRoute()) {
List<WptPt> routePoints = collectRoutePointsFromSegment(segment, si);
if (!routePoints.isEmpty() && si < segments.size() - 1) {
List<WptPt> routePoints = collectRoutePointsFromSegment(segment, i);
if (!routePoints.isEmpty() && i < segments.size() - 1) {
routePoints.get(routePoints.size() - 1).setGap();
}
addPoints(routePoints);
} else {
List<WptPt> points = segment.getPoints();
addPoints(points);
if (!points.isEmpty() && si < segments.size() - 1) {
if (!points.isEmpty() && i < segments.size() - 1) {
points.get(points.size() - 1).setGap();
}
}
Expand Down Expand Up @@ -1039,12 +1040,7 @@ private boolean needDuplicatePoint(List<GpxPoint> gpxPoints, int index) {
}

private void updateSegmentsForSnap(boolean both) {
recreateSegments(beforeSegments = new ArrayList<>(),
beforeSegmentsForSnap = new ArrayList<>(), before.getPoints(), true);
if (both) {
recreateSegments(afterSegments = new ArrayList<>(),
afterSegmentsForSnap = new ArrayList<>(), after.getPoints(), true);
}
updateSegmentsForSnap(both, true);
}

private void updateSegmentsForSnap(boolean both, boolean calculateIfNeeded) {
Expand Down

0 comments on commit e64d549

Please sign in to comment.