Files
mc-mesh/src/main/java/com/aaaaahhhhhhh/bananapuncher714/tess4j/HalfWing.java
BananaPuncher714 d16041f977 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
2025-05-04 00:04:22 -04:00

108 lines
2.3 KiB
Java

package com.aaaaahhhhhhh.bananapuncher714.tess4j;
import com.aaaaahhhhhhh.bananapuncher714.mesh.Vector2d;
public class HalfWing {
protected HalfWing sym;
protected HalfWing prev;
protected HalfWing next;
protected Vertex origin;
public HalfWing() {
init();
new HalfWing( this );
}
private HalfWing( HalfWing o ) {
init();
sym = o;
o.sym = this;
next = o;
o.next = this;
}
private void init() {
origin = new Vertex( this );
prev = this;
}
public Vertex getOrigin() {
return origin;
}
public HalfWing setOrigin( Vertex vert ) {
origin = vert;
return this;
}
public HalfWing getSym() {
return sym;
}
public HalfWing getPrev() {
return prev;
}
public HalfWing setPrev( HalfWing wing ) {
this.prev = wing;
return this;
}
public HalfWing getNext() {
return next;
}
public HalfWing setNext( HalfWing wing ) {
this.next = wing;
return this;
}
public Vertex getDest() {
return sym.origin;
}
public Vector2d toVector2d() {
return getDest().getPosition().subtracted( getOrigin().getPosition() );
}
public boolean isZero() {
return getOrigin().equals( getDest() );
}
// Split this edge in half, and return the new edge
public HalfWing split() {
HalfWing wing = new HalfWing();
splice( wing, getNext() );
splice( getSym(), getNext() );
splice( getSym(), wing.getSym() );
wing.setOrigin( getDest() );
wing.getOrigin().setWing( wing );
getSym().setOrigin( wing.getDest() );
getDest().setWing( getSym() );
wing.getOrigin().update();
wing.getDest().update();
return wing.getSym();
}
public static void splice( HalfWing a, HalfWing b ) {
HalfWing ap = a.prev;
HalfWing bp = b.prev;
a.prev = bp;
b.prev = ap;
ap.sym.next = b;
bp.sym.next = a;
}
}