2018-12-21 16:57:10 +01:00
|
|
|
import { name, version } from "../package.json";
|
|
|
|
|
|
|
|
export default {
|
|
|
|
name: name,
|
|
|
|
version: version,
|
|
|
|
hooks: {
|
|
|
|
preRender: function(svg) {
|
|
|
|
if (svg.attributes.get("freesewing:plugin-round") === false)
|
|
|
|
svg.attributes.set("freesewing:plugin-round", version);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
macros: {
|
|
|
|
round: function(so) {
|
|
|
|
const C = 0.55191502449;
|
|
|
|
// Find angle between points
|
|
|
|
let from = so.from;
|
|
|
|
let to = so.to;
|
|
|
|
let via = so.via;
|
|
|
|
let radius = so.radius;
|
|
|
|
let prefix = so.prefix;
|
|
|
|
let angle1 = from.angle(via);
|
|
|
|
let angle2 = via.angle(to);
|
2019-05-10 13:14:31 +02:00
|
|
|
if ((Math.round(angle1) - Math.round(angle2)) % 90 !== 0)
|
2019-05-31 18:07:01 +02:00
|
|
|
console.log(
|
|
|
|
"Warning: The round macro only handles 90 degree angles correctly."
|
2019-05-10 13:14:31 +02:00
|
|
|
);
|
2018-12-21 16:57:10 +01:00
|
|
|
let fd = from.dist(via);
|
|
|
|
let td = to.dist(via);
|
2019-05-10 13:14:31 +02:00
|
|
|
if (radius > fd || radius > td || typeof radius === "undefined")
|
2018-12-21 16:57:10 +01:00
|
|
|
radius = fd > td ? td : fd;
|
2019-05-10 13:14:31 +02:00
|
|
|
this.points[prefix + "Start"] = via.shiftTowards(from, radius);
|
|
|
|
this.points[prefix + "Cp1"] = via.shiftTowards(from, radius * (1 - C));
|
|
|
|
this.points[prefix + "Cp2"] = via.shiftTowards(to, radius * (1 - C));
|
|
|
|
this.points[prefix + "End"] = via.shiftTowards(to, radius);
|
|
|
|
this.paths[prefix + "Rounded"] = new this.Path()
|
|
|
|
.move(this.points[prefix + "Start"])
|
2018-12-21 16:57:10 +01:00
|
|
|
.curve(
|
2019-05-10 13:14:31 +02:00
|
|
|
this.points[prefix + "Cp1"],
|
|
|
|
this.points[prefix + "Cp2"],
|
|
|
|
this.points[prefix + "End"]
|
2018-12-21 16:57:10 +01:00
|
|
|
)
|
|
|
|
.attr("class", so.class ? so.class : "");
|
2019-05-10 13:14:31 +02:00
|
|
|
if (typeof so.render !== "undefined" && so.render)
|
|
|
|
this.paths[prefix + "Rounded"].render = true;
|
|
|
|
else this.paths[prefix + "Rounded"].render = false;
|
2018-12-21 16:57:10 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|