1
0
Fork 0

🚧 shorthand

This commit is contained in:
joostdecock 2018-07-19 14:02:04 +00:00
parent 39f177dc26
commit 4f39c66381
3 changed files with 32 additions and 31 deletions

View file

@ -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
});
}
}

View file

@ -19,6 +19,7 @@ export class Pattern {
hooks: Hooks; hooks: Hooks;
snippet: Snippet snippet: Snippet
path: Path path: Path
context: any
constructor(config: PatternConfig) { constructor(config: PatternConfig) {
if(!config) { if(!config) {
@ -44,6 +45,13 @@ export class Pattern {
else this.options[conf.id] = conf.val; 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; return this;
} }

View file

@ -60,3 +60,27 @@ export function linesCross(a1: Point, a2: Point, b1: Point, b2: Point): Point |
return false; 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
}
}