From 5538aaa1474f5bdf512b7a61be8e4d24caedde71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E5=87=AF?= <324400663+KyleHuangFromHZ@users.noreply.github.com> Date: Mon, 16 Nov 2026 16:52:00 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix(sound-power):=20=E7=94=A8=E7=8E=B0?= =?UTF-8?q?=E6=9C=89=E5=8E=9F=E7=94=9F=E6=8E=A5=E5=8F=A3=E4=BC=A0=E5=85=A5?= =?UTF-8?q?=E7=9C=9F=E5=AE=9E=E6=B5=8B=E9=87=8F=E9=9D=A2=E7=A7=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../runtime/PublicAlgorithmService.java | 27 ++++++++++++++----- .../runtime/PublicSoundPowerMathTest.java | 11 +++++--- .../TerminalEngineeringSoundPowerTest.java | 20 ++++++++++++++ .../api/SoundPowerSurveyOptions.java | 2 +- 4 files changed, 48 insertions(+), 12 deletions(-) diff --git a/apps/backend/crydaq-algorithm-runtime/src/main/java/com/opentest/algorithm/runtime/PublicAlgorithmService.java b/apps/backend/crydaq-algorithm-runtime/src/main/java/com/opentest/algorithm/runtime/PublicAlgorithmService.java index 54d145f1..b22aa582 100644 --- a/apps/backend/crydaq-algorithm-runtime/src/main/java/com/opentest/algorithm/runtime/PublicAlgorithmService.java +++ b/apps/backend/crydaq-algorithm-runtime/src/main/java/com/opentest/algorithm/runtime/PublicAlgorithmService.java @@ -195,10 +195,9 @@ public PublicAlgorithmService(AlgorithmLibJNIBridgeService runtime, CurveNativeA parameters.put("height", options.height()); parameters.put("roomSurface", options.roomSurface()); parameters.put("absortionCoef", options.absorptionCoefficient()); - if (options.measurementSurfaceArea() != null) - parameters.put("measurementSurfaceArea", options.measurementSurfaceArea()); + int nativeSurfaceType = soundPowerNativeSurface(options.surfaceType(), options.measurementSurfaceArea(), parameters); return Optional.ofNullable(runtime.calculateSimplifiedSoundPowerSurvey( - options.surfaceType(), parameters, levels, backgroundLevels)).map(value -> + nativeSurfaceType, parameters, levels, backgroundLevels)).map(value -> new SoundPowerSurveyResult(value.getSoundPowerLevel(), value.getBackgroundCorrection(), value.getEnvironmentalCorrection(), value.getEquivalentSoundPressureLevelAverage())); } @@ -236,19 +235,33 @@ private Optional calculateEngineeringSoundPower( parameters.put("absortionCoef", options.absorptionCoefficient()); parameters.put("temperature", options.temperature()); parameters.put("humidity", options.humidity()); parameters.put("atmosphericPressure", options.atmosphericPressure()); - if (options.measurementSurfaceArea() != null) - parameters.put("measurementSurfaceArea", options.measurementSurfaceArea()); + int nativeSurfaceType = soundPowerNativeSurface(options.surfaceType(), options.measurementSurfaceArea(), parameters); parameters.values().removeIf(Objects::isNull); var response = terminal - ? runtime.calculateTerminalEngineeringSoundPower(options.surfaceType(), options.calculationType(), + ? runtime.calculateTerminalEngineeringSoundPower(nativeSurfaceType, options.calculationType(), parameters, frequencies, levels, backgroundLevels) - : runtime.calculateEngineeringSoundPowerSurvey(options.surfaceType(), options.calculationType(), + : runtime.calculateEngineeringSoundPowerSurvey(nativeSurfaceType, options.calculationType(), parameters, frequencies, levels, backgroundLevels); return Optional.ofNullable(response).map(value -> new EngineeringSoundPowerResult(value.getFrequency(), value.getWeightedSoundPowerSpectrum(), value.getWeightedSoundPowerLevel(), value.getSoundPowerSpectrum(), value.getEquivalentSoundPressureSpectrum(), value.getK1(), value.getDs(), value.getK2(), value.getC1(), value.getC2(), value.getC3())); } + /** + * The released JNI calculates area from supported geometry. Encode the caller's + * area as an equal-area hemisphere only at that boundary; the measurement's + * actual geometry and point channels remain part of the plugin configuration. + */ + private static int soundPowerNativeSurface(int surface, Double area, Map parameters) { + if (area == null) { + return surface; + } + double radius = Math.sqrt(area) / Math.sqrt(2.0 * Math.PI); + parameters.put("sphereRadius", radius); + parameters.put("measureDistance", radius); + return 0; // Hemisphere with one reflecting plane, S = 2πr². + } + @Override public synchronized Optional calculateFrequencyWeighting(double[] frequencies, double[] levels, double sampleRate, int nativeWeightingType) { return Optional.ofNullable(runtime.calculateFrequencyWeighting(frequencies, levels, sampleRate, nativeWeightingType)); diff --git a/apps/backend/crydaq-algorithm-runtime/src/test/java/com/opentest/algorithm/runtime/PublicSoundPowerMathTest.java b/apps/backend/crydaq-algorithm-runtime/src/test/java/com/opentest/algorithm/runtime/PublicSoundPowerMathTest.java index 2b1d69fa..e6d63c18 100644 --- a/apps/backend/crydaq-algorithm-runtime/src/test/java/com/opentest/algorithm/runtime/PublicSoundPowerMathTest.java +++ b/apps/backend/crydaq-algorithm-runtime/src/test/java/com/opentest/algorithm/runtime/PublicSoundPowerMathTest.java @@ -70,15 +70,18 @@ class PublicSoundPowerMathTest { bridge.surveyStatus=13200001; assertTrue(service.calculateSoundPowerSurvey(options,new double[]{80},new double[]{40}).isEmpty()); } - @Test void explicitSurveyAreaUsesDedicatedSurfaceAndDoesNotChangeLegacyOperands() { + @Test void explicitSurveyAreaReachesTheReleasedNativeInterfaceAsTheSameArea() { var bridge = new NativeObservation(); var service = new PublicAlgorithmService(new AlgorithmLibJNIBridgeService(bridge)); var options = SoundPowerSurveyOptions.withArea(48.849555921539, 1000D, .5); assertTrue(service.calculateSoundPowerSurvey(options,new double[]{75},new double[]{65}).isPresent()); - assertEquals(-1, bridge.surface); - assertEquals(48.849555921539, bridge.parameters.get("measurementSurfaceArea")); + assertEquals(0, bridge.surface); + double radius = bridge.parameters.get("sphereRadius"); + assertEquals(options.measurementSurfaceArea(), 2.0 * Math.PI * radius * radius, 1e-10); + assertEquals(radius, bridge.parameters.get("measureDistance")); + assertEquals(1000D, bridge.parameters.get("roomSurface")); + assertEquals(.5, bridge.parameters.get("absortionCoef")); assertNull(bridge.parameters.get("length")); - assertNull(bridge.parameters.get("sphereRadius")); assertThrows(IllegalArgumentException.class, () -> SoundPowerSurveyOptions.withArea(Double.NaN,1000D,.5)); assertThrows(IllegalArgumentException.class, () -> new SoundPowerSurveyOptions(3,1D,1D,1D,1D,1D,1000D,.5,50D)); } diff --git a/apps/backend/crydaq-algorithm-runtime/src/test/java/com/opentest/algorithm/runtime/TerminalEngineeringSoundPowerTest.java b/apps/backend/crydaq-algorithm-runtime/src/test/java/com/opentest/algorithm/runtime/TerminalEngineeringSoundPowerTest.java index b5a5bef2..46031897 100644 --- a/apps/backend/crydaq-algorithm-runtime/src/test/java/com/opentest/algorithm/runtime/TerminalEngineeringSoundPowerTest.java +++ b/apps/backend/crydaq-algorithm-runtime/src/test/java/com/opentest/algorithm/runtime/TerminalEngineeringSoundPowerTest.java @@ -36,6 +36,26 @@ class TerminalEngineeringSoundPowerTest { frequencies[0] = -1; assertEquals(100, terminal.frequency()[0]); } + @Test void explicitEngineeringAreaUsesTheSameReleasedInterfaceForLiveAndTerminalResults() { + var nativeCall = new NativeCall(); + var api = api(nativeCall); + var options = new EngineeringSoundPowerOptions(-1, 0, null, null, null, null, null, + null, null, null, 1000D, .5, null, null, null, 31.46); + + assertTrue(api.calculateEngineeringSoundPower(options, new double[]{1000}, LEVELS, BACKGROUNDS).isPresent()); + Map liveParameters = Map.copyOf(nativeCall.parameters); + assertTrue(api.calculateTerminalEngineeringSoundPower(options, new double[]{1000}, LEVELS, BACKGROUNDS).isPresent()); + assertEquals(2, nativeCall.calls); + assertEquals(0, nativeCall.surface); + assertEquals(0, nativeCall.type); + assertEquals(liveParameters, nativeCall.parameters); + double radius = nativeCall.parameters.get("sphereRadius"); + assertEquals(31.46, 2.0 * Math.PI * radius * radius, 1e-10); + assertEquals(radius, nativeCall.parameters.get("measureDistance")); + assertEquals(1000D, nativeCall.parameters.get("roomSurface")); + assertEquals(.5, nativeCall.parameters.get("absortionCoef")); + } + @Test void actualNativeExceptionIsEmptyForOrdinaryAndRetainedAtTheTerminalBoundary() { var nativeCall = new NativeCall(); var api = api(nativeCall); var original = new IllegalStateException("native failed while calculating"); nativeCall.failure = original; diff --git a/apps/backend/opentest-algorithm-api/src/main/java/com/opentest/algorithm/api/SoundPowerSurveyOptions.java b/apps/backend/opentest-algorithm-api/src/main/java/com/opentest/algorithm/api/SoundPowerSurveyOptions.java index 721289c5..39649428 100644 --- a/apps/backend/opentest-algorithm-api/src/main/java/com/opentest/algorithm/api/SoundPowerSurveyOptions.java +++ b/apps/backend/opentest-algorithm-api/src/main/java/com/opentest/algorithm/api/SoundPowerSurveyOptions.java @@ -14,7 +14,7 @@ public SoundPowerSurveyOptions(int surfaceType, Double sphereRadius, Double meas this(surfaceType, sphereRadius, measureDistance, length, width, height, roomSurface, absorptionCoefficient, null); } - /** Area in m²; no synthetic geometry is required. Requires the explicit-area native runtime. */ + /** Area in m², independent of the shape used to transport it to the numerical backend. */ public static SoundPowerSurveyOptions withArea(double area, Double roomSurface, Double absorptionCoefficient) { return new SoundPowerSurveyOptions(-1, null, null, null, null, null, roomSurface, absorptionCoefficient, area); } From 2ab64b9237b5492e2659f65b2c32e8fae3435877 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E5=87=AF?= <324400663+KyleHuangFromHZ@users.noreply.github.com> Date: Mon, 16 Nov 2026 17:56:24 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix(sound-power):=20=E9=9A=94=E7=A6=BB?= =?UTF-8?q?=E6=98=BE=E5=BC=8F=E9=9D=A2=E7=A7=AF=E7=9A=84=20JNI=20=E5=87=A0?= =?UTF-8?q?=E4=BD=95=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../runtime/PublicAlgorithmService.java | 29 +++++++++++-------- .../runtime/PublicSoundPowerMathTest.java | 5 ++-- .../TerminalEngineeringSoundPowerTest.java | 17 +++++++++-- 3 files changed, 35 insertions(+), 16 deletions(-) diff --git a/apps/backend/crydaq-algorithm-runtime/src/main/java/com/opentest/algorithm/runtime/PublicAlgorithmService.java b/apps/backend/crydaq-algorithm-runtime/src/main/java/com/opentest/algorithm/runtime/PublicAlgorithmService.java index b22aa582..807a21a7 100644 --- a/apps/backend/crydaq-algorithm-runtime/src/main/java/com/opentest/algorithm/runtime/PublicAlgorithmService.java +++ b/apps/backend/crydaq-algorithm-runtime/src/main/java/com/opentest/algorithm/runtime/PublicAlgorithmService.java @@ -188,11 +188,13 @@ public PublicAlgorithmService(AlgorithmLibJNIBridgeService runtime, CurveNativeA SoundPowerSurveyOptions options, double[] levels, double[] backgroundLevels) { Objects.requireNonNull(options, "options"); var parameters = new HashMap(); - parameters.put("sphereRadius", options.sphereRadius()); - parameters.put("measureDistance", options.measureDistance()); - parameters.put("length", options.length()); - parameters.put("width", options.width()); - parameters.put("height", options.height()); + if (options.measurementSurfaceArea() == null) { + parameters.put("sphereRadius", options.sphereRadius()); + parameters.put("measureDistance", options.measureDistance()); + parameters.put("length", options.length()); + parameters.put("width", options.width()); + parameters.put("height", options.height()); + } parameters.put("roomSurface", options.roomSurface()); parameters.put("absortionCoef", options.absorptionCoefficient()); int nativeSurfaceType = soundPowerNativeSurface(options.surfaceType(), options.measurementSurfaceArea(), parameters); @@ -224,13 +226,15 @@ private Optional calculateEngineeringSoundPower( if (levels == null || levels.isEmpty() || backgroundLevels == null || backgroundLevels.isEmpty()) return Optional.empty(); var parameters = new HashMap(); - parameters.put("sphereRadius", options.sphereRadius()); - parameters.put("measureDistance", options.measureDistance()); - parameters.put("length", options.length()); parameters.put("width", options.width()); - parameters.put("height", options.height()); - parameters.put("cylinderMeasureDistance1", options.cylinderMeasureDistance1()); - parameters.put("cylinderMeasureDistance2", options.cylinderMeasureDistance2()); - parameters.put("cylinderMeasureDistance3", options.cylinderMeasureDistance3()); + if (options.measurementSurfaceArea() == null) { + parameters.put("sphereRadius", options.sphereRadius()); + parameters.put("measureDistance", options.measureDistance()); + parameters.put("length", options.length()); parameters.put("width", options.width()); + parameters.put("height", options.height()); + parameters.put("cylinderMeasureDistance1", options.cylinderMeasureDistance1()); + parameters.put("cylinderMeasureDistance2", options.cylinderMeasureDistance2()); + parameters.put("cylinderMeasureDistance3", options.cylinderMeasureDistance3()); + } parameters.put("roomSurface", options.roomSurface()); parameters.put("absortionCoef", options.absorptionCoefficient()); parameters.put("temperature", options.temperature()); parameters.put("humidity", options.humidity()); @@ -251,6 +255,7 @@ private Optional calculateEngineeringSoundPower( * The released JNI calculates area from supported geometry. Encode the caller's * area as an equal-area hemisphere only at that boundary; the measurement's * actual geometry and point channels remain part of the plugin configuration. + * The option records require a finite positive area and surface -1 for this path. */ private static int soundPowerNativeSurface(int surface, Double area, Map parameters) { if (area == null) { diff --git a/apps/backend/crydaq-algorithm-runtime/src/test/java/com/opentest/algorithm/runtime/PublicSoundPowerMathTest.java b/apps/backend/crydaq-algorithm-runtime/src/test/java/com/opentest/algorithm/runtime/PublicSoundPowerMathTest.java index e6d63c18..7d9c3631 100644 --- a/apps/backend/crydaq-algorithm-runtime/src/test/java/com/opentest/algorithm/runtime/PublicSoundPowerMathTest.java +++ b/apps/backend/crydaq-algorithm-runtime/src/test/java/com/opentest/algorithm/runtime/PublicSoundPowerMathTest.java @@ -73,7 +73,8 @@ class PublicSoundPowerMathTest { @Test void explicitSurveyAreaReachesTheReleasedNativeInterfaceAsTheSameArea() { var bridge = new NativeObservation(); var service = new PublicAlgorithmService(new AlgorithmLibJNIBridgeService(bridge)); - var options = SoundPowerSurveyOptions.withArea(48.849555921539, 1000D, .5); + var options = new SoundPowerSurveyOptions(-1, 9D, 1D, 4D, 5D, 6D, + 1000D, .5, 48.849555921539); assertTrue(service.calculateSoundPowerSurvey(options,new double[]{75},new double[]{65}).isPresent()); assertEquals(0, bridge.surface); double radius = bridge.parameters.get("sphereRadius"); @@ -81,7 +82,7 @@ class PublicSoundPowerMathTest { assertEquals(radius, bridge.parameters.get("measureDistance")); assertEquals(1000D, bridge.parameters.get("roomSurface")); assertEquals(.5, bridge.parameters.get("absortionCoef")); - assertNull(bridge.parameters.get("length")); + assertEquals(4, bridge.parameters.size()); assertThrows(IllegalArgumentException.class, () -> SoundPowerSurveyOptions.withArea(Double.NaN,1000D,.5)); assertThrows(IllegalArgumentException.class, () -> new SoundPowerSurveyOptions(3,1D,1D,1D,1D,1D,1000D,.5,50D)); } diff --git a/apps/backend/crydaq-algorithm-runtime/src/test/java/com/opentest/algorithm/runtime/TerminalEngineeringSoundPowerTest.java b/apps/backend/crydaq-algorithm-runtime/src/test/java/com/opentest/algorithm/runtime/TerminalEngineeringSoundPowerTest.java index 46031897..01580d2d 100644 --- a/apps/backend/crydaq-algorithm-runtime/src/test/java/com/opentest/algorithm/runtime/TerminalEngineeringSoundPowerTest.java +++ b/apps/backend/crydaq-algorithm-runtime/src/test/java/com/opentest/algorithm/runtime/TerminalEngineeringSoundPowerTest.java @@ -39,8 +39,8 @@ class TerminalEngineeringSoundPowerTest { @Test void explicitEngineeringAreaUsesTheSameReleasedInterfaceForLiveAndTerminalResults() { var nativeCall = new NativeCall(); var api = api(nativeCall); - var options = new EngineeringSoundPowerOptions(-1, 0, null, null, null, null, null, - null, null, null, 1000D, .5, null, null, null, 31.46); + var options = new EngineeringSoundPowerOptions(-1, 0, 9D, 1D, 4D, 5D, 6D, + 7D, 8D, 9D, 1000D, .5, null, null, null, 31.46); assertTrue(api.calculateEngineeringSoundPower(options, new double[]{1000}, LEVELS, BACKGROUNDS).isPresent()); Map liveParameters = Map.copyOf(nativeCall.parameters); @@ -54,6 +54,19 @@ class TerminalEngineeringSoundPowerTest { assertEquals(radius, nativeCall.parameters.get("measureDistance")); assertEquals(1000D, nativeCall.parameters.get("roomSurface")); assertEquals(.5, nativeCall.parameters.get("absortionCoef")); + assertEquals(4, nativeCall.parameters.size()); + } + + @Test void engineeringOptionsRejectInvalidAreaAndAreaWithLegacySurfaceType() { + for (Double invalidArea : new Double[]{null, 0D, -1D, Double.NaN, Double.POSITIVE_INFINITY}) { + assertThrows(IllegalArgumentException.class, () -> engineeringAreaOptions(-1, invalidArea)); + } + assertThrows(IllegalArgumentException.class, () -> engineeringAreaOptions(0, 31.46)); + } + + private static EngineeringSoundPowerOptions engineeringAreaOptions(int surface, Double area) { + return new EngineeringSoundPowerOptions(surface, 0, null, null, null, null, null, + null, null, null, 1000D, .5, null, null, null, area); } @Test void actualNativeExceptionIsEmptyForOrdinaryAndRetainedAtTheTerminalBoundary() {