1
0
Fork 0

🚧 Pre work on offsets

This commit is contained in:
joostdecock 2018-07-26 13:43:12 +00:00
parent f14ebb1e87
commit be4e759c1a
5 changed files with 991 additions and 953 deletions

1898
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -12,5 +12,7 @@ export default {
point, point,
path, path,
snippet, snippet,
utils utils,
patterns: {},
plugins: {}
}; };

View file

@ -1,4 +1,5 @@
import attributes from "./attributes"; import attributes from "./attributes";
import { pathOffset } from "./utils";
function path() { function path() {
this.render = true; this.render = true;
@ -69,4 +70,12 @@ path.prototype.asPathstring = function() {
return d; 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; export default path;

View file

@ -106,9 +106,7 @@ pattern.prototype.loadPluginHooks = function(plugin) {
pattern.prototype.loadPluginMacros = function(plugin) { pattern.prototype.loadPluginMacros = function(plugin) {
for (let macro in plugin.macros) { for (let macro in plugin.macros) {
console.log("loading ", macro);
if (typeof plugin.macros[macro] === "function") { if (typeof plugin.macros[macro] === "function") {
console.log(macro, "is a function");
this.macro(macro, plugin.macros[macro]); this.macro(macro, plugin.macros[macro]);
} }
} }
@ -118,7 +116,6 @@ pattern.prototype.macro = function(key, method) {
let name = macroName(key); let name = macroName(key);
this.on(name, method); this.on(name, method);
for (let partId in this.parts) { for (let partId in this.parts) {
console.log(`Attaching macro ${name} to part ${partId}`);
let part = this.parts[partId]; let part = this.parts[partId];
part[name] = () => null; part[name] = () => null;
this.hooks.attach(name, part); this.hooks.attach(name, part);

View file

@ -79,3 +79,33 @@ export function shorthand(part) {
paperless 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);
}