From e76e16933be59b4a8d022cbf68f227aac913a505 Mon Sep 17 00:00:00 2001 From: Pierre Aumond Date: Mon, 31 Jul 2023 15:33:22 +0200 Subject: [PATCH 1/2] fix ComputeCnossosRays.java --- .../noisemodelling/pathfinder/ComputeCnossosRays.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/noisemodelling-pathfinder/src/main/java/org/noise_planet/noisemodelling/pathfinder/ComputeCnossosRays.java b/noisemodelling-pathfinder/src/main/java/org/noise_planet/noisemodelling/pathfinder/ComputeCnossosRays.java index be83e0d78..8e69fad45 100644 --- a/noisemodelling-pathfinder/src/main/java/org/noise_planet/noisemodelling/pathfinder/ComputeCnossosRays.java +++ b/noisemodelling-pathfinder/src/main/java/org/noise_planet/noisemodelling/pathfinder/ComputeCnossosRays.java @@ -785,7 +785,7 @@ public PropagationPath computeHEdgeDiffraction(ProfileBuilder.CutProfile cutProf List filteredCoordinates = new ArrayList<>(); for (Coordinate coord : pts2D) { double lineY = slope * coord.x + yIntercept; - if (coord.y >= lineY-0.001) { // espilon to avoir float issues + if (coord.y >= lineY-0.000001) { // espilon to avoir float issues filteredCoordinates.add(coord); } } @@ -795,7 +795,9 @@ public PropagationPath computeHEdgeDiffraction(ProfileBuilder.CutProfile cutProf Coordinate[] coordsArray = filteredCoordinates.toArray(new Coordinate[0]); ConvexHull convexHull = new ConvexHull(coordsArray, geomFactory); Coordinate[] convexHullCoords = convexHull.getConvexHull().getCoordinates(); - Arrays.sort(convexHullCoords, Comparator.comparingDouble(coord -> coord.x)); + int indexFirst = Arrays.asList(convexHull.getConvexHull().getCoordinates()).indexOf(firstPt); + int indexLast = Arrays.asList(convexHull.getConvexHull().getCoordinates()).lastIndexOf(lastPt); + convexHullCoords = Arrays.copyOfRange(convexHullCoords, indexFirst, indexLast+1); CoordinateSequence coordSequence = geomFactory.getCoordinateSequenceFactory().create(convexHullCoords); Geometry geom = geomFactory.createLineString(coordSequence); From 263710b562e8a4a38663af494e44ba7ea0769208 Mon Sep 17 00:00:00 2001 From: Pierre Aumond Date: Thu, 3 Aug 2023 13:40:30 +0200 Subject: [PATCH 2/2] Update ComputeCnossosRays.java ChatGPT 3.5 is not still a good dev :) --- .../pathfinder/ComputeCnossosRays.java | 21 +++++++------------ 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/noisemodelling-pathfinder/src/main/java/org/noise_planet/noisemodelling/pathfinder/ComputeCnossosRays.java b/noisemodelling-pathfinder/src/main/java/org/noise_planet/noisemodelling/pathfinder/ComputeCnossosRays.java index 8e69fad45..0a692aae7 100644 --- a/noisemodelling-pathfinder/src/main/java/org/noise_planet/noisemodelling/pathfinder/ComputeCnossosRays.java +++ b/noisemodelling-pathfinder/src/main/java/org/noise_planet/noisemodelling/pathfinder/ComputeCnossosRays.java @@ -745,23 +745,18 @@ public PropagationPath computeHEdgeDiffraction(ProfileBuilder.CutProfile cutProf List newCutPts = new ArrayList<>(cutPts.size()); Geometry lineString = new GeometryFactory().createLineString(pts2D.toArray(new Coordinate[0])); List newPts2D = List.of(DouglasPeuckerSimplifier.simplify(lineString, 0.5*cutProfile.getDistanceToSR()).getCoordinates()); - List matchingIndices = new ArrayList<>(); - for (int i = 0; i < pts2D.size(); i++) { - Coordinate coordinate1 = pts2D.get(i); - for (int j = 0; j < newPts2D.size(); j++) { - Coordinate coordinate2 = newPts2D.get(j); - if (coordinate1.equals(coordinate2)) { - matchingIndices.add(i); - break; // Move to the next coordinate in list1 once a match is found - } - } - } - for (int index : matchingIndices) { - newCutPts.add(cutPts.get(index)); + + for (int i = 0; i < newPts2D.size(); i++) { + newCutPts.add(cutPts.get(pts2D.indexOf(newPts2D.get(i)))); } + pts2D = newPts2D; cutPts = newCutPts; + if(pts2D.size() != cutPts.size()) { + throw new IllegalArgumentException("The two arrays size should be the same"); + } + double[] meanPlane = JTSUtility.getMeanPlaneCoefficients(pts2D.toArray(new Coordinate[0])); Coordinate firstPts2D = pts2D.get(0); Coordinate lastPts2D = pts2D.get(pts2D.size()-1);