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 10, 2024
1 parent 3ca3c25 commit 1ca2fe4
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ protected Control createDialogArea(Composite parent) {

Combo cmbType = Theming.combo(cmpContainer, SWT.READ_ONLY);
this.cmbTypePtr[0] = cmbType;
widgetUtil(cmbType).setItems(I18n.PRIMGEN_CIRCLE, I18n.PRIMGEN_RING, I18n.PRIMGEN_CONE, I18n.PRIMGEN_TORUS, I18n.PRIMGEN_CYLINDER, I18n.PRIMGEN_DISC, I18n.PRIMGEN_DISC_NEGATIVE, I18n.PRIMGEN_DISC_NEGATIVE_TRUNCATED, I18n.PRIMGEN_CHORD);
widgetUtil(cmbType).setItems(I18n.PRIMGEN_CIRCLE, I18n.PRIMGEN_RING, I18n.PRIMGEN_CONE, I18n.PRIMGEN_TORUS, I18n.PRIMGEN_CYLINDER, I18n.PRIMGEN_DISC, I18n.PRIMGEN_DISC_NEGATIVE, I18n.PRIMGEN_DISC_NEGATIVE_TRUNCATED, I18n.PRIMGEN_CHORD, I18n.PRIMGEN_TANGENTIAL_RING_SEGMENT);
cmbType.setText(I18n.PRIMGEN_CIRCLE);
cmbType.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 2, 1));

