Skip to content

Commit

Permalink
Merge pull request #3864 from kwvanderlinde/bugfix/3763-topology-poin…
Browse files Browse the repository at this point in the history
…t-rounding

Stop rounding *BL points
  • Loading branch information
Phergus authored Mar 16, 2023
2 parents fa0ee20 + 55975fc commit 471b084
Showing 1 changed file with 30 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -732,8 +732,8 @@ private Area makePolygon(JsonObject topologyObject, String funcname) throws Pars
I18N.getText("macro.function.json.getInvalidEndIndex", funcname, 2, points.size()));
}
// Optional Parameters
int fill = getJSONint(topologyObject, "fill", funcname);
int close = getJSONint(topologyObject, "close", funcname);
boolean close = 0 != getJSONint(topologyObject, "close", funcname);
boolean fill = close && 0 != getJSONint(topologyObject, "fill", funcname);
double r = getJSONdouble(topologyObject, "r", funcname);
double facing = getJSONdouble(topologyObject, "facing", funcname);
float t = (float) getJSONdouble(topologyObject, "thickness", funcname);
Expand All @@ -745,63 +745,43 @@ private Area makePolygon(JsonObject topologyObject, String funcname) throws Pars

Area area = null;

if (close == 0) {
// User requests for polygon to not be closed, so a Path is used
Path2D path = new Path2D.Double();
double lastX = 0;
double lastY = 0;
Path2D path = new Path2D.Double();
double lastX = 0;
double lastY = 0;

for (int i = 0; i < points.size(); i++) {
JsonObject point = points.get(i).getAsJsonObject();
String[] requiredPointParms = {"x", "y"};
for (int i = 0; i < points.size(); i++) {
JsonObject point = points.get(i).getAsJsonObject();

String requiredPointParms[] = {"x", "y"};
if (!jsonKeysExist(point, requiredPointParms, funcname)) {
throw new ParserException(
I18N.getText("macro.function.general.argumentKeyTypeI", funcname, "{x,y}"));
}
if (!jsonKeysExist(point, requiredPointParms, funcname)) {
throw new ParserException(
I18N.getText("macro.function.general.argumentKeyTypeI", funcname, "{x,y}"));
}

double x = getJSONdouble(point, "x", funcname);
double y = getJSONdouble(point, "y", funcname);
double x = getJSONdouble(point, "x", funcname);
double y = getJSONdouble(point, "y", funcname);

if (path.getCurrentPoint() == null) {
path.moveTo(x, y);
} else if (!(lastX == x && lastY == y)) {
path.lineTo(x, y);
lastX = x;
lastY = y;
}
if (path.getCurrentPoint() == null) {
path.moveTo(x, y);
} else if (!(lastX == x && lastY == y)) {
path.lineTo(x, y);
lastX = x;
lastY = y;
}
}

if (close) {
path.closePath();
}
if (fill) {
area = new Area(path);
} else {
// A strokedShape will not be filled in and have a defined thickness.
BasicStroke stroke =
new BasicStroke(Math.max(t, 0f), BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER);
area = new Area(stroke.createStrokedShape(path));
} else {
// User requests for polygon to be closed, so a Polygon is used which is automatically
// closed
Polygon poly = new Polygon();

for (int i = 0; i < points.size(); i++) {
JsonObject point = points.get(i).getAsJsonObject();

String requiredPointParms[] = {"x", "y"};
if (!jsonKeysExist(point, requiredPointParms, funcname)) {
throw new ParserException(
I18N.getText("macro.function.general.argumentKeyTypeI", funcname, "{x,y}"));
}

int x = getJSONint(point, "x", funcname);
int y = getJSONint(point, "y", funcname);

poly.addPoint(x, y);
}
// A strokedShape will not be filled in and have a defined thickness.
if (fill == 0) {
BasicStroke stroke =
new BasicStroke(Math.max(t, 0f), BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER);
area = new Area(stroke.createStrokedShape(poly));
} else {
area = new Area(poly);
}
}

AffineTransform atArea = new AffineTransform();
applyTranslate(funcname, atArea, topologyObject, paramTranslate);

Expand Down Expand Up @@ -1198,10 +1178,6 @@ private void consumeAreaPoints(Area area, BiConsumer<Double, Double> pointConsum
double[] moveTo = null;

for (double[] currentElement : areaPoints) {
// 2 decimals is precise enough, we will deal in .5 pixels mostly.
currentElement[1] = Math.floor(currentElement[1] * 100) / 100;
currentElement[2] = Math.floor(currentElement[2] * 100) / 100;

// Make the lines
if (currentElement[0] == PathIterator.SEG_MOVETO) {
if (defaultPos == null) {
Expand Down

0 comments on commit 471b084

Please sign in to comment.