Skip to content

Commit 8d9270d

Browse files
committed
Trying to understand this difference in behavior for legacy
1 parent 4a1c827 commit 8d9270d

File tree

2 files changed

+81
-3
lines changed

2 files changed

+81
-3
lines changed

UnitTests/LegacyHelper.cs

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
using Clipper2Lib;
2+
using geoWrangler;
3+
using shapeEngine;
4+
5+
namespace UnitTests;
6+
using System;
7+
using System.Reflection;
8+
9+
// Paste this into your test project (same assembly as ShapeLibrary) and call InvokeLegacyFromTest.
10+
// Requires the project's PathD, ShapeLibrary, GeoWrangler and Clipper types to be in scope.
11+
12+
public static class LegacyReflectionHelper
13+
{
14+
/// <summary>
15+
/// Invokes the private legacy_processCorners_actual method on an existing ShapeLibrary instance.
16+
/// Returns the produced PathD and its signed area (as returned by Clipper.Area).
17+
/// </summary>
18+
public static (PathD path, double area) InvokeLegacy(
19+
ShapeLibrary shapeLib,
20+
bool previewMode,
21+
bool cornerCheck,
22+
int cornerSegments,
23+
int optimizeCorners,
24+
double resolution,
25+
bool iCPA = false,
26+
bool oCPA = false,
27+
double iCV = 0.0,
28+
double iCVariation_scalar = 0.0,
29+
double oCV = 0.0,
30+
double oCVariation_scalar = 0.0)
31+
{
32+
if (shapeLib == null) throw new ArgumentNullException(nameof(shapeLib));
33+
34+
var method = typeof(ShapeLibrary).GetMethod(
35+
"legacy_processCorners_actual",
36+
BindingFlags.NonPublic | BindingFlags.Instance);
37+
38+
if (method == null)
39+
throw new InvalidOperationException("legacy_processCorners_actual method not found on ShapeLibrary");
40+
41+
object[] args = new object[]
42+
{
43+
previewMode,
44+
cornerCheck,
45+
cornerSegments,
46+
optimizeCorners,
47+
resolution,
48+
iCPA,
49+
oCPA,
50+
iCV,
51+
iCVariation_scalar,
52+
oCV,
53+
oCVariation_scalar
54+
};
55+
56+
// If the private method throws, TargetInvocationException will be raised — let it bubble so the test can see the cause.
57+
var result = method.Invoke(shapeLib, args) as PathD ?? new PathD();
58+
59+
// Optionally remove duplicate points before area measurement to match other tests:
60+
var clean = GeoWrangler.removeDuplicates(result);
61+
62+
double area = Clipper.Area(clean);
63+
64+
return (clean, area);
65+
}
66+
}

UnitTests/ShapeEngineTests.cs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1597,15 +1597,27 @@ public static void customOrthoOuterRoundingTest()
15971597
shape.setShape(shapeSettings.getInt(ShapeSettings.properties_i.shapeIndex), customShape);
15981598
// Check the shape settings are in the shape.
15991599
Assert.That(shape.shapeIndex, Is.EqualTo((int)ShapeLibrary.shapeNames_all.GEOCORE));
1600-
PathD out_ = shape.processCorners(false, false, 90, 1, .5);
1600+
PathD out_ = shape.processCorners(false, false, 90, 1, .01);
16011601
SvgWriter svgSrc = new SvgWriter();
16021602
SvgUtils.AddSolution(svgSrc, new() { out_ }, true);
16031603
SvgUtils.SaveToFile(svgSrc, root_loc + "customortho_outer.svg", FillRule.NonZero, 800, 800, 10);
16041604
// Corners can have duplicate points.
16051605
PathD clean = GeoWrangler.removeDuplicates(out_);
1606-
Assert.That(clean.Count, Is.EqualTo(115));
1606+
// Assert.That(clean.Count, Is.EqualTo(115));
16071607
// Check expected area
1608-
// double area = Clipper.Area(out_);
1608+
double area = Clipper.Area(out_);
1609+
// Call the private legacy routine directly
1610+
var (legacyPath, legacyArea) = LegacyReflectionHelper.InvokeLegacy(
1611+
shape,
1612+
previewMode: false,
1613+
cornerCheck: false,
1614+
cornerSegments: 90,
1615+
optimizeCorners: 0, // optimization off
1616+
resolution: 0.01,
1617+
iCPA: false,
1618+
oCPA: false,
1619+
iCV: 0, iCVariation_scalar: 0, oCV: 0, oCVariation_scalar: 0
1620+
);
16091621
// Assert.That(Math.Abs(-(Math.PI * 10 * 10) - area), Is.LessThanOrEqualTo(0.15));
16101622
RectD bounds = Clipper.GetBounds(clean);
16111623
Assert.That(bounds.Width, Is.GreaterThanOrEqualTo(19.99));

0 commit comments

Comments
 (0)