Expand Down
63 changes: 61 additions & 2 deletions src/org/nschmidt/ldparteditor/dialog/primgen2/PrimGen2Dialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public class PrimGen2Dialog extends PrimGen2Design {
public static final int DISC_NEGATIVE = 6;
public static final int DISC_NEGATIVE_TRUNCATED = 7;
public static final int CHORD = 8;
public static final int TANGENTIAL_RING_SEGMENT = 9;

private boolean doUpdate = false;
private boolean ok = false;
Expand Down Expand Up @@ -269,7 +270,7 @@ public int open() {
doUpdate = true;

switch (cmbTypePtr[0].getSelectionIndex()) {
case CIRCLE, CYLINDER, DISC, DISC_NEGATIVE, DISC_NEGATIVE_TRUNCATED, CHORD:
case CIRCLE, CYLINDER, DISC, DISC_NEGATIVE, DISC_NEGATIVE_TRUNCATED, CHORD, TANGENTIAL_RING_SEGMENT:
lblMinorPtr[0].setText(I18n.PRIMGEN_MINOR);
lblMajorPtr[0].setEnabled(false);
lblMinorPtr[0].setEnabled(false);
Expand Down Expand Up @@ -864,6 +865,64 @@ public static String buildPrimitiveSource(int pType, int divisions, int segments
}
}

break;
case TANGENTIAL_RING_SEGMENT:
name = upper + "-" + lower + "tang.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 + "Disc Negative Tangent " + removeTrailingZeros2(decformat4f.format(segments * 1d / divisions)) + "\n"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$

{
// its always 16, there is no hi-res outer tangent (48\3-16tang.dat and 3-16tang.dat are used to pad a 16-sided polygon!)
int tangentStep = divisions / 16;
double deltaAngle = Math.PI * 2d / divisions;
double deltaAngleTangent = Math.PI / 16.0;
double scale = 1.0 / Math.cos(deltaAngleTangent);
double angle = 0d;
double angleTangent = -deltaAngleTangent;
for(int i = 0; i < segments; i++) {
double nextAngle = angle + deltaAngle;
double x1 = Math.cos(angle);
double z1 = Math.sin(angle);
double x2 = Math.cos(nextAngle);
double z2 = Math.sin(nextAngle);
if (i % tangentStep == 0) {
angleTangent = angleTangent + deltaAngleTangent * 2d;
}
double x3 = Math.cos(angleTangent) * scale;
double z3 = Math.sin(angleTangent) * scale;
if (ccw) {
sb.append("3 16 "); //$NON-NLS-1$
sb.append(removeTrailingZeros(decformat4f.format(x2)));
sb.append(" 0 "); //$NON-NLS-1$
sb.append(removeTrailingZeros(decformat4f.format(z2)));
sb.append(" "); //$NON-NLS-1$
sb.append(removeTrailingZeros(decformat4f.format(x1)));
sb.append(" 0 "); //$NON-NLS-1$
sb.append(removeTrailingZeros(decformat4f.format(z1)));
sb.append(" "); //$NON-NLS-1$
sb.append(removeTrailingZeros(decformat4f.format(x3)));
sb.append(" 0 "); //$NON-NLS-1$
sb.append(removeTrailingZeros(decformat4f.format(z3)));
} else {
sb.append("3 16 "); //$NON-NLS-1$
sb.append(removeTrailingZeros(decformat4f.format(x3)));
sb.append(" 0 "); //$NON-NLS-1$
sb.append(removeTrailingZeros(decformat4f.format(z3)));
sb.append(" "); //$NON-NLS-1$
sb.append(removeTrailingZeros(decformat4f.format(x1)));
sb.append(" 0 "); //$NON-NLS-1$
sb.append(removeTrailingZeros(decformat4f.format(z1)));
sb.append(" "); //$NON-NLS-1$
sb.append(removeTrailingZeros(decformat4f.format(x2)));
sb.append(" 0 "); //$NON-NLS-1$
sb.append(removeTrailingZeros(decformat4f.format(z2)));
}

sb.append("\n"); //$NON-NLS-1$
angle = nextAngle;
}
}

break;
default:
break;
Expand Down Expand Up @@ -2239,7 +2298,7 @@ private boolean isOfficialRules(int typ, double size, double divisions, double s
}
switch (typ)
{
case CIRCLE, CYLINDER, DISC, DISC_NEGATIVE, CHORD:
case CIRCLE, CYLINDER, DISC, DISC_NEGATIVE, CHORD, TANGENTIAL_RING_SEGMENT:
return true;
case DISC_NEGATIVE_TRUNCATED:
return segments < divisions && segments > 0 && divisions / segments >= 4.0;
Expand Down
1 change: 1 addition & 0 deletions src/org/nschmidt/ldparteditor/i18n/I18n.java
Original file line number Diff line number Diff line change
Expand Up @@ -1192,6 +1192,7 @@ private static void adjust() { // Calculate line offset
public static final String PRIMGEN_SIXTEEN = PRIMGEN.getString(getProperty());
public static final String PRIMGEN_SIZE = PRIMGEN.getString(getProperty());
public static final String PRIMGEN_STANDARD = PRIMGEN.getString(getProperty());
public static final String PRIMGEN_TANGENTIAL_RING_SEGMENT = PRIMGEN.getString(getProperty());
public static final String PRIMGEN_THREE_QUARTER = PRIMGEN.getString(getProperty());
public static final String PRIMGEN_TITLE = PRIMGEN.getString(getProperty());
public static final String PRIMGEN_TORUS = PRIMGEN.getString(getProperty());
Expand Down
1 change: 1 addition & 0 deletions src/org/nschmidt/ldparteditor/i18n/PrimGen.properties
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ SEGMENTS = Segments
SIXTEEN = 16
SIZE = Size (radius)
STANDARD = STANDARD
TANGENTIAL_RING_SEGMENT = Disc Negative Tangent
THREE_QUARTER = 3-4
TITLE = Primitive Generator 2.X
TORUS = Torus
Expand Down
5 changes: 5 additions & 0 deletions src/org/nschmidt/ldparteditor/text/PrimitiveReplacer.java
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,11 @@ private static List<String> substituteSimplePrimitivesWithFraction(String name,
return buildPrimitive(PrimGen2Dialog.CHORD, quality, segments);
}

// Substitute tangential ring segments
if ("tang".equals(name)) { //$NON-NLS-1$
return buildPrimitive(PrimGen2Dialog.TANGENTIAL_RING_SEGMENT, quality, segments);
}

return List.of();
}

Expand Down
6 changes: 6 additions & 0 deletions test/primitive_substitution.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,9 @@
1 14 13.29 -2.01 6.95 1 0 0 0 1 0 0 0 1 48\tm16q0667.dat
1 9 13.58 -1.32 6.33 1 0 0 0 1 0 0 0 1 r04o3000.dat
1 10 12.66 -1.38 5.93 1 0 0 0 1 0 0 0 1 r04i1000.dat

1 16 14.56 -1.48 7.05 1 0 0 0 1 0 0 0 1 3-16tang.dat
1 16 14.56 -1.48 7.05 1 0 0 0 1 0 0 0 1 3-16disc.dat

1 16 12.56 -1.48 7.05 1 0 0 0 1 0 0 0 1 48\3-16tang.dat
1 16 12.56 -1.48 7.05 1 0 0 0 1 0 0 0 1 48\3-16disc.dat

0 comments on commit 1ca2fe4

Please sign in to comment.