🚧 Pre work on offsets
This commit is contained in:
parent
f14ebb1e87
commit
be4e759c1a
5 changed files with 991 additions and 953 deletions
1898
package-lock.json
generated
1898
package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
@ -12,5 +12,7 @@ export default {
|
|||
point,
|
||||
path,
|
||||
snippet,
|
||||
utils
|
||||
utils,
|
||||
patterns: {},
|
||||
plugins: {}
|
||||
};
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import attributes from "./attributes";
|
||||
import { pathOffset } from "./utils";
|
||||
|
||||
function path() {
|
||||
this.render = true;
|
||||
|
@ -69,4 +70,12 @@ path.prototype.asPathstring = function() {
|
|||
return d;
|
||||
};
|
||||
|
||||
/** Returns this path as a Bezier object */
|
||||
path.prototype.asBezier = function() {};
|
||||
|
||||
/** Returns offset of this path as a new path */
|
||||
path.prototype.offset = function(distance) {
|
||||
return pathOffset(this, distance);
|
||||
};
|
||||
|
||||
export default path;
|
||||
|
|
|
@ -106,9 +106,7 @@ pattern.prototype.loadPluginHooks = function(plugin) {
|
|||
|
||||
pattern.prototype.loadPluginMacros = function(plugin) {
|
||||
for (let macro in plugin.macros) {
|
||||
console.log("loading ", macro);
|
||||
if (typeof plugin.macros[macro] === "function") {
|
||||
console.log(macro, "is a function");
|
||||
this.macro(macro, plugin.macros[macro]);
|
||||
}
|
||||
}
|
||||
|
@ -118,7 +116,6 @@ pattern.prototype.macro = function(key, method) {
|
|||
let name = macroName(key);
|
||||
this.on(name, method);
|
||||
for (let partId in this.parts) {
|
||||
console.log(`Attaching macro ${name} to part ${partId}`);
|
||||
let part = this.parts[partId];
|
||||
part[name] = () => null;
|
||||
this.hooks.attach(name, part);
|
||||
|
|
30
src/utils.js
30
src/utils.js
|
@ -79,3 +79,33 @@ export function shorthand(part) {
|
|||
paperless
|
||||
};
|
||||
}
|
||||
/** Offsets a line by distance */
|
||||
export function offsetLine(from, to, distance) {
|
||||
if (from.x === to.x && from.y === to.y) {
|
||||
throw "Cannot offset line that starts and ends in the same point";
|
||||
}
|
||||
|
||||
let angle = from.angle(to) + 90;
|
||||
console.log("offsetting line from", from, "to", to, "angle is", angle);
|
||||
return {
|
||||
from: from.shift(angle, distance),
|
||||
to: to.shift(angle, distance)
|
||||
};
|
||||
}
|
||||
|
||||
/** Offsets a path by distance */
|
||||
export function pathOffset(path, distance) {
|
||||
let offset = [];
|
||||
let current;
|
||||
for (let i in path.ops) {
|
||||
let op = path.ops[i];
|
||||
if (op.type === "line") {
|
||||
offset.push(offsetLine(current, op.to, distance));
|
||||
} else if (op.type === "curve") {
|
||||
//offset.push(utils.offsetLine(current, op.to);
|
||||
}
|
||||
current = op.to;
|
||||
}
|
||||
//let orig = new Bezier(
|
||||
console.log(offset);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue