🚧 shorthand
This commit is contained in:
parent
39f177dc26
commit
4f39c66381
3 changed files with 32 additions and 31 deletions
|
@ -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
|
||||
});
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
24
lib/utils.ts
24
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
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue