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:
@@ -9,6 +9,8 @@ import java.util.Optional;
|
||||
|
||||
import org.joml.Math;
|
||||
|
||||
import com.aaaaahhhhhhh.bananapuncher714.mesh.Point;
|
||||
|
||||
public class Util {
|
||||
protected static String toString( Object obj ) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
@@ -142,8 +144,8 @@ public class Util {
|
||||
if ( qpr == 0 ) {
|
||||
// Do not need to calculate the distance between the two parallel lines since it is 0
|
||||
final Vector2dOld midpoint = r.multiply( midt ).add( p );
|
||||
point.x = midpoint.x;
|
||||
point.y = midpoint.y;
|
||||
point.setX( midpoint.x );
|
||||
point.setY( midpoint.y );
|
||||
} else {
|
||||
// Calculate the midpoint along pr
|
||||
final Vector2dOld midp = r.multiply( midt ).add( p );
|
||||
@@ -152,8 +154,8 @@ public class Util {
|
||||
final Vector2dOld z = perp.multiply( qp.dot( perp ) / rr );
|
||||
// Sum the components
|
||||
final Vector2dOld midpoint = midp.add( z.divide( 2.0 ) );
|
||||
point.x = midpoint.x;
|
||||
point.y = midpoint.y;
|
||||
point.setX( midpoint.x );
|
||||
point.setY( midpoint.y );
|
||||
}
|
||||
} else {
|
||||
// The lines aren't really anywhere close to each other, so just find the midpoint between the 2 closest points
|
||||
@@ -162,8 +164,8 @@ public class Util {
|
||||
// Same as the first edge but the second edge may be inverted
|
||||
final Vector2dOld qv = ( inverted ^ t0 > 1 ) ? q : v;
|
||||
final Vector2dOld midpoint = pu.add( qv ).divide( 2.0 );
|
||||
point.x = midpoint.x;
|
||||
point.y = midpoint.y;
|
||||
point.setX( midpoint.x );
|
||||
point.setY( midpoint.y );
|
||||
}
|
||||
} else {
|
||||
// Calculate t and u
|
||||
@@ -174,8 +176,8 @@ public class Util {
|
||||
if ( t >= 0 && t <= 1 && u >= 0 && u <= 1 ) {
|
||||
// Calculate the point of intersection
|
||||
final Vector2dOld intersection = r.multiply( t ).add( p );
|
||||
point.x = intersection.x;
|
||||
point.y = intersection.y;
|
||||
point.setX( intersection.x );
|
||||
point.setY( intersection.y );
|
||||
} else {
|
||||
// No intersection, so calculate the closest point between the two segments
|
||||
// We have t and u, which we can use to find the closest endpoints
|
||||
@@ -185,8 +187,8 @@ public class Util {
|
||||
final Vector2dOld nearP = r.multiply( nearT ).add( p );
|
||||
final Vector2dOld nearQ = s.multiply( nearU ).add( q );
|
||||
|
||||
point.x = ( nearP.x + nearQ.x ) / 2.0;
|
||||
point.y = ( nearP.y + nearQ.y ) / 2.0;
|
||||
point.setX( ( nearP.x + nearQ.x ) / 2.0 );
|
||||
point.setY( ( nearP.y + nearQ.y ) / 2.0 );
|
||||
}
|
||||
}
|
||||
return point;
|
||||
|
||||
Reference in New Issue
Block a user