diff options
author | Sven Gothel <[email protected]> | 2023-08-28 22:54:36 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2023-08-28 22:54:36 +0200 |
commit | 733cc5272cfed10fa07b707e29fd756f44581508 (patch) | |
tree | 1f175df7f89ad0c1fe7c810aa6e4ac2c535c9434 /src/jogl/classes/jogamp/graph | |
parent | d6056f4daf2bd6f19cc3f8ff7ca1a812d8db9695 (diff) |
Graph Loop: Make initFromPolyline() and locateClosestVertex() more robust, report error but do not crash.
This behavior has been evaluated with a few fonts and the WIP FontView01 demo application.
Diffstat (limited to 'src/jogl/classes/jogamp/graph')
3 files changed, 33 insertions, 11 deletions
diff --git a/src/jogl/classes/jogamp/graph/curve/tess/CDTriangulator2D.java b/src/jogl/classes/jogamp/graph/curve/tess/CDTriangulator2D.java index 85a18c982..e187b1590 100644 --- a/src/jogl/classes/jogamp/graph/curve/tess/CDTriangulator2D.java +++ b/src/jogl/classes/jogamp/graph/curve/tess/CDTriangulator2D.java @@ -1,5 +1,5 @@ /** - * Copyright 2010 JogAmp Community. All rights reserved. + * Copyright 2010-2023 JogAmp Community. All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: @@ -83,15 +83,17 @@ public class CDTriangulator2D implements Triangulator { public final void addCurve(final List<Triangle> sink, final Outline polyline, final float sharpness) { Loop loop = getContainerLoop(polyline); - if(loop == null) { + if( null == loop ) { final Winding winding = Winding.CCW; // -> HEdge.BOUNDARY // Too late: polyline.setWinding(winding); final GraphOutline outline = new GraphOutline(polyline); // , winding); final GraphOutline innerPoly = extractBoundaryTriangles(sink, outline, false, sharpness); // vertices.addAll(polyline.getVertices()); if( innerPoly.getGraphPoint().size() >= 3 ) { - loop = new Loop(innerPoly, winding); - loops.add(loop); + loop = Loop.create(innerPoly, winding); + if( null != loop ) { + loops.add(loop); + } } else if( DEBUG ) { /* * Font FreeMono-Bold: ID 0 + 465: Glyph[id 465 'uni020F', advance 600, leftSideBearings 42, kerning[size 0, horiz true, cross true], shape true], OutlineShape@5e8a459[outlines 2, vertices 34] diff --git a/src/jogl/classes/jogamp/graph/curve/tess/GraphOutline.java b/src/jogl/classes/jogamp/graph/curve/tess/GraphOutline.java index 75192d45a..a2b789862 100644 --- a/src/jogl/classes/jogamp/graph/curve/tess/GraphOutline.java +++ b/src/jogl/classes/jogamp/graph/curve/tess/GraphOutline.java @@ -1,5 +1,5 @@ /** - * Copyright 2010 JogAmp Community. All rights reserved. + * Copyright 2010-2023 JogAmp Community. All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: @@ -29,11 +29,14 @@ package jogamp.graph.curve.tess; import java.util.ArrayList; +import com.jogamp.graph.curve.Region; import com.jogamp.graph.geom.Outline; import com.jogamp.graph.geom.Vertex; -import com.jogamp.graph.geom.plane.Winding; public class GraphOutline { + /** Debug flag for [com.]jogamp.graph.curve.* (graph.curve) */ + /* pp */ static boolean DEBUG = Region.DEBUG; // Debug.debug("graph.curve"); + final private Outline outline; final private ArrayList<GraphVertex> controlpoints = new ArrayList<GraphVertex>(3); diff --git a/src/jogl/classes/jogamp/graph/curve/tess/Loop.java b/src/jogl/classes/jogamp/graph/curve/tess/Loop.java index 1939dcb1e..6020e7c66 100644 --- a/src/jogl/classes/jogamp/graph/curve/tess/Loop.java +++ b/src/jogl/classes/jogamp/graph/curve/tess/Loop.java @@ -1,5 +1,5 @@ /** - * Copyright 2010 JogAmp Community. All rights reserved. + * Copyright 2010-2023 JogAmp Community. All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: @@ -35,7 +35,6 @@ import com.jogamp.graph.geom.plane.Winding; import com.jogamp.graph.geom.Triangle; import com.jogamp.opengl.math.Vec3f; import com.jogamp.opengl.math.VectorUtil; -import com.jogamp.opengl.math.Vert2fImmutable; import com.jogamp.opengl.math.geom.AABBox; public class Loop { @@ -43,11 +42,16 @@ public class Loop { private final AABBox box = new AABBox(); private GraphOutline initialOutline = null; - public Loop(final GraphOutline polyline, final Winding winding){ + private Loop(final GraphOutline polyline, final Winding winding){ initialOutline = polyline; this.root = initFromPolyline(initialOutline, winding); } + public static Loop create(final GraphOutline polyline, final Winding winding) { + final Loop res = new Loop(polyline, winding); + return null != res.root ? res : null; + } + public HEdge getHEdge(){ return root; } @@ -116,7 +120,11 @@ public class Loop { final ArrayList<GraphVertex> vertices = outline.getGraphPoint(); if(vertices.size()<3) { - throw new IllegalArgumentException("outline's vertices < 3: " + vertices.size()); + System.err.println( "Graph: Loop.initFromPolyline: GraphOutline's vertices < 3: " + vertices.size() ); + if( GraphOutline.DEBUG ) { + Thread.dumpStack(); + } + return null; } final Winding hasWinding = getWinding( vertices ); // requires area-winding detection @@ -183,9 +191,18 @@ public class Loop { public void addConstraintCurve(final GraphOutline polyline) { // GraphOutline outline = new GraphOutline(polyline); /**needed to generate vertex references.*/ - initFromPolyline(polyline, Winding.CW); // -> HEdge.HOLE + if( null == initFromPolyline(polyline, Winding.CW) ) { // -> HEdge.HOLE + return; + } final GraphVertex v3 = locateClosestVertex(polyline); + if( null == v3 ) { + System.err.println( "Graph: Loop.locateClosestVertex returns null; root valid? "+(null!=root)); + if( GraphOutline.DEBUG ) { + Thread.dumpStack(); + } + return; + } final HEdge v3Edge = v3.findBoundEdge(); final HEdge v3EdgeP = v3Edge.getPrev(); final HEdge crossEdge = new HEdge(root.getGraphPoint(), HEdge.INNER); |