From 2143079e4b674b4e1b56767a7f6bca9e8252c35d Mon Sep 17 00:00:00 2001 From: nicolas-f Date: Tue, 3 Dec 2024 17:03:58 +0100 Subject: [PATCH] add unit test issue with path state --- .../noisemodelling/jdbc/RegressionTest.java | 111 ++++++++++++++++++ .../jdbc/regression_nan/lw_roads.sql | 51 ++++++++ .../noisemodelling/pathfinder/PathFinder.java | 3 + 3 files changed, 165 insertions(+) create mode 100644 noisemodelling-jdbc/src/test/java/org/noise_planet/noisemodelling/jdbc/RegressionTest.java create mode 100644 noisemodelling-jdbc/src/test/resources/org/noise_planet/noisemodelling/jdbc/regression_nan/lw_roads.sql diff --git a/noisemodelling-jdbc/src/test/java/org/noise_planet/noisemodelling/jdbc/RegressionTest.java b/noisemodelling-jdbc/src/test/java/org/noise_planet/noisemodelling/jdbc/RegressionTest.java new file mode 100644 index 000000000..e7e5dbfa8 --- /dev/null +++ b/noisemodelling-jdbc/src/test/java/org/noise_planet/noisemodelling/jdbc/RegressionTest.java @@ -0,0 +1,111 @@ +package org.noise_planet.noisemodelling.jdbc; + +import org.h2gis.api.EmptyProgressVisitor; +import org.h2gis.api.ProgressVisitor; +import org.h2gis.functions.factory.H2GISDBFactory; +import org.h2gis.functions.io.geojson.GeoJsonRead; +import org.h2gis.functions.io.shp.SHPRead; +import org.h2gis.utilities.JDBCUtilities; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.noise_planet.noisemodelling.jdbc.utils.CellIndex; +import org.noise_planet.noisemodelling.pathfinder.IComputePathsOut; +import org.noise_planet.noisemodelling.pathfinder.cnossos.CnossosPath; +import org.noise_planet.noisemodelling.pathfinder.path.Scene; +import org.noise_planet.noisemodelling.pathfinder.utils.profiler.RootProgressVisitor; +import org.noise_planet.noisemodelling.propagation.Attenuation; + +import java.net.URL; +import java.nio.file.Paths; +import java.sql.Connection; +import java.sql.Statement; +import java.util.*; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.noise_planet.noisemodelling.jdbc.Utils.getRunScriptRes; + +public class RegressionTest { + + private Connection connection; + + @BeforeEach + public void tearUp() throws Exception { + connection = JDBCUtilities.wrapConnection(H2GISDBFactory.createSpatialDataBase(NoiseMapByReceiverMakerTest.class.getSimpleName(), true, "")); + } + + @AfterEach + public void tearDown() throws Exception { + if(connection != null) { + connection.close(); + } + } + + /** + * Got reflection out of bound in this scenario + */ + @Test + public void testScenarioOutOfBoundException() throws Exception { + try(Statement st = connection.createStatement()) { + st.execute(getRunScriptRes("regression_nan/lw_roads.sql")); + + // Init NoiseModelling + NoiseMapByReceiverMaker noiseMapByReceiverMaker = new NoiseMapByReceiverMaker("BUILDINGS", + "LW_ROADS", "RECEIVERS"); + + noiseMapByReceiverMaker.setMaximumPropagationDistance(500.0); + noiseMapByReceiverMaker.setSoundReflectionOrder(1); + noiseMapByReceiverMaker.setThreadCount(1); + noiseMapByReceiverMaker.setComputeHorizontalDiffraction(true); + noiseMapByReceiverMaker.setComputeVerticalDiffraction(true); + // Building height field name + noiseMapByReceiverMaker.setHeightField("HEIGHT"); + + // Init custom input in order to compute more than just attenuation + // LW_ROADS contain Day Evening Night emission spectrum + NoiseMapParameters noiseMapParameters = new NoiseMapParameters(NoiseMapParameters.INPUT_MODE.INPUT_MODE_LW_DEN); + + noiseMapParameters.setComputeLDay(false); + noiseMapParameters.setComputeLEvening(false); + noiseMapParameters.setComputeLNight(false); + noiseMapParameters.setComputeLDEN(true); + + NoiseMapMaker tableWriter = new NoiseMapMaker(connection, noiseMapParameters); + + noiseMapByReceiverMaker.setPropagationProcessDataFactory(tableWriter); + noiseMapByReceiverMaker.setComputeRaysOutFactory(tableWriter); + + RootProgressVisitor progressLogger = new RootProgressVisitor(1, true, 1); + + noiseMapByReceiverMaker.initialize(connection, new EmptyProgressVisitor()); + + noiseMapParameters.getPropagationProcessPathData(NoiseMapParameters.TIME_PERIOD.DAY).setTemperature(20); + noiseMapParameters.getPropagationProcessPathData(NoiseMapParameters.TIME_PERIOD.EVENING).setTemperature(16); + noiseMapParameters.getPropagationProcessPathData(NoiseMapParameters.TIME_PERIOD.NIGHT).setTemperature(10); + + noiseMapByReceiverMaker.setGridDim(1); + + // Set of already processed receivers + Set receivers = new HashSet<>(); + + // Iterate over computation areas + try { + tableWriter.start(); + // Fetch cell identifiers with receivers + Map cells = noiseMapByReceiverMaker.searchPopulatedCells(connection); + ProgressVisitor progressVisitor = progressLogger.subProcess(cells.size()); + for(CellIndex cellIndex : new TreeSet<>(cells.keySet())) { + // Run ray propagation + noiseMapByReceiverMaker.evaluateCell(connection, cellIndex.getLatitudeIndex(), + cellIndex.getLongitudeIndex(), progressVisitor, receivers); + } + } finally { + tableWriter.stop(); + } + + } + } + + +} diff --git a/noisemodelling-jdbc/src/test/resources/org/noise_planet/noisemodelling/jdbc/regression_nan/lw_roads.sql b/noisemodelling-jdbc/src/test/resources/org/noise_planet/noisemodelling/jdbc/regression_nan/lw_roads.sql new file mode 100644 index 000000000..f87717dd7 --- /dev/null +++ b/noisemodelling-jdbc/src/test/resources/org/noise_planet/noisemodelling/jdbc/regression_nan/lw_roads.sql @@ -0,0 +1,51 @@ +CREATE TABLE PUBLIC.LW_ROADS ( + PK INTEGER NOT NULL, + THE_GEOM GEOMETRY(LINESTRINGZ, 2154), + LWD63 DOUBLE PRECISION, + LWD125 DOUBLE PRECISION, + LWD250 DOUBLE PRECISION, + LWD500 DOUBLE PRECISION, + LWD1000 DOUBLE PRECISION, + LWD2000 DOUBLE PRECISION, + LWD4000 DOUBLE PRECISION, + LWD8000 DOUBLE PRECISION, + LWE63 DOUBLE PRECISION, + LWE125 DOUBLE PRECISION, + LWE250 DOUBLE PRECISION, + LWE500 DOUBLE PRECISION, + LWE1000 DOUBLE PRECISION, + LWE2000 DOUBLE PRECISION, + LWE4000 DOUBLE PRECISION, + LWE8000 DOUBLE PRECISION, + LWN63 DOUBLE PRECISION, + LWN125 DOUBLE PRECISION, + LWN250 DOUBLE PRECISION, + LWN500 DOUBLE PRECISION, + LWN1000 DOUBLE PRECISION, + LWN2000 DOUBLE PRECISION, + LWN4000 DOUBLE PRECISION, + LWN8000 DOUBLE PRECISION, + PRIMARY KEY(PK) +); +INSERT INTO PUBLIC.LW_ROADS +(PK, THE_GEOM, LWD63, LWD125, LWD250, LWD500, LWD1000, LWD2000, LWD4000, LWD8000, LWE63, LWE125, LWE250, LWE500, LWE1000, LWE2000, LWE4000, LWE8000, LWN63, LWN125, LWN250, LWN500, LWN1000, LWN2000, LWN4000, LWN8000) +VALUES(7481, 'SRID=2154; LINESTRING Z(375800.1 6667058.5 0.05, 375839.2 6667115.6 0.05)'::geometry, 65.36442635294232, 54.456764645234145, 53.32864179559816, 52.5428622578291, 54.12712826805112, 52.83281286202566, 47.071026050561315, 38.79424858063663, 64.69495845663619, 53.787296748928014, 52.65917389929203, 51.87339436152297, 53.45766037174499, 52.16334496571953, 46.401558154255184, 38.1247806843305, 58.67435854335656, 47.76669683564839, 46.6385739860124, 45.852794448243344, 47.43706045846537, 46.142745052439906, 40.38095824097556, 32.10418077105088); + +DROP TABLE IF EXISTS RECEIVERS; +CREATE TABLE RECEIVERS(the_geom GEOMETRY(POINTZ), GID SERIAL PRIMARY KEY); +INSERT INTO RECEIVERS(the_geom) VALUES ('SRID=2154; POINTZ(375773.1272896934 6667129.820221064 4)'); + + +CREATE TABLE PUBLIC.BUILDINGS ( + THE_GEOM GEOMETRY(POLYGON, 2154), + PK INTEGER NOT NULL, + HEIGHT DOUBLE PRECISION, + PRIMARY KEY(PK) +); +INSERT INTO PUBLIC.BUILDINGS +(THE_GEOM, PK, HEIGHT) +VALUES('SRID=2154; POLYGON ((375811.5984267707 6667066.103970759, 375844.3666811302 6667112.905505047, 375868.2113708865 6667096.309221784, 375861.41009082325 6667086.588539035, 375850.2608152096 6667094.344287971, 375827.4262067741 6667061.732203544, 375819.16536903894 6667067.485188738, 375816.03307242284 6667063.016344914, 375811.5984267707 6667066.103970759))'::geometry, 1, 5.117702); +INSERT INTO PUBLIC.BUILDINGS +(THE_GEOM, PK, HEIGHT) +VALUES('SRID=2154; POLYGON ((375796.10196917434 6667073.082938105, 375832.0771203075 6667125.027724414, 375838.20779331593 6667120.813838921, 375802.2326758393 6667068.869016298, 375796.10196917434 6667073.082938105))'::geometry, 2, 4.4559813); + diff --git a/noisemodelling-pathfinder/src/main/java/org/noise_planet/noisemodelling/pathfinder/PathFinder.java b/noisemodelling-pathfinder/src/main/java/org/noise_planet/noisemodelling/pathfinder/PathFinder.java index 1b39cd974..a4227bd61 100644 --- a/noisemodelling-pathfinder/src/main/java/org/noise_planet/noisemodelling/pathfinder/PathFinder.java +++ b/noisemodelling-pathfinder/src/main/java/org/noise_planet/noisemodelling/pathfinder/PathFinder.java @@ -667,6 +667,9 @@ public CnossosPath computeHEdgeDiffraction(CutProfile cutProfile , boolean bodyB Coordinate[] convexHullCoords = convexHull.getConvexHull().getCoordinates(); int indexFirst = Arrays.asList(convexHull.getConvexHull().getCoordinates()).indexOf(firstPt); int indexLast = Arrays.asList(convexHull.getConvexHull().getCoordinates()).lastIndexOf(lastPt); + if(indexFirst == -1 || indexLast == -1 || indexFirst > indexLast) { + throw new IllegalArgumentException("Wrong input data " + cutProfile.toString()); + } convexHullCoords = Arrays.copyOfRange(convexHullCoords, indexFirst, indexLast + 1); CoordinateSequence coordSequence = geomFactory.getCoordinateSequenceFactory().create(convexHullCoords); Geometry geom = geomFactory.createLineString(coordSequence);