Skip to content

Commit

Permalink
Merge pull request #330 from bannergress/skip-unavailable-portals
Browse files Browse the repository at this point in the history
Skip unavailable portals in distance calculation
  • Loading branch information
Poeschl authored Jul 23, 2023
2 parents 1dcceb6 + 7cf19f1 commit f8b207e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.bannergress.backend.entities.Mission;
import com.bannergress.backend.entities.MissionStep;
import com.bannergress.backend.enums.POIType;
import org.geotools.referencing.GeodeticCalculator;
import org.geotools.referencing.crs.DefaultGeographicCRS;
import org.locationtech.jts.geom.Point;
Expand All @@ -25,7 +26,7 @@ public static int calculateLengthMeters(Collection<Mission> missions) {

for (Mission mission : missions) {
for (MissionStep step : mission.getSteps()) {
if (step.getPoi() != null) {
if (step.getPoi() != null && step.getPoi().getType() != POIType.unavailable) {
Point point = step.getPoi().getPoint();
if (point != null) {
if (prevPoint != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.bannergress.backend.entities.MissionStepBuilder;
import com.bannergress.backend.entities.POI;
import com.bannergress.backend.entities.POIBuilder;
import com.bannergress.backend.enums.POIType;
import org.assertj.core.data.Offset;
import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -35,4 +36,17 @@ void test() {
assertThat(DistanceCalculation.calculateLengthMeters(List.of(mission1, mission2))).isCloseTo(834_885,
Offset.offset(10));
}

@Test
void testUnavailablePortal() {
Spatial spatial = new Spatial();

Mission mission1 = new Mission();
POI frankfurt = new POIBuilder().withPoint(spatial.createPoint(50.110556, 8.682222)).build();
POI bielefeld = new POIBuilder().withPoint(spatial.createPoint(52.02182, 8.53509)).withType(POIType.unavailable)
.build();
mission1.getSteps().add(new MissionStepBuilder().withPoi(frankfurt).build());
mission1.getSteps().add(new MissionStepBuilder().withPoi(bielefeld).build());
assertThat(DistanceCalculation.calculateLengthMeters(List.of(mission1))).isEqualTo(0);
}
}

0 comments on commit f8b207e

Please sign in to comment.