diff --git a/common/src/app/common/svg/path/Parser.java b/common/src/app/common/svg/path/Parser.java
index cfceaf944..dec9ff00f 100644
--- a/common/src/app/common/svg/path/Parser.java
+++ b/common/src/app/common/svg/path/Parser.java
@@ -1,3 +1,11 @@
+/**
+ * Performance focused pure java implementation of the
+ * SVG path parser.
+ *
+ * @author KALEIDOS INC
+ * @license MPL-2.0
+ */
+
package app.common.svg.path;
import java.util.Arrays;
@@ -61,9 +69,11 @@ public class Parser {
command = MOVE_TO;
params = new Object[] {K_X, this.params[0], K_Y, this.params[1]};
break;
+
case 'Z':
command = CLOSE_PATH;
break;
+
case 'L':
command = LINE_TO;
params = new Object[] {K_X, this.params[0], K_Y, this.params[1]};
@@ -781,16 +791,6 @@ public class Parser {
var segments = arcToBeziers(currentX, currentY, x, y, fa, fs, rx, ry, phi);
result.addAll(segments);
-
- // if (rx == 0 || ry == 0) {
- // segment.command = 'C';
- // segment.params = new double[] {currentX, currentY, x, y, x, y};
- // result.add(segment);
- // } else if (currentX != x || currentY != y) {
- // var segments = arcToBeziers(currentX, currentY, x, y, fa, fs, rx, ry, phi);
- // result.addAll(segments);
- // }
-
currentX = x;
currentY = y;
@@ -871,7 +871,6 @@ public class Parser {
}
private static void processCurve(double[] curve, double cx, double cy, double rx, double ry, double sinPhi, double cosPhi) {
-
double x0 = curve[0] * rx;
double y0 = curve[1] * ry;
double x1 = curve[2] * rx;
@@ -911,7 +910,13 @@ public class Parser {
double x1p = ((cosPhi * (x1 - x2)) / 2) + ((sinPhi * (y1 - y2)) / 2);
double y1p = ((-sinPhi * (x1 - x2)) / 2) + ((cosPhi * (y1 - y2)) / 2);
- if (x1p == 0 || y1p == 0 || rx == 0 || ry == 0) {
+ if (x1p == 0 && y1p == 0) {
+ // we're asked to draw line to itself
+ return new ArrayList<>();
+ }
+
+ if (rx == 0 || ry == 0) {
+ // one of the radii is zero
return new ArrayList<>();
}
diff --git a/common/src/app/common/svg/path/parser.js b/common/src/app/common/svg/path/parser.js
index d156d6ca2..804112f07 100644
--- a/common/src/app/common/svg/path/parser.js
+++ b/common/src/app/common/svg/path/parser.js
@@ -1,3 +1,11 @@
+/**
+ * Performance focused pure javascript implementation of the
+ * SVG path parser.
+ *
+ * @author KALEIDOS INC
+ * @license MPL-2.0
+ */
+
import cljs from "goog:cljs.core";
const MOVE_TO = cljs.keyword("move-to");
@@ -674,7 +682,13 @@ export function arcToBeziers(x1, y1, x2, y2, fa, fs, rx, ry, phi) {
let x1p = (cosPhi * (x1 - x2)) / 2 + (sinPhi * (y1 - y2)) / 2;
let y1p = (-sinPhi * (x1 - x2)) / 2 + (cosPhi * (y1 - y2)) / 2;
- if (x1p === 0 || y1p === 0 || rx === 0 || ry === 0) {
+ if (x1p === 0 && y1p === 0) {
+ // we're asked to draw line to itself
+ return [];
+ }
+
+ if (rx === 0 || ry === 0) {
+ // one of the radii is zero
return [];
}
@@ -877,6 +891,7 @@ function simplifyPathData(pdata) {
currentX = x;
currentY = y;
} else if (currentX !== x || currentY !== y) {
+
var segments = arcToBeziers(currentX, currentY, x, y, fa, fs, rx, ry, phi);
result.push(...segments);
diff --git a/common/target/classes/app/common/svg/path/Parser$ParserImpl.class b/common/target/classes/app/common/svg/path/Parser$ParserImpl.class
index eb42edaca..e146fff62 100644
Binary files a/common/target/classes/app/common/svg/path/Parser$ParserImpl.class and b/common/target/classes/app/common/svg/path/Parser$ParserImpl.class differ
diff --git a/common/target/classes/app/common/svg/path/Parser$Segment.class b/common/target/classes/app/common/svg/path/Parser$Segment.class
index 646d3b803..29c2be111 100644
Binary files a/common/target/classes/app/common/svg/path/Parser$Segment.class and b/common/target/classes/app/common/svg/path/Parser$Segment.class differ
diff --git a/common/target/classes/app/common/svg/path/Parser.class b/common/target/classes/app/common/svg/path/Parser.class
index 13d8402cf..351b04b77 100644
Binary files a/common/target/classes/app/common/svg/path/Parser.class and b/common/target/classes/app/common/svg/path/Parser.class differ