#2165 Tweak round values in shape fixer

This commit is contained in:
Jindra Petřík
2025-09-28 11:18:23 +02:00
parent 1e126a476d
commit 8afe8c29d5
3 changed files with 31 additions and 15 deletions

View File

@@ -578,7 +578,7 @@ public class BezierEdge implements Serializable {
));
}
calcParams();
}
}
public static final double ROUND_VALUE = 2;
@@ -591,6 +591,16 @@ public class BezierEdge implements Serializable {
}
calcParams();
}
public void roundN(double n) {
for (int i = 0; i < this.points.size(); i++) {
this.points.set(i, new Point2D.Double(
Math.round(this.points.get(i).getX() * n) / n,
Math.round(this.points.get(i).getY() * n) / n
));
}
calcParams();
}
@Override
public int hashCode() {

View File

@@ -252,7 +252,7 @@ public class XFLConverter {
*/
private final boolean DEBUG_EXPORT_LAYER_DEPTHS = false;
private static final DecimalFormat EDGE_DECIMAL_FORMAT = new DecimalFormat("0.#", DecimalFormatSymbols.getInstance(Locale.ENGLISH));
private static final DecimalFormat EDGE_DECIMAL_FORMAT = new DecimalFormat("0.##", DecimalFormatSymbols.getInstance(Locale.ENGLISH));
private static final double SMALL_DIVISOR = 20;
@@ -308,12 +308,12 @@ public class XFLConverter {
}
private static String formatEdgeDouble(double value) {
if (value % 1 == 0) {
/*if (value % 1 == 0) {
return "" + (int) value;
}
}*/
//value = Math.round(value * 2.0) / 2.0;
return EDGE_DECIMAL_FORMAT.format(value);
//return numEdgeToString(value);
//return EDGE_DECIMAL_FORMAT.format(value);
return numEdgeToString(value);
}
private static String convertShapeEdge(MATRIX mat, ShapeRecordAdvanced record, double x, double y) {
@@ -715,7 +715,7 @@ public class XFLConverter {
shapeTransformer.transformStyles(scale, fillStyles, lineStyles, shapeNum);
}
shapeRecordsAdvanced = fixer.fix(shapeRecords, shapeNum, fillStyles, lineStyles);
shapeRecordsAdvanced = fixer.fix(shapeRecords, shapeNum, fillStyles, lineStyles, small);
List<ShapeRecordAdvanced> edges = new ArrayList<>();
int lineStyleCount = 0;

View File

@@ -253,7 +253,7 @@ public class ShapeFixer {
}
}
private void handleBewList(List<BezierEdgeWrapper> bewList, List<List<BezierEdge>> shapes) {
private void handleBewList(List<BezierEdgeWrapper> bewList, List<List<BezierEdge>> shapes, boolean wasSmall) {
Map<Integer, List<BezierEdgeWrapper>> bewMap = bewList.stream()
.collect(Collectors.groupingBy(b -> b.layer));
@@ -368,7 +368,11 @@ public class ShapeFixer {
shapes.get(bew.shapeIndex).remove(bew.edgeIndex);
int pos = 0;
for (BezierEdge bes : splitted) {
bes.roundX();
if (wasSmall) {
bes.roundN(2); //this value works best for #1011, why? Also for #2532 it is okay.
} else {
bes.roundN(100); //this value works best for #2165, it's not multiplied by 20 like not small :-(
}
if (bes.isEmpty()) {
continue;
}
@@ -384,7 +388,8 @@ public class ShapeFixer {
List<Integer> fillStyles0,
List<Integer> fillStyles1,
List<Integer> lineStyles,
List<Integer> layers
List<Integer> layers,
boolean wasSmall
) {
/*if (true) {
@@ -412,8 +417,8 @@ public class ShapeFixer {
}
}
handleBewList(strokesBewList, shapes);
handleBewList(fillsBewList, shapes);
handleBewList(strokesBewList, shapes, wasSmall);
handleBewList(fillsBewList, shapes, wasSmall);
for (int i1 = 0; i1 < shapes.size(); i1++) {
for (int j1 = 0; j1 < shapes.get(i1).size(); j1++) {
@@ -848,7 +853,8 @@ public class ShapeFixer {
List<SHAPERECORD> records,
int shapeNum,
FILLSTYLEARRAY baseFillStyles,
LINESTYLEARRAY baseLineStyles
LINESTYLEARRAY baseLineStyles,
boolean wasSmall
) {
List<List<BezierEdge>> shapes = new ArrayList<>();
List<Integer> fillStyles0 = new ArrayList<>();
@@ -865,7 +871,7 @@ public class ShapeFixer {
if (Configuration.flaExportFixShapes.get()) {
SwitchedFillSidesFixer switchedFillSidesFixer = new SwitchedFillSidesFixer();
switchedFillSidesFixer.fixSwitchedFills(shapeNum, records, baseFillStyles, baseLineStyles, shapes, fillStyles0, fillStyles1, layers);
detectOverlappingEdges(shapes, fillStyles0, fillStyles1, lineStyles, layers);
detectOverlappingEdges(shapes, fillStyles0, fillStyles1, lineStyles, layers, wasSmall);
}
return combineLayers(shapes, fillStyles0, fillStyles1, lineStyles, layers, fillStyleLayers, lineStyleLayers);
@@ -919,6 +925,6 @@ public class ShapeFixer {
beList.add(new BezierEdge(10000.0, 4980.0, 10040.0, 5060.0));
beList.add(new BezierEdge(10040.0, 5040.0, 9900.0, 4900.0, 9900.0, 4860.0));
shapes.add(beList);
f.detectOverlappingEdges(shapes, Arrays.asList(1), Arrays.asList(2), Arrays.asList(0), Arrays.asList(0));
f.detectOverlappingEdges(shapes, Arrays.asList(1), Arrays.asList(2), Arrays.asList(0), Arrays.asList(0), false);
}
}