From a77b487a44124a9e55fa9a53d1f9c3ae20b9c3ba Mon Sep 17 00:00:00 2001 From: Sven Göthel Date: Mon, 12 Feb 2024 06:17:07 +0100 Subject: Bug 1501: Graph Delaunay: Use default winding outer-boundary:=CCW and inner-hole:=CW w/o using winding determination (might be incorrect) This simplifies our code further and it has been validated that our polygon shoelace-algo for area >= 0 ? CCW doesn't produce correct results with all curves. Hence rely on given winding depending on outer-boundary and inner-hole if CDTriangulator2D.FixedWindingRule == true (default and fixed). This also removes the more costly winding shoelace calculus, hence Outline ctor only sets dirtyWinding:=true w/o calculating the winding. --- src/jogl/classes/com/jogamp/math/VectorUtil.java | 56 +++++++++++++++++++----- 1 file changed, 45 insertions(+), 11 deletions(-) (limited to 'src/jogl/classes/com/jogamp/math') diff --git a/src/jogl/classes/com/jogamp/math/VectorUtil.java b/src/jogl/classes/com/jogamp/math/VectorUtil.java index 716b63e47..7e66f0b4f 100644 --- a/src/jogl/classes/com/jogamp/math/VectorUtil.java +++ b/src/jogl/classes/com/jogamp/math/VectorUtil.java @@ -537,7 +537,7 @@ public final class VectorUtil { /** * Check if points are in ccw order *

- * Consider using {@link #getWinding(ArrayList)} using the {@link #area(ArrayList)} function over all points + * Consider using {@link #getWinding2f(ArrayList)} using the {@link #area2f(ArrayList)} function over all points * on complex shapes for a reliable result! *

* @param a first vertex @@ -552,29 +552,29 @@ public final class VectorUtil { /** * Compute the winding of the 3 given points *

- * Consider using {@link #getWinding(ArrayList)} using the {@link #area(ArrayList)} function over all points + * Consider using {@link #getWinding2f(ArrayList)} using the {@link #area2f(ArrayList)} function over all points * on complex shapes for a reliable result! *

* @param a first vertex * @param b second vertex * @param c third vertex * @return {@link Winding#CCW} or {@link Winding#CW} - * @see #getWinding(ArrayList) + * @see #getWinding2f(ArrayList) */ public static Winding getWinding(final Vert2fImmutable a, final Vert2fImmutable b, final Vert2fImmutable c) { return triAreaVec2d(a,b,c) > InCircleDThreshold ? Winding.CCW : Winding.CW ; } /** - * Computes the area of a list of vertices. + * Computes the area of a list of vertices via shoelace formula. *

* This method is utilized e.g. to reliably compute the {@link Winding} of complex shapes. *

* @param vertices * @return positive area if ccw else negative area value - * @see #getWinding(ArrayList) + * @see #getWinding2f(ArrayList) */ - public static float area(final ArrayList vertices) { + public static float area2f(final ArrayList vertices) { final int n = vertices.size(); float area = 0.0f; for (int p = n - 1, q = 0; q < n; p = q++) { @@ -586,17 +586,51 @@ public final class VectorUtil { } /** - * Compute the winding using the {@link #area(ArrayList)} function over all vertices for complex shapes. + * Compute the winding using the {@link #area2f(ArrayList)} function over all vertices for complex shapes. *

- * Uses the {@link #area(ArrayList)} function over all points + * Uses the {@link #area2f(ArrayList)} function over all points * on complex shapes for a reliable result! *

* @param vertices array of Vertices * @return {@link Winding#CCW} or {@link Winding#CW} - * @see #area(ArrayList) + * @see #area2f(ArrayList) */ - public static Winding getWinding(final ArrayList vertices) { - return area(vertices) >= 0 ? Winding.CCW : Winding.CW ; + public static Winding getWinding2f(final ArrayList vertices) { + return area2f(vertices) >= 0 ? Winding.CCW : Winding.CW ; + } + + /** + * Computes the area of a list of vertices via shoelace formula. + *

+ * This method is utilized e.g. to reliably compute the {@link Winding} of complex shapes. + *

+ * @param vertices + * @return positive area if ccw else negative area value + * @see #getWinding2d(ArrayList) + */ + public static double area2d(final ArrayList vertices) { + final int n = vertices.size(); + double area = 0.0; + for (int p = n - 1, q = 0; q < n; p = q++) { + final Vert2fImmutable pCoord = vertices.get(p); + final Vert2fImmutable qCoord = vertices.get(q); + area += (double)pCoord.x() * (double)qCoord.y() - (double)qCoord.x() * (double)pCoord.y(); + } + return area; + } + + /** + * Compute the winding using the {@link #area2f(ArrayList)} function over all vertices for complex shapes. + *

+ * Uses the {@link #area2f(ArrayList)} function over all points + * on complex shapes for a reliable result! + *

+ * @param vertices array of Vertices + * @return {@link Winding#CCW} or {@link Winding#CW} + * @see #area2d(ArrayList) + */ + public static Winding getWinding2d(final ArrayList vertices) { + return area2d(vertices) >= 0 ? Winding.CCW : Winding.CW ; } /** -- cgit v1.2.3