From 4f39c663815d100d3423f8f66cad35fbd1735f0b Mon Sep 17 00:00:00 2001 From: joostdecock Date: Thu, 19 Jul 2018 14:02:04 +0000 Subject: [PATCH] :construction: shorthand --- lib/decorators/point.ts | 31 ------------------------------- lib/pattern.ts | 8 ++++++++ lib/utils.ts | 24 ++++++++++++++++++++++++ 3 files changed, 32 insertions(+), 31 deletions(-) delete mode 100644 lib/decorators/point.ts diff --git a/lib/decorators/point.ts b/lib/decorators/point.ts deleted file mode 100644 index 59924447e14..00000000000 --- a/lib/decorators/point.ts +++ /dev/null @@ -1,31 +0,0 @@ -import { Point } from '../point' - -export function pointDecorator(target: any, key: string) { - - // property value - var _val: Point = this[key]; - - // property getter - var getter = function (): Point { - console.log(`Get: ${key} => ${_val}`); - return _val; - }; - - // property setter - var setter = function (newVal: Point): void { - console.log(`Set: ${key} => ${newVal}`); - _val = newVal; - }; - - // Delete property. - if (delete this[key]) { - - // Create new property with getter and setter - Object.defineProperty(target, key, { - get: getter, - set: setter, - enumerable: true, - configurable: true - }); - } -} diff --git a/lib/pattern.ts b/lib/pattern.ts index c7124f68bf4..35f66d6dab9 100644 --- a/lib/pattern.ts +++ b/lib/pattern.ts @@ -19,6 +19,7 @@ export class Pattern { hooks: Hooks; snippet: Snippet path: Path + context: any constructor(config: PatternConfig) { if(!config) { @@ -44,6 +45,13 @@ export class Pattern { else this.options[conf.id] = conf.val; } } + this.context = { + parts: this.parts, + options: this.options, + values: this.values, + config: this.config, + settings: this.settings + } return this; } diff --git a/lib/utils.ts b/lib/utils.ts index aead7071dea..4d2284ae294 100644 --- a/lib/utils.ts +++ b/lib/utils.ts @@ -60,3 +60,27 @@ export function linesCross(a1: Point, a2: Point, b1: Point, b2: Point): Point | return false; } +/** Find where an (endless) line crosses a certain Y-value */ +export function beamCrossesY(from: Point, to: Point, y: number) { + if(from.y === to.y) return false; // Horizontal line + let left = new Point(-10,y); + let right = new Point(10,y); + + return beamsCross(from, to, left, right); +} + +/** Returns an object with shorthand access for pattern design */ +export function shorthand(part, context): {} { + let final = (context.settings.mode === 'draft') ? true : false; + let paperless = (context.settings.paperless === true) ? true : false; + return { + measurements: context.settings.measurements || {}, + options: context.options || {}, + values: context.values || {}, + points: part.points || {}, + paths: part.paths || {}, + snippets: part.snippets || {}, + final, + paperless + } +}