From 11785baf1fe222ca9c502be880c0860ca42bb0f4 Mon Sep 17 00:00:00 2001 From: joostdecock Date: Thu, 12 Jul 2018 07:37:52 +0000 Subject: [PATCH] :sparkles: New point methods --- .gitignore | 3 ++ dist/config/config.d.ts | 24 --------- dist/config/config.js | 113 ---------------------------------------- dist/index.d.ts | 10 ---- dist/index.js | 15 ------ dist/lib/model.d.ts | 16 ------ dist/lib/model.js | 34 ------------ dist/lib/option.d.ts | 7 --- dist/lib/option.js | 12 ----- dist/lib/part.d.ts | 10 ---- dist/lib/part.js | 18 ------- dist/lib/pattern.d.ts | 16 ------ dist/lib/pattern.js | 34 ------------ dist/lib/point.d.ts | 5 -- dist/lib/point.js | 12 ----- dist/lib/types.d.ts | 35 ------------- dist/lib/types.js | 2 - dist/types.d.ts | 32 ------------ dist/types.js | 2 - lib/pattern.ts | 13 ++--- lib/point.ts | 49 +++++++++++++++++ lib/types.ts | 26 +++++++++ 22 files changed, 81 insertions(+), 407 deletions(-) delete mode 100644 dist/config/config.d.ts delete mode 100644 dist/config/config.js delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/lib/model.d.ts delete mode 100644 dist/lib/model.js delete mode 100644 dist/lib/option.d.ts delete mode 100644 dist/lib/option.js delete mode 100644 dist/lib/part.d.ts delete mode 100644 dist/lib/part.js delete mode 100644 dist/lib/pattern.d.ts delete mode 100644 dist/lib/pattern.js delete mode 100644 dist/lib/point.d.ts delete mode 100644 dist/lib/point.js delete mode 100644 dist/lib/types.d.ts delete mode 100644 dist/lib/types.js delete mode 100644 dist/types.d.ts delete mode 100644 dist/types.js diff --git a/.gitignore b/.gitignore index ad46b30886f..734627bbee0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ +# Compiled code +dist + # Logs logs *.log diff --git a/dist/config/config.d.ts b/dist/config/config.d.ts deleted file mode 100644 index 5358e870f60..00000000000 --- a/dist/config/config.d.ts +++ /dev/null @@ -1,24 +0,0 @@ -declare const manSize34: { - bicepsCircumference: number; - centerBackNeckToWaist: number; - chestCircumference: number; - hipsCircumference: number; - naturalWaistToHip: number; - neckCircumference: number; - shoulderSlope: number; - shoulderToShoulder: number; - shoulderToWrist: number; - wristCircumference: number; -}; -declare const manSize36: { - bicepsCircumference: number; - centerBackNeckToWaist: number; - chestCircumference: number; - hipsCircumference: number; - naturalWaistToHip: number; - neckCircumference: number; - shoulderSlope: number; - shoulderToShoulder: number; - shoulderToWrist: number; - wristCircumference: number; -}; diff --git a/dist/config/config.js b/dist/config/config.js deleted file mode 100644 index 085f88bfe2d..00000000000 --- a/dist/config/config.js +++ /dev/null @@ -1,113 +0,0 @@ -"use strict"; -var manSize34 = { - bicepsCircumference: 335, - centerBackNeckToWaist: 489, - chestCircumference: 849, - hipsCircumference: 722, - naturalWaistToHip: 100, - neckCircumference: 366, - shoulderSlope: 43, - shoulderToShoulder: 419, - shoulderToWrist: 670, - wristCircumference: 175 -}; -var manSize36 = { - bicepsCircumference: 290, - centerBackNeckToWaist: 492, - chestCircumference: 907, - hipsCircumference: 780, - naturalWaistToHip: 105, - neckCircumference: 378, - shoulderSlope: 46, - shoulderToShoulder: 431, - shoulderToWrist: 675, - wristCircumference: 180 -}; -size38: { - bicepsCircumference: 305, - centerBackNeckToWaist; - 495, - chestCircumference; - 965, - hipsCircumference; - 838, - naturalWaistToHip; - 110, - neckCircumference; - 391, - shoulderSlope; - 49, - shoulderToShoulder; - 444, - shoulderToWrist; - 680, - wristCircumference; - 185; -} -; -size40: { - bicepsCircumference: 320, - centerBackNeckToWaist; - 498, - chestCircumference; - 1023, - hipsCircumference; - 896, - naturalWaistToHip; - 115, - neckCircumference; - 404, - shoulderSlope; - 52, - shoulderToShoulder; - 457, - shoulderToWrist; - 685, - wristCircumference; - 190; -} -; -size42: { - bicepsCircumference: 335, - centerBackNeckToWaist; - 501, - chestCircumference; - 1081, - hipsCircumference; - 895, - naturalWaistToHip; - 120, - neckCircumference; - 416, - shoulderSlope; - 55, - shoulderToShoulder; - 470, - shoulderToWrist; - 690, - wristCircumference; - 195; -} -; -size44: { - bicepsCircumference: 350, - centerBackNeckToWaist; - 505, - chestCircumference; - 1139, - hipsCircumference; - 1012, - naturalWaistToHip; - 125, - neckCircumference; - 429, - shoulderSlope; - 58, - shoulderToShoulder; - 483, - shoulderToWrist; - 700, - wristCircumference; - 200; -} -; diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index a5f206ac623..00000000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,10 +0,0 @@ -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 deleted file mode 100644 index 693b7524cf0..00000000000 --- a/dist/index.js +++ /dev/null @@ -1,15 +0,0 @@ -"use strict"; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": 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 deleted file mode 100644 index ed4cfb3ccab..00000000000 --- a/dist/lib/model.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -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 deleted file mode 100644 index 4e71c3ad59e..00000000000 --- a/dist/lib/model.js +++ /dev/null @@ -1,34 +0,0 @@ -"use strict"; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var part_1 = __importDefault(require("./part")); -var option_1 = __importDefault(require("./option")); -var Pattern = /** @class */ (function () { - function Pattern(config) { - this.config = config; - 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; - } - 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/option.d.ts b/dist/lib/option.d.ts deleted file mode 100644 index 75b53d4952c..00000000000 --- a/dist/lib/option.d.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { PatternOption } from './types'; -export default class Option { - id: string; - config: PatternOption; - val: number; - constructor(config: PatternOption); -} diff --git a/dist/lib/option.js b/dist/lib/option.js deleted file mode 100644 index 82bae0c4f6b..00000000000 --- a/dist/lib/option.js +++ /dev/null @@ -1,12 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var Option = /** @class */ (function () { - function Option(config) { - this.id = config.id; - this.config = config; - this.val = config.val; - return this; - } - return Option; -}()); -exports.default = Option; diff --git a/dist/lib/part.d.ts b/dist/lib/part.d.ts deleted file mode 100644 index 20ba850714b..00000000000 --- a/dist/lib/part.d.ts +++ /dev/null @@ -1,10 +0,0 @@ -import Point from './point'; -export default class Part { - 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 deleted file mode 100644 index 4a8493bf1a9..00000000000 --- a/dist/lib/part.js +++ /dev/null @@ -1,18 +0,0 @@ -"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 deleted file mode 100644 index ed4cfb3ccab..00000000000 --- a/dist/lib/pattern.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -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/pattern.js b/dist/lib/pattern.js deleted file mode 100644 index 4e71c3ad59e..00000000000 --- a/dist/lib/pattern.js +++ /dev/null @@ -1,34 +0,0 @@ -"use strict"; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var part_1 = __importDefault(require("./part")); -var option_1 = __importDefault(require("./option")); -var Pattern = /** @class */ (function () { - function Pattern(config) { - this.config = config; - 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; - } - 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 deleted file mode 100644 index c851541f2f6..00000000000 --- a/dist/lib/point.d.ts +++ /dev/null @@ -1,5 +0,0 @@ -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 deleted file mode 100644 index 9002a98d4f6..00000000000 --- a/dist/lib/point.js +++ /dev/null @@ -1,12 +0,0 @@ -"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 deleted file mode 100644 index 6eaf3606f0e..00000000000 --- a/dist/lib/types.d.ts +++ /dev/null @@ -1,35 +0,0 @@ -export declare type PatternOptionType = "measure" | "percentage" | "angle" | "choice" | "constant"; -export interface PatternOption { - id: string; - val: number; - type?: string; - onlyIf?: { - option: string; - oneOf: number[]; - }; - min?: number; - max?: number; - options?: { - [index: number]: string; - }; -} -export interface PatternConfig { - parts: string[]; - measurements: string[]; - options: PatternOption[]; - [propName: string]: any; -} -export declare type DraftMode = "sample" | "compare" | "draft"; -export declare type CompareGroup = "men" | "women"; -export declare type Units = "metric" | "imperial"; -export interface DraftConfig { - mode: DraftMode; - units?: Units; - options: PatternOption[]; - measurements?: { - [index: string]: number; - }; - sa?: number; - scope?: string[]; - theme?: string; -} diff --git a/dist/lib/types.js b/dist/lib/types.js deleted file mode 100644 index c8ad2e549bd..00000000000 --- a/dist/lib/types.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/dist/types.d.ts b/dist/types.d.ts deleted file mode 100644 index 207f3c9ae5a..00000000000 --- a/dist/types.d.ts +++ /dev/null @@ -1,32 +0,0 @@ -export interface StringArray { - [index: number]: string; -} -export interface PatternOptionDependency { - option: string; - oneOf: number[]; -} -export declare type PatternOptionType = "measure" | "percentage" | "angle" | "choice"; -export interface PatternOption { - type?: PatternOptionType; - onlyIf?: PatternOptionDependency; -} -export interface PatternOptionNumeric extends PatternOption { - min: number; - max: number; - std: number; -} -export interface PatternOptionChoice extends PatternOption { - type: "choice"; - options: { - [index: number]: string; - }; -} -export interface PatternOptionArray { - [index: string]: PatternOptionNumeric | PatternOptionChoice; -} -export interface PatternConfig { - parts: StringArray; - measurements: StringArray; - options: PatternOptionArray; - [propName: string]: any; -} diff --git a/dist/types.js b/dist/types.js deleted file mode 100644 index c8ad2e549bd..00000000000 --- a/dist/types.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/lib/pattern.ts b/lib/pattern.ts index 0b310b0d8a9..e774f8ae79f 100644 --- a/lib/pattern.ts +++ b/lib/pattern.ts @@ -5,7 +5,7 @@ import Option from './option' export default class Pattern { config: PatternConfig; parts: {[propName: string]: Part}; - options: {[propName: string]: Option}; + options: {[propName: string]: number}; constructor(config: PatternConfig) { this.config = config; @@ -17,7 +17,8 @@ export default class Pattern { this.options = {}; for (let conf of config.options) { - this.options[conf.id] = new Option(conf); + if(conf.type === 'percentage') this.options[conf.id] = conf.val/100; + else this.options[conf.id] = conf.val; } return this; @@ -26,12 +27,4 @@ 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 index 468f601fe03..f885e7e5966 100644 --- a/lib/point.ts +++ b/lib/point.ts @@ -1,4 +1,6 @@ const PRECISION = 2; +const RAD = 57.29577951308232; + export default class Point { x: number; @@ -10,4 +12,51 @@ export default class Point { return this; } + + /** Returns the distance between this point and that point */ + distance(that: Point): number { + let dx = this.x - that.x; + let dy = this.y - that.y; + + return Math.sqrt(Math.pow(dx, 2) + Math.pow(dy,2)); + } + + /** Returns slope of a line made by this point and that point */ + slope(that: Point): number { + return (that.y - this.y) / (that.x - this.x); + } + + /** Returns the angle between this point and that point */ + angle(that: Point): number { + let dx = this.x - that.x; + let dy = this.y - that.y; + let rad = Math.atan2(-1 * dy, dy); + while (rad < 0) rad += 2 * Math.PI; + + // A poor man's rad2deg() + return rad * RAD; + } + + /** Rotate this point degrees around that point */ + rotate(degrees: number, that: Point) { + let radius = this.distance(that); + let angle = this.angle(that); + let x = that.x + radius * Math.cos((angle + degrees) / RAD) * -1; + let y = that.y + radius * Math.sin((angle + degrees) / RAD); + + return new Point(x, y); + } + + /** Shifts this point distance in the degrees direction */ + shift(degrees: number, distance: number): Point { + let p = this.copy(); + p.x += distance; + + return p.rotate(degrees, this); + } + + /** returns an identical copy of this point */ + copy(): Point { + return new Point(this.x, this.y); + } } diff --git a/lib/types.ts b/lib/types.ts index 4d944ec559b..7626ddbb6b5 100644 --- a/lib/types.ts +++ b/lib/types.ts @@ -37,3 +37,29 @@ export interface DraftConfig { scope?: string[]; theme?: string; } + +declare namespace Pattern { + export type OptionType = "measure" | "percentage" | "angle" | "choice" | "constant"; + + export interface Option { + id: string; + val: number; + type?: string; + onlyIf?: { + option: string; + oneOf: number[]; + } + min?: number; + max?: number; + options?: { + [index: number]: string; + } + } + + export interface Config { + parts: string[]; + measurements: string[]; + options: Option[]; + [propName: string]: any; + } +}