Skip to content

Commit

Permalink
Prepared fix for issue #1039.
Browse files Browse the repository at this point in the history
  • Loading branch information
nilsschmidt1337 committed Aug 15, 2024
1 parent 6f965c5 commit 7ea24f0
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
31 changes: 26 additions & 5 deletions src/org/nschmidt/ldparteditor/dialog/primgen2/PrimGen2Dialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ public class PrimGen2Dialog extends PrimGen2Design {
public static final int CYLINDER_WITHOUT_CONDLINES = -4;
public static final int CYLINDER_SLOPED = -5;
public static final int CYLINDER_SLOPED_CONVEX = -6;
public static final int EIGHT_SPHERE = -7;
public static final int CYLINDER_SLOPED_HELICAL = -7;
public static final int EIGHT_SPHERE = -8;
public static final int DISC = 5;
public static final int DISC_NEGATIVE = 6;
public static final int DISC_NEGATIVE_TRUNCATED = 7;
Expand Down Expand Up @@ -725,15 +726,23 @@ public static String buildPrimitiveSource(int pType, int divisions, int segments
sb.insert(0, "0 Name: " + prefix + name + "\n"); //$NON-NLS-1$ //$NON-NLS-2$
sb.insert(0, "0 " + resolution + "Cylinder Sloped " + removeTrailingZeros2(decformat4f.format(segments * 1d / divisions)) + " Convex\n"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$

sb.append(cylinderSloped(divisions, segments, ccw, true));
sb.append(cylinderSloped(divisions, segments, ccw, true, false));

break;
case CYLINDER_SLOPED_HELICAL:
name = upper + "-" + lower + "cylh.dat"; //$NON-NLS-1$ //$NON-NLS-2$
sb.insert(0, "0 Name: " + prefix + name + "\n"); //$NON-NLS-1$ //$NON-NLS-2$
sb.insert(0, "0 " + resolution + "Cylinder Helical " + removeTrailingZeros2(decformat4f.format(segments * 1d / divisions)) + "\n"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$

sb.append(cylinderSloped(divisions, segments, ccw, false, true));

break;
case CYLINDER_SLOPED:
name = upper + "-" + lower + "cyls.dat"; //$NON-NLS-1$ //$NON-NLS-2$
sb.insert(0, "0 Name: " + prefix + name + "\n"); //$NON-NLS-1$ //$NON-NLS-2$
sb.insert(0, "0 " + resolution + "Cylinder Sloped " + removeTrailingZeros2(decformat4f.format(segments * 1d / divisions)) + "\n"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$

sb.append(cylinderSloped(divisions, segments, ccw, false));
sb.append(cylinderSloped(divisions, segments, ccw, false, false));

break;
case DISC:
Expand Down Expand Up @@ -1113,7 +1122,7 @@ else if (num == 0)
}


private static Object cylinderSloped(int divisions, int segments, boolean ccw, boolean convex) {
private static Object cylinderSloped(int divisions, int segments, boolean ccw, boolean convex, boolean helical) {

// Crazy Reverse Engineering from Mike's PrimGen2
// Thanks to Mr. Heidemann! :)
Expand Down Expand Up @@ -1155,6 +1164,11 @@ private static Object cylinderSloped(int divisions, int segments, boolean ccw, b
objdatLinePoint4Y = 1.0 - objdatLinePoint4Y;
}

if (helical) {
objdatLinePoint3Y = (num / (divisions / 4.0));
objdatLinePoint4Y = ((num + 1) / (divisions / 4.0));
}

sb2.append("4 16 "); //$NON-NLS-1$
if (ccw ^ convex) {
sb2.append(removeTrailingZeros(formatDec(objdatLinePoint1X)));
Expand Down Expand Up @@ -1249,6 +1263,13 @@ else if (num == 0)
objdatLinePoint3Y = 0.0;
objdatLinePoint4Y = 0.0;
}

if (helical) {
objdatLinePoint2Y = (num / (divisions / 4.0));
objdatLinePoint3Y = 0.0;
objdatLinePoint4Y = 0.0;
}

sb2.append("5 24 "); //$NON-NLS-1$
sb2.append(removeTrailingZeros(formatDec(objdatLinePoint1X)));
sb2.append(" " + removeTrailingZeros(formatDec(objdatLinePoint1Y)) + " "); //$NON-NLS-1$ //$NON-NLS-2$
Expand Down Expand Up @@ -2501,7 +2522,7 @@ private boolean isOfficialRules(int typ, double size, double divisions, double s
}
switch (typ)
{
case CIRCLE, CYLINDER, CYLINDER_WITHOUT_CONDLINES, CYLINDER_SLOPED, CYLINDER_SLOPED_CONVEX
case CIRCLE, CYLINDER, CYLINDER_WITHOUT_CONDLINES, CYLINDER_SLOPED, CYLINDER_SLOPED_CONVEX, CYLINDER_SLOPED_HELICAL
, DISC, DISC_NEGATIVE, CHORD, TANGENTIAL_RING_SEGMENT:
return true;
case DISC_NEGATIVE_TRUNCATED:
Expand Down
4 changes: 4 additions & 0 deletions src/org/nschmidt/ldparteditor/text/PrimitiveReplacer.java
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,10 @@ private static List<String> substituteSimplePrimitivesWithFraction(String name,
return buildPrimitive(PrimGen2Dialog.CYLINDER_SLOPED_CONVEX, quality, segments);
}

if ("cylh".equals(name)) { //$NON-NLS-1$
return buildPrimitive(PrimGen2Dialog.CYLINDER_SLOPED_HELICAL, quality, segments);
}

// Substitute circular disc segments
if ("chrd".equals(name)) { //$NON-NLS-1$
return buildPrimitive(PrimGen2Dialog.CHORD, quality, segments);
Expand Down
5 changes: 5 additions & 0 deletions test/primitive_substitution.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,8 @@

1 44 -5.56 -1.48 7.05 1 0 0 0 1 0 0 0 1 48\1-8sphe.dat
1 7 -5.56 -1.48 7.05 .9 0 0 0 .9 0 0 0 .9 8-8sphe.dat

1 7 -7.56 -1.48 7.05 1 0 0 0 1 0 0 0 1 1-8sphc.dat

1 8 -9.56 -1.48 7.05 1 0 0 0 1 0 0 0 1 1-4edgh.dat
1 9 -11.56 -1.48 7.05 1 0 0 0 1 0 0 0 1 1-4cylh.dat

0 comments on commit 7ea24f0

Please sign in to comment.