From 20eafd4a99a890deaaa4476c42530d73cb25f4de Mon Sep 17 00:00:00 2001 From: joostdecock Date: Wed, 11 Jul 2018 12:45:02 +0000 Subject: [PATCH] =?UTF-8?q?=C3=B0=C2=9F=C2=9A=C2=A7=20Question=20time?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dist/index.d.ts | 2 ++ dist/index.js | 2 ++ dist/lib/model.d.ts | 21 +++++++++++++++------ dist/lib/model.js | 34 ++++++++++++++++++++++++++++------ dist/lib/part.d.ts | 10 ++++++++-- dist/lib/part.js | 8 ++++++++ dist/lib/pattern.d.ts | 2 ++ dist/lib/pattern.js | 6 ++++++ dist/lib/point.d.ts | 5 +++++ dist/lib/point.js | 12 ++++++++++++ dist/lib/types.d.ts | 5 ----- index.ts | 2 ++ lib/model.ts | 14 -------------- lib/part.ts | 15 ++++++++++++--- lib/pattern.ts | 8 ++++++++ lib/point.ts | 13 +++++++++++++ lib/types.ts | 8 -------- 17 files changed, 123 insertions(+), 44 deletions(-) create mode 100644 dist/lib/point.d.ts create mode 100644 dist/lib/point.js delete mode 100644 lib/model.ts create mode 100644 lib/point.ts diff --git a/dist/index.d.ts b/dist/index.d.ts index 33c8e5c2a94..a5f206ac623 100644 --- a/dist/index.d.ts +++ b/dist/index.d.ts @@ -1,8 +1,10 @@ import pattern from './lib/pattern'; +import point from './lib/point'; import bezier from 'bezier-js'; declare var Freesewing: { version: string; pattern: typeof pattern; + point: typeof point; bezier: typeof bezier; }; export default Freesewing; diff --git a/dist/index.js b/dist/index.js index fe97877d7b5..693b7524cf0 100644 --- a/dist/index.js +++ b/dist/index.js @@ -4,10 +4,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) { }; Object.defineProperty(exports, "__esModule", { value: true }); var pattern_1 = __importDefault(require("./lib/pattern")); +var point_1 = __importDefault(require("./lib/point")); var bezier_js_1 = __importDefault(require("bezier-js")); var Freesewing = { version: '0.0.1', pattern: pattern_1.default, + point: point_1.default, bezier: bezier_js_1.default }; exports.default = Freesewing; diff --git a/dist/lib/model.d.ts b/dist/lib/model.d.ts index 195888a5eaf..ed4cfb3ccab 100644 --- a/dist/lib/model.d.ts +++ b/dist/lib/model.d.ts @@ -1,7 +1,16 @@ -import { PatternOption } from './types'; -export default class Model { - id: string; - config: PatternOption; - val: number; - constructor(config: PatternOption); +import { PatternConfig } from './types'; +import Part from './part'; +import Option from './option'; +export default class Pattern { + config: PatternConfig; + parts: { + [propName: string]: Part; + }; + options: { + [propName: string]: Option; + }; + constructor(config: PatternConfig); + draft(config: object): void; + getOption(id: string | number): any; + o(id: string | number): any; } diff --git a/dist/lib/model.js b/dist/lib/model.js index 7d0ac6e8a87..4e71c3ad59e 100644 --- a/dist/lib/model.js +++ b/dist/lib/model.js @@ -1,12 +1,34 @@ "use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; Object.defineProperty(exports, "__esModule", { value: true }); -var Model = /** @class */ (function () { - function Model(config) { - this.id = config.id; +var part_1 = __importDefault(require("./part")); +var option_1 = __importDefault(require("./option")); +var Pattern = /** @class */ (function () { + function Pattern(config) { this.config = config; - this.val = config.val; + this.parts = {}; + for (var _i = 0, _a = config.parts; _i < _a.length; _i++) { + var id = _a[_i]; + this.parts[id] = new part_1.default(id); + } + this.options = {}; + for (var _b = 0, _c = config.options; _b < _c.length; _b++) { + var conf = _c[_b]; + this.options[conf.id] = new option_1.default(conf); + } return this; } - return Model; + Pattern.prototype.draft = function (config) { + throw Error('You have to implement the draft() method in your Pattern instance.'); + }; + Pattern.prototype.getOption = function (id) { + return this.options[id].val; + }; + Pattern.prototype.o = function (id) { + return this.getOption(id); + }; + return Pattern; }()); -exports.default = Model; +exports.default = Pattern; diff --git a/dist/lib/part.d.ts b/dist/lib/part.d.ts index 7c8f48f031d..20ba850714b 100644 --- a/dist/lib/part.d.ts +++ b/dist/lib/part.d.ts @@ -1,4 +1,10 @@ +import Point from './point'; export default class Part { - id: string; - constructor(id: string); + id: string | number; + points: { + [index: string]: Point; + }; + [propName: string]: any; + constructor(id: string | number); + newPoint(id: string | number, x: number, y: number): void; } diff --git a/dist/lib/part.js b/dist/lib/part.js index 5ac001f178d..4a8493bf1a9 100644 --- a/dist/lib/part.js +++ b/dist/lib/part.js @@ -1,10 +1,18 @@ "use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; Object.defineProperty(exports, "__esModule", { value: true }); +var point_1 = __importDefault(require("./point")); var Part = /** @class */ (function () { function Part(id) { this.id = id; + this.points = {}; return this; } + Part.prototype.newPoint = function (id, x, y) { + this.points[id] = new point_1.default(x, y); + }; return Part; }()); exports.default = Part; diff --git a/dist/lib/pattern.d.ts b/dist/lib/pattern.d.ts index ddf72ac0c0d..ed4cfb3ccab 100644 --- a/dist/lib/pattern.d.ts +++ b/dist/lib/pattern.d.ts @@ -11,4 +11,6 @@ export default class Pattern { }; constructor(config: PatternConfig); draft(config: object): void; + getOption(id: string | number): any; + o(id: string | number): any; } diff --git a/dist/lib/pattern.js b/dist/lib/pattern.js index d83118b6fb9..4e71c3ad59e 100644 --- a/dist/lib/pattern.js +++ b/dist/lib/pattern.js @@ -23,6 +23,12 @@ var Pattern = /** @class */ (function () { Pattern.prototype.draft = function (config) { throw Error('You have to implement the draft() method in your Pattern instance.'); }; + Pattern.prototype.getOption = function (id) { + return this.options[id].val; + }; + Pattern.prototype.o = function (id) { + return this.getOption(id); + }; return Pattern; }()); exports.default = Pattern; diff --git a/dist/lib/point.d.ts b/dist/lib/point.d.ts new file mode 100644 index 00000000000..c851541f2f6 --- /dev/null +++ b/dist/lib/point.d.ts @@ -0,0 +1,5 @@ +export default class Point { + x: number; + y: number; + constructor(x: number, y: number); +} diff --git a/dist/lib/point.js b/dist/lib/point.js new file mode 100644 index 00000000000..9002a98d4f6 --- /dev/null +++ b/dist/lib/point.js @@ -0,0 +1,12 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +var PRECISION = 2; +var Point = /** @class */ (function () { + function Point(x, y) { + this.x = +x.toFixed(PRECISION); + this.y = +y.toFixed(PRECISION); + return this; + } + return Point; +}()); +exports.default = Point; diff --git a/dist/lib/types.d.ts b/dist/lib/types.d.ts index 2ecc442b594..6eaf3606f0e 100644 --- a/dist/lib/types.d.ts +++ b/dist/lib/types.d.ts @@ -19,11 +19,6 @@ export interface PatternConfig { options: PatternOption[]; [propName: string]: any; } -export declare type Pattern = { - parts: string[]; - measurements: string[]; - config: PatternConfig; -}; export declare type DraftMode = "sample" | "compare" | "draft"; export declare type CompareGroup = "men" | "women"; export declare type Units = "metric" | "imperial"; diff --git a/index.ts b/index.ts index b525e1be340..033319fa080 100644 --- a/index.ts +++ b/index.ts @@ -1,9 +1,11 @@ import pattern from './lib/pattern' +import point from './lib/point' import bezier from 'bezier-js' var Freesewing = { version: '0.0.1', pattern, + point, bezier } diff --git a/lib/model.ts b/lib/model.ts deleted file mode 100644 index ae29c30014d..00000000000 --- a/lib/model.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { PatternOption } from './types' -export default class Model { - id: string; - config: PatternOption; - val: number; - - constructor(config: PatternOption) { - this.id = config.id; - this.config = config; - this.val = config.val; - - return this; - } -} diff --git a/lib/part.ts b/lib/part.ts index 9ae7e3a41c3..bf822a52494 100644 --- a/lib/part.ts +++ b/lib/part.ts @@ -1,11 +1,20 @@ -import { PatternOption } from './types' +import Point from './point' export default class Part { - id: string; + id: string | number; + points: { + [index: string]: Point; + } + [propName: string]: any; - constructor(id: string) { + constructor(id: string | number) { this.id = id; + this.points = {}; return this; } + + newPoint(id: string | number, x: number, y: number) { + this.points[id] = new Point(x, y); + } } diff --git a/lib/pattern.ts b/lib/pattern.ts index 076712cb555..0b310b0d8a9 100644 --- a/lib/pattern.ts +++ b/lib/pattern.ts @@ -26,4 +26,12 @@ export default class Pattern { draft(config: object): void { throw Error('You have to implement the draft() method in your Pattern instance.'); } + + getOption(id: string | number): any { + return this.options[id].val; + } + + o(id: string | number): any { + return this.getOption(id); + } } diff --git a/lib/point.ts b/lib/point.ts new file mode 100644 index 00000000000..468f601fe03 --- /dev/null +++ b/lib/point.ts @@ -0,0 +1,13 @@ +const PRECISION = 2; + +export default class Point { + x: number; + y: number; + + constructor(x: number, y: number) { + this.x = +x.toFixed(PRECISION); + this.y = +y.toFixed(PRECISION); + + return this; + } +} diff --git a/lib/types.ts b/lib/types.ts index 5de534bb8ac..4d944ec559b 100644 --- a/lib/types.ts +++ b/lib/types.ts @@ -22,12 +22,6 @@ export interface PatternConfig { [propName: string]: any; } -export type Pattern = { - parts: string[]; - measurements: string[]; - config: PatternConfig; -} - export type DraftMode = "sample" | "compare" | "draft"; export type CompareGroup = "men" | "women"; export type Units = "metric" | "imperial"; @@ -43,5 +37,3 @@ export interface DraftConfig { scope?: string[]; theme?: string; } - -