✨ New point methods
This commit is contained in:
parent
c761e5d157
commit
11785baf1f
22 changed files with 81 additions and 407 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -1,3 +1,6 @@
|
|||
# Compiled code
|
||||
dist
|
||||
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
|
|
24
dist/config/config.d.ts
vendored
24
dist/config/config.d.ts
vendored
|
@ -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;
|
||||
};
|
113
dist/config/config.js
vendored
113
dist/config/config.js
vendored
|
@ -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;
|
||||
}
|
||||
;
|
10
dist/index.d.ts
vendored
10
dist/index.d.ts
vendored
|
@ -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;
|
15
dist/index.js
vendored
15
dist/index.js
vendored
|
@ -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;
|
16
dist/lib/model.d.ts
vendored
16
dist/lib/model.d.ts
vendored
|
@ -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;
|
||||
}
|
34
dist/lib/model.js
vendored
34
dist/lib/model.js
vendored
|
@ -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;
|
7
dist/lib/option.d.ts
vendored
7
dist/lib/option.d.ts
vendored
|
@ -1,7 +0,0 @@
|
|||
import { PatternOption } from './types';
|
||||
export default class Option {
|
||||
id: string;
|
||||
config: PatternOption;
|
||||
val: number;
|
||||
constructor(config: PatternOption);
|
||||
}
|
12
dist/lib/option.js
vendored
12
dist/lib/option.js
vendored
|
@ -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;
|
10
dist/lib/part.d.ts
vendored
10
dist/lib/part.d.ts
vendored
|
@ -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;
|
||||
}
|
18
dist/lib/part.js
vendored
18
dist/lib/part.js
vendored
|
@ -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;
|
16
dist/lib/pattern.d.ts
vendored
16
dist/lib/pattern.d.ts
vendored
|
@ -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;
|
||||
}
|
34
dist/lib/pattern.js
vendored
34
dist/lib/pattern.js
vendored
|
@ -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;
|
5
dist/lib/point.d.ts
vendored
5
dist/lib/point.d.ts
vendored
|
@ -1,5 +0,0 @@
|
|||
export default class Point {
|
||||
x: number;
|
||||
y: number;
|
||||
constructor(x: number, y: number);
|
||||
}
|
12
dist/lib/point.js
vendored
12
dist/lib/point.js
vendored
|
@ -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;
|
35
dist/lib/types.d.ts
vendored
35
dist/lib/types.d.ts
vendored
|
@ -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;
|
||||
}
|
2
dist/lib/types.js
vendored
2
dist/lib/types.js
vendored
|
@ -1,2 +0,0 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
32
dist/types.d.ts
vendored
32
dist/types.d.ts
vendored
|
@ -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;
|
||||
}
|
2
dist/types.js
vendored
2
dist/types.js
vendored
|
@ -1,2 +0,0 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
49
lib/point.ts
49
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);
|
||||
}
|
||||
}
|
||||
|
|
26
lib/types.ts
26
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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue