Improve tessellation algorithm

Added new mesh class
Rewrite mesh algorithms to be less error prone
Make code more concise
Tried to add some documentation
Added half edge set
This commit is contained in:
2025-05-03 23:52:54 -04:00
parent a1899a52b7
commit d16041f977
30 changed files with 2923 additions and 227 deletions

View File

@@ -9,6 +9,9 @@ import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import com.aaaaahhhhhhh.bananapuncher714.mesh.Point;
import com.aaaaahhhhhhh.bananapuncher714.mesh.Polygon;
import com.aaaaahhhhhhh.bananapuncher714.mesh.Vector2d;
import com.aaaaahhhhhhh.bananapuncher714.tess4j.region.RegionSimple;
import com.aaaaahhhhhhh.bananapuncher714.tess4j.region.RegionSimple.GluWindingRule;
import com.aaaaahhhhhhh.bananapuncher714.tess4j.region.WindingRuleSimple;
@@ -114,14 +117,14 @@ public class Tess4jTest extends JPanel {
public double compareX( Vector2d a, Vector2d b ) {
a = rotate( a, 128 );
b = rotate( b, 128 );
return a.x - b.x;
return a.getX() - b.getX();
}
@Override
public double compareY(Vector2d a, Vector2d b ) {
a = rotate( a, 128 );
b = rotate( b, 128 );
return b.y - a.y;
return b.getY() - a.getY();
}
} );
// tess4j.addPolygon( new Polygon( Arrays.asList(
@@ -195,21 +198,21 @@ public class Tess4jTest extends JPanel {
System.out.println( "Polygon count" );
System.out.println( polygons.size() );
for ( Polygon p : polygons ) {
System.out.println( p.points.size() );
int size = p.points.size();
System.out.println( p.getPoints().size() );
int size = p.getPoints().size();
int[] xPoints = new int[ size ];
int[] yPoints = new int[ size ];
for ( int i = 0; i < p.points.size(); i++ ) {
Point point = p.points.get( i );
for ( int i = 0; i < p.getPoints().size(); i++ ) {
Point point = p.getPoints().get( i );
System.out.println( point.x + ", " + point.y );
Vector2d pVec = new Vector2d( point.x, point.y );
System.out.println( point.getX() + ", " + point.getY() );
Vector2d pVec = new Vector2d( point.getX(), point.getY() );
pVec = rotate( pVec, 0 );
point = new Point( pVec.getX(), pVec.getY() );
xPoints[ i ] = ( int ) ( point.x * scale ) + centerX;
yPoints[ i ] = 100 - ( int ) ( point.y * scale ) + centerY;
xPoints[ i ] = ( int ) ( point.getX() * scale ) + centerX;
yPoints[ i ] = 100 - ( int ) ( point.getY() * scale ) + centerY;
}
g.setColor( new Color( ( int ) ( Math.random() * 0xFFFFFF ) ) );
@@ -218,13 +221,13 @@ public class Tess4jTest extends JPanel {
g.setColor( Color.BLACK );
for ( Polygon p : polygons ) {
for ( Point point : p.points ) {
Vector2d pVec = new Vector2d( point.x, point.y );
for ( Point point : p.getPoints() ) {
Vector2d pVec = new Vector2d( point.getX(), point.getY() );
pVec = rotate( pVec, 0 );
point = new Point( pVec.getX(), pVec.getY() );
double diff = scale * .05;
g.drawRect( ( int ) ( point.x * scale ) + centerX - ( int ) diff, 100 - ( int ) ( point.y * scale ) + centerY - ( int ) diff, ( int ) ( diff * 2 ), ( int ) ( diff * 2 ) );
g.drawRect( ( int ) ( point.getX() * scale ) + centerX - ( int ) diff, 100 - ( int ) ( point.getY() * scale ) + centerY - ( int ) diff, ( int ) ( diff * 2 ), ( int ) ( diff * 2 ) );
}
}