Skip to content

Commit

Permalink
Fixed issue #456.
Browse files Browse the repository at this point in the history
  • Loading branch information
nilsschmidt1337 committed Sep 25, 2016
1 parent a3efac4 commit 1b254bc
Show file tree
Hide file tree
Showing 9 changed files with 418 additions and 173 deletions.
2 changes: 1 addition & 1 deletion src/org/nschmidt/csg/Polygon.java
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ public HashMap<GData3, Integer> toLDrawTriangles2(GData1 parent) {
org.nschmidt.ldparteditor.helpers.math.Vector3d.sub(vertexB, vertexC, vertexB);
boolean parseError = org.nschmidt.ldparteditor.helpers.math.Vector3d.angle(vertexA, vertexB) < Threshold.collinear_angle_minimum;

parseError = parseError ||vertexA.length().compareTo(identical_vertex_distance) < 0;
parseError = parseError || vertexA.length().compareTo(identical_vertex_distance) < 0;
parseError = parseError || vertexB.length().compareTo(identical_vertex_distance) < 0;
parseError = parseError || org.nschmidt.ldparteditor.helpers.math.Vector3d.sub(vertexA, vertexB).length().compareTo(identical_vertex_distance) < 0;

Expand Down
31 changes: 26 additions & 5 deletions src/org/nschmidt/ldparteditor/data/GData3.java
Original file line number Diff line number Diff line change
Expand Up @@ -1484,14 +1484,35 @@ public void getVertexNormalMapNOCLIP(GDataState state, ThreadsafeTreeMap<Vertex,
}

public boolean isCollinear() {
double angle;
Vector3d vertexA = new Vector3d(X1, Y1, Z1);
Vector3d vertexB = new Vector3d(X2, Y2, Z2);
Vector3d vertexC = new Vector3d(X3, Y3, Z3);
Vector3d vertexA2 = new Vector3d();
Vector3d vertexB2 = new Vector3d();
Vector3d.sub(vertexA, vertexC, vertexA2);
Vector3d.sub(vertexB, vertexC, vertexB2);
return Vector3d.angle(vertexA2, vertexB2) < Threshold.collinear_angle_minimum;
Vector3d A = new Vector3d();
Vector3d B = new Vector3d();
Vector3d C = new Vector3d();
Vector3d.sub(vertexB, vertexA, A);
Vector3d.sub(vertexC, vertexB, B);
Vector3d.sub(vertexC, vertexA, C);

angle = Vector3d.angle(A, C);
double sumAngle = angle;
if (angle < Threshold.collinear_angle_minimum || angle > Threshold.collinear_angle_maximum) {
return true;
}

A.negate();
angle = Vector3d.angle(A, B);
sumAngle = sumAngle + angle;
if (angle < Threshold.collinear_angle_minimum || angle > Threshold.collinear_angle_maximum) {
return true;
}

angle = 180.0 - sumAngle;
if (angle < Threshold.collinear_angle_minimum || angle > Threshold.collinear_angle_maximum) {
return true;
}
return false;
}

public String colourReplace(String col) {
Expand Down
48 changes: 35 additions & 13 deletions src/org/nschmidt/ldparteditor/data/GData4.java
Original file line number Diff line number Diff line change
Expand Up @@ -1150,13 +1150,13 @@ public void drawGL20_BFC_Textured(Composite3D c3d) {
tex.calcUVcoords4(x4, y4, z4, parent);
uv = tex.getUVcoords(false, this);
GL11.glTexCoord2f(uv[0], uv[1]);
c3d.getVertexManager().setVertexAndNormal(x1, y1, z1, false, this, useCubeMap);
c3d.getVertexManager().setVertexAndNormal(x1, y1, z1, true, this, useCubeMap);
GL11.glTexCoord2f(uv[2], uv[3]);
c3d.getVertexManager().setVertexAndNormal(x2, y2, z2, false, this, useCubeMap);
c3d.getVertexManager().setVertexAndNormal(x2, y2, z2, true, this, useCubeMap);
GL11.glTexCoord2f(uv[4], uv[5]);
c3d.getVertexManager().setVertexAndNormal(x3, y3, z3, false, this, useCubeMap);
c3d.getVertexManager().setVertexAndNormal(x3, y3, z3, true, this, useCubeMap);
GL11.glTexCoord2f(uv[6], uv[7]);
c3d.getVertexManager().setVertexAndNormal(x4, y4, z4, false, this, useCubeMap);
c3d.getVertexManager().setVertexAndNormal(x4, y4, z4, true, this, useCubeMap);
GL11.glEnd();
} else {
GL11.glColor4f(r, g, b, a);
Expand Down Expand Up @@ -1632,15 +1632,37 @@ public boolean isCollinear() {
Vector3d vertexB = new Vector3d(X2, Y2, Z2);
Vector3d vertexC = new Vector3d(X3, Y3, Z3);
Vector3d vertexD = new Vector3d(X4, Y4, Z4);
Vector3d.sub(vertexA, vertexD, vertexA);
Vector3d.sub(vertexB, vertexD, vertexB);
Vector3d.sub(vertexC, vertexD, vertexC);
boolean parseError = false;
parseError = Vector3d.angle(vertexA, vertexB) < Threshold.collinear_angle_minimum;
parseError = parseError || Vector3d.angle(vertexB, vertexC) < Threshold.collinear_angle_minimum;
parseError = parseError || 180.0 - Vector3d.angle(vertexA, vertexC) < Threshold.collinear_angle_minimum;
parseError = parseError || 180.0 - Vector3d.angle(Vector3d.sub(vertexC, vertexB), Vector3d.sub(vertexA, vertexB)) < Threshold.collinear_angle_minimum;
return parseError;
Vector3d A = Vector3d.sub(vertexB, vertexA);
Vector3d B = Vector3d.sub(vertexB, vertexC);
Vector3d C = Vector3d.sub(vertexD, vertexC);
Vector3d D = Vector3d.sub(vertexD, vertexA);

double angle = Vector3d.angle(A, D);
double sumAngle = angle;
if (angle < Threshold.collinear_angle_minimum || angle > Threshold.collinear_angle_maximum) {
return true;
}

angle = Vector3d.angle(B, C);
sumAngle = sumAngle + angle;
if (angle < Threshold.collinear_angle_minimum || angle > Threshold.collinear_angle_maximum) {
return true;
}

A.negate();
B.negate();
angle = Vector3d.angle(A, B);
sumAngle = sumAngle + angle;
if (angle < Threshold.collinear_angle_minimum || angle > Threshold.collinear_angle_maximum) {
return true;
}

angle = 360.0 - sumAngle;
if (angle < Threshold.collinear_angle_minimum || angle > Threshold.collinear_angle_maximum) {
return true;
}

return false;
}

public int getHourglassConfiguration() {
Expand Down
90 changes: 70 additions & 20 deletions src/org/nschmidt/ldparteditor/data/VM02Add.java
Original file line number Diff line number Diff line change
Expand Up @@ -406,17 +406,41 @@ public void addTriangle(Vertex v1, Vertex v2, Vertex v3, Composite3D c3d, boolea
}

// Resolving Collinearity
Vector3f v13f = new Vector3f(v1.x, v1.y, v1.z);
Vector3f v23f = new Vector3f(v2.x, v2.y, v2.z);
Vector3f v33f = new Vector3f(v3.x, v3.y, v3.z);
Vector3f.sub(v13f, v33f, v13f);
Vector3f.sub(v23f, v33f, v23f);
double angle = Vector3f.angle(v13f, v23f) * 180d / Math.PI;;
if (angle < Threshold.collinear_angle_minimum && !allowInvalidShapes) {
double angle;
Vector3f a = new Vector3f();
Vector3f b = new Vector3f();
Vector3f c = new Vector3f();

{
Vector3f v13f = new Vector3f(v1.x, v1.y, v1.z);
Vector3f v23f = new Vector3f(v2.x, v2.y, v2.z);
Vector3f v33f = new Vector3f(v3.x, v3.y, v3.z);
Vector3f.sub(v23f, v13f, a);
Vector3f.sub(v33f, v23f, b);
Vector3f.sub(v33f, v13f, c);
}

angle = Vector3f.angle(a, c) * 180d / Math.PI;
double sumAngle = angle;
if ((angle < Threshold.collinear_angle_minimum || angle > Threshold.collinear_angle_maximum) && !allowInvalidShapes) {
linkedDatFile.setObjVertex3(null);
return;
}


a.negate();
angle = Vector3f.angle(a, b) * 180d / Math.PI;
sumAngle = sumAngle + angle;
if ((angle < Threshold.collinear_angle_minimum || angle > Threshold.collinear_angle_maximum) && !allowInvalidShapes) {
linkedDatFile.setObjVertex3(null);
return;
}

angle = 180.0 - sumAngle;
if ((angle < Threshold.collinear_angle_minimum || angle > Threshold.collinear_angle_maximum) && !allowInvalidShapes) {
linkedDatFile.setObjVertex3(null);
return;
}

Vector4f n = new Vector4f();
n.setW(1f);
n.setX((v3.y - v1.y) * (v2.z - v1.z) - (v3.z - v1.z) * (v2.y - v1.y));
Expand Down Expand Up @@ -610,19 +634,45 @@ public void addQuad(Vertex v1, Vertex v2, Vertex v3, Vertex v4, Composite3D c3d)
double angle2 = Vector3f.angle(normals[0], normals[2]) * 180d / Math.PI;
double angle;

boolean parseError = false;
Vector3f.sub(v13f, v43f, v13f);
Vector3f.sub(v23f, v43f, v23f);
Vector3f.sub(v33f, v43f, v33f);
angle = Vector3f.angle(v13f, v23f) * 180d / Math.PI;;
parseError = angle < Threshold.collinear_angle_minimum;
angle = Vector3f.angle(v23f, v33f) * 180d / Math.PI;;
parseError = parseError || angle < Threshold.collinear_angle_minimum;
angle = Vector3f.angle(v33f, v13f) * 180d / Math.PI;;
parseError = parseError || angle < Threshold.collinear_angle_minimum;

// Collinearity
if (parseError && !allowInvalidShapes) {
Vector3f a = new Vector3f();
Vector3f b = new Vector3f();
Vector3f c = new Vector3f();
Vector3f d = new Vector3f();

Vector3f.sub(v23f, v13f, a);
Vector3f.sub(v23f, v33f, b);
Vector3f.sub(v43f, v33f, c);
Vector3f.sub(v43f, v13f, d);

angle = Vector3f.angle(a, d) * 180d / Math.PI;
double sumAngle = angle;
if ((angle < Threshold.collinear_angle_minimum || angle > Threshold.collinear_angle_maximum) && !allowInvalidShapes) {
linkedDatFile.setObjVertex3(null);
linkedDatFile.setObjVertex4(null);
return;
}

angle = Vector3f.angle(b, c) * 180d / Math.PI;
sumAngle = sumAngle + angle;
if ((angle < Threshold.collinear_angle_minimum || angle > Threshold.collinear_angle_maximum) && !allowInvalidShapes) {
linkedDatFile.setObjVertex3(null);
linkedDatFile.setObjVertex4(null);
return;
}

a.negate();
b.negate();
angle = Vector3f.angle(a, b) * 180d / Math.PI;
sumAngle = sumAngle + angle;
if ((angle < Threshold.collinear_angle_minimum || angle > Threshold.collinear_angle_maximum) && !allowInvalidShapes) {
linkedDatFile.setObjVertex3(null);
linkedDatFile.setObjVertex4(null);
return;
}

angle = 360.0 - sumAngle;
if ((angle < Threshold.collinear_angle_minimum || angle > Threshold.collinear_angle_maximum) && !allowInvalidShapes) {
linkedDatFile.setObjVertex3(null);
linkedDatFile.setObjVertex4(null);
return;
Expand Down
94 changes: 60 additions & 34 deletions src/org/nschmidt/ldparteditor/data/VM04Rectifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -207,26 +207,39 @@ public void run(final IProgressMonitor monitor) throws InvocationTargetException
// Concave
continue;
}

angle = Vector3d.angle(normals[0], normals[2]);
if (angle > targetAngle) continue;

Vector3d A = Vector3d.sub(vertexB, vertexA);
Vector3d B = Vector3d.sub(vertexB, vertexC);
Vector3d C = Vector3d.sub(vertexD, vertexC);
Vector3d D = Vector3d.sub(vertexD, vertexA);

Vector3d.sub(vertexA, vertexD, vertexA);
Vector3d.sub(vertexB, vertexD, vertexB);
Vector3d.sub(vertexC, vertexD, vertexC);

boolean parseError = false;
angle = Vector3d.angle(vertexA, vertexB); // AB
parseError = angle < Threshold.collinear_angle_minimum;
angle = Vector3d.angle(vertexB, vertexC); // BC
parseError = parseError || angle < Threshold.collinear_angle_minimum;
angle = 180.0 - Vector3d.angle(vertexA, vertexC); // 180 - AC
parseError = parseError || angle < Threshold.collinear_angle_minimum;
angle = 180.0 - Vector3d.angle(Vector3d.sub(vertexC, vertexB), Vector3d.sub(vertexA, vertexB)); // 180 - (C-B)(A-B)
parseError = parseError || angle < Threshold.collinear_angle_minimum;
if (parseError) {
angle = Vector3d.angle(A, D);
double sumAngle = angle;
if (angle < Threshold.collinear_angle_minimum || angle > Threshold.collinear_angle_maximum) {
continue;
}

angle = Vector3d.angle(B, C);
sumAngle = sumAngle + angle;
if (angle < Threshold.collinear_angle_minimum || angle > Threshold.collinear_angle_maximum) {
continue;
}

A.negate();
B.negate();
angle = Vector3d.angle(A, B);
sumAngle = sumAngle + angle;
if (angle < Threshold.collinear_angle_minimum || angle > Threshold.collinear_angle_maximum) {
continue;
}

angle = 360.0 - sumAngle;
if (angle < Threshold.collinear_angle_minimum || angle > Threshold.collinear_angle_maximum) {
continue;
}

angle = Vector3d.angle(normals[0], normals[2]);
if (angle > targetAngle) continue;

BigDecimal m1 = Vector3d.distSquare(new Vector3d(first), new Vector3d(third)).add(BigDecimal.ONE);
BigDecimal m2 = Vector3d.distSquare(new Vector3d(second), new Vector3d(fourth)).add(BigDecimal.ONE);
Expand Down Expand Up @@ -685,25 +698,38 @@ public void run(final IProgressMonitor monitor) throws InvocationTargetException
continue;
}

Vector3d.sub(vertexA, vertexD, vertexA);
Vector3d.sub(vertexB, vertexD, vertexB);
Vector3d.sub(vertexC, vertexD, vertexC);

boolean parseError = false;
angle = Vector3d.angle(vertexA, vertexB); // AB
parseError = angle < Threshold.collinear_angle_minimum;
angle = Vector3d.angle(vertexB, vertexC); // BC
parseError = parseError || angle < Threshold.collinear_angle_minimum;
angle = 180.0 - Vector3d.angle(vertexA, vertexC); // 180 - AC
parseError = parseError || angle < Threshold.collinear_angle_minimum;
angle = 180.0 - Vector3d.angle(Vector3d.sub(vertexC, vertexB), Vector3d.sub(vertexA, vertexB)); // 180 - (C-B)(A-B)
parseError = parseError || angle < Threshold.collinear_angle_minimum;
if (parseError) {
continue;
}

angle = Vector3d.angle(normals[0], normals[2]);
if (angle > targetAngle) continue;

Vector3d A = Vector3d.sub(vertexB, vertexA);
Vector3d B = Vector3d.sub(vertexB, vertexC);
Vector3d C = Vector3d.sub(vertexD, vertexC);
Vector3d D = Vector3d.sub(vertexD, vertexA);

angle = Vector3d.angle(A, D);
double sumAngle = angle;
if (angle < Threshold.collinear_angle_minimum || angle > Threshold.collinear_angle_maximum) {
continue;
}

angle = Vector3d.angle(B, C);
sumAngle = sumAngle + angle;
if (angle < Threshold.collinear_angle_minimum || angle > Threshold.collinear_angle_maximum) {
continue;
}

A.negate();
B.negate();
angle = Vector3d.angle(A, B);
sumAngle = sumAngle + angle;
if (angle < Threshold.collinear_angle_minimum || angle > Threshold.collinear_angle_maximum) {
continue;
}

angle = 360.0 - sumAngle;
if (angle < Threshold.collinear_angle_minimum || angle > Threshold.collinear_angle_maximum) {
continue;
}

BigDecimal m1 = Vector3d.distSquare(new Vector3d(first), new Vector3d(third)).add(BigDecimal.ONE);
BigDecimal m2 = Vector3d.distSquare(new Vector3d(second), new Vector3d(fourth)).add(BigDecimal.ONE);
Expand Down
Loading

0 comments on commit 1b254bc

Please sign in to comment.