@projectstorm/geometry
Advanced tools
Comparing version 6.2.0 to 6.3.0
export * from './Point'; | ||
export * from './Matrix'; | ||
export * from './Polygon'; | ||
export * from './Rectangle'; | ||
export * from './BezierCurve'; |
@@ -1,2 +0,2 @@ | ||
import { Matrix } from 'ml-matrix'; | ||
import { Matrix } from './Matrix'; | ||
export declare class Point { | ||
@@ -3,0 +3,0 @@ x: number; |
import { Point } from './Point'; | ||
import { Matrix } from 'ml-matrix'; | ||
import { Matrix } from './Matrix'; | ||
export declare class Polygon { | ||
@@ -4,0 +4,0 @@ protected points: Point[]; |
@@ -10,6 +10,7 @@ "use strict"; | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); | ||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
__exportStar(require("./Point"), exports); | ||
__exportStar(require("./Matrix"), exports); | ||
__exportStar(require("./Polygon"), exports); | ||
@@ -16,0 +17,0 @@ __exportStar(require("./Rectangle"), exports); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Point = void 0; | ||
const ml_matrix_1 = require("ml-matrix"); | ||
const Matrix_1 = require("./Matrix"); | ||
class Point { | ||
@@ -21,3 +21,3 @@ constructor(x, y) { | ||
asMatrix() { | ||
return new ml_matrix_1.Matrix([[this.x], [this.y], [1]]); | ||
return new Matrix_1.Matrix([[this.x], [this.y], [1]]); | ||
} | ||
@@ -40,3 +40,3 @@ transform(matrix) { | ||
static scaleMatrix(x, y) { | ||
return new ml_matrix_1.Matrix([ | ||
return new Matrix_1.Matrix([ | ||
[x, 0, 0], | ||
@@ -48,3 +48,3 @@ [0, y, 0], | ||
static translateMatrix(x, y) { | ||
return new ml_matrix_1.Matrix([ | ||
return new Matrix_1.Matrix([ | ||
[1, 0, x], | ||
@@ -56,3 +56,3 @@ [0, 1, y], | ||
static rotateMatrix(deg) { | ||
return new ml_matrix_1.Matrix([ | ||
return new Matrix_1.Matrix([ | ||
[Math.cos(deg), -1 * Math.sin(deg), 0], | ||
@@ -59,0 +59,0 @@ [Math.sin(deg), Math.cos(deg), 0], |
@@ -1,2 +0,2 @@ | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports["@projectstorm/react-diagrams-geometry"]=e():t["@projectstorm/react-diagrams-geometry"]=e()}(window,(function(){return function(t){var e={};function n(i){if(e[i])return e[i].exports;var o=e[i]={i:i,l:!1,exports:{}};return t[i].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=t,n.c=e,n.d=function(t,e,i){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:i})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var i=Object.create(null);if(n.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)n.d(i,o,function(e){return t[e]}.bind(null,o));return i},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=3)}([function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.Point=void 0;const i=n(4);class o{constructor(t,e){this.x=t,this.y=e}translate(t,e){this.x+=t,this.y+=e}clone(){return new o(this.x,this.y)}toSVG(){return this.x+" "+this.y}asMatrix(){return new i.Matrix([[this.x],[this.y],[1]])}transform(t){let e=t.mmul(this.asMatrix());this.x=e.get(0,0),this.y=e.get(1,0)}static middlePoint(t,e){return new o((e.x+t.x)/2,(e.y+t.y)/2)}static multiply(...t){let e=t[0];for(let n=1;n<t.length;n++)e=e.mmul(t[n]);return e}static scaleMatrix(t,e){return new i.Matrix([[t,0,0],[0,e,0],[0,0,1]])}static translateMatrix(t,e){return new i.Matrix([[1,0,t],[0,1,e],[0,0,1]])}static rotateMatrix(t){return new i.Matrix([[Math.cos(t),-1*Math.sin(t),0],[Math.sin(t),Math.cos(t),0],[0,0,1]])}static createScaleMatrix(t,e,n){return this.multiply(o.translateMatrix(n.x,n.y),o.scaleMatrix(t,e),o.translateMatrix(-n.x,-n.y))}static createRotateMatrix(t,e){return this.multiply(o.translateMatrix(e.x,e.y),o.rotateMatrix(t),o.translateMatrix(-e.x,-e.y))}}e.Point=o},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.Polygon=void 0;const i=n(0),o=n(5);class r{constructor(t=[]){this.points=t}serialize(){return o.map(this.points,t=>[t.x,t.y])}deserialize(t){this.points=o.map(t,t=>new i.Point(t[0],t[1]))}scale(t,e,n){let r=i.Point.createScaleMatrix(t,e,n);o.forEach(this.points,t=>{t.transform(r)})}transform(t){o.forEach(this.points,e=>{e.transform(t)})}setPoints(t){this.points=t}getPoints(){return this.points}rotate(t){this.transform(i.Point.createRotateMatrix(t/(180/Math.PI),this.getOrigin()))}translate(t,e){o.forEach(this.points,n=>{n.translate(t,e)})}doClone(t){this.points=o.map(t.points,t=>t.clone())}clone(){let t=Object.create(this);return t.doClone(this),t}getOrigin(){if(0===this.points.length)return null;let t=this.getBoundingBox();return i.Point.middlePoint(t.getTopLeft(),t.getBottomRight())}static boundingBoxFromPolygons(t){return r.boundingBoxFromPoints(o.flatMap(t,t=>t.getPoints()))}static boundingBoxFromPoints(t){if(0===t.length)return new s.Rectangle(0,0,0,0);let e=t[0].x,n=t[0].x,o=t[0].y,r=t[0].y;for(let i=1;i<t.length;i++)t[i].x<e&&(e=t[i].x),t[i].x>n&&(n=t[i].x),t[i].y<o&&(o=t[i].y),t[i].y>r&&(r=t[i].y);return new s.Rectangle(new i.Point(e,o),new i.Point(n,o),new i.Point(n,r),new i.Point(e,r))}getBoundingBox(){let t=this.points[0].x,e=this.points[0].x,n=this.points[0].y,o=this.points[0].y;for(let i=1;i<this.points.length;i++)this.points[i].x<t&&(t=this.points[i].x),this.points[i].x>e&&(e=this.points[i].x),this.points[i].y<n&&(n=this.points[i].y),this.points[i].y>o&&(o=this.points[i].y);return new s.Rectangle(new i.Point(t,n),new i.Point(e,n),new i.Point(e,o),new i.Point(t,o))}}e.Polygon=r;const s=n(2)},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.Rectangle=void 0;const i=n(0),o=n(1);class r extends o.Polygon{constructor(t=0,e=0,n=0,o=0){t instanceof i.Point&&e instanceof i.Point&&n instanceof i.Point&&o instanceof i.Point?super([t,e,n,o]):t instanceof i.Point?super([t,new i.Point(t.x+e,t.y),new i.Point(t.x+e,t.y+n),new i.Point(t.x,t.y+n)]):super(r.pointsFromBounds(t,e,n,o))}static pointsFromBounds(t,e,n,o){return[new i.Point(t,e),new i.Point(t+n,e),new i.Point(t+n,e+o),new i.Point(t,e+o)]}updateDimensions(t,e,n,i){this.points=r.pointsFromBounds(t,e,n,i)}setPoints(t){if(4!==t.length)throw"Rectangles must always have 4 points";super.setPoints(t)}containsPoint(t){const e=this.getTopLeft(),n=this.getBottomRight();return t.x>=e.x&&t.x<=n.x&&t.y>=e.y&&t.y<=n.y}getWidth(){return Math.sqrt(Math.pow(this.getTopLeft().x-this.getTopRight().x,2)+Math.pow(this.getTopLeft().y-this.getTopRight().y,2))}getHeight(){return Math.sqrt(Math.pow(this.getBottomLeft().x-this.getTopLeft().x,2)+Math.pow(this.getBottomLeft().y-this.getTopLeft().y,2))}getTopMiddle(){return i.Point.middlePoint(this.getTopLeft(),this.getTopRight())}getBottomMiddle(){return i.Point.middlePoint(this.getBottomLeft(),this.getBottomRight())}getLeftMiddle(){return i.Point.middlePoint(this.getBottomLeft(),this.getTopLeft())}getRightMiddle(){return i.Point.middlePoint(this.getBottomRight(),this.getTopRight())}getTopLeft(){return this.points[0]}getTopRight(){return this.points[1]}getBottomRight(){return this.points[2]}getBottomLeft(){return this.points[3]}}e.Rectangle=r},function(t,e,n){"use strict";var i=this&&this.__createBinding||(Object.create?function(t,e,n,i){void 0===i&&(i=n),Object.defineProperty(t,i,{enumerable:!0,get:function(){return e[n]}})}:function(t,e,n,i){void 0===i&&(i=n),t[i]=e[n]}),o=this&&this.__exportStar||function(t,e){for(var n in t)"default"===n||e.hasOwnProperty(n)||i(e,t,n)};Object.defineProperty(e,"__esModule",{value:!0}),o(n(0),e),o(n(1),e),o(n(2),e),o(n(6),e)},function(t,e){t.exports=require("ml-matrix")},function(t,e){t.exports=require("lodash")},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.BezierCurve=e.BezierCurvepPoints=void 0;const i=n(0),o=n(1);var r;!function(t){t[t.SOURCE=0]="SOURCE",t[t.SOURCE_CONTROL=1]="SOURCE_CONTROL",t[t.TARGET_CONTROL=2]="TARGET_CONTROL",t[t.TARGET=3]="TARGET"}(r=e.BezierCurvepPoints||(e.BezierCurvepPoints={}));class s extends o.Polygon{constructor(){super([new i.Point(0,0),new i.Point(0,0),new i.Point(0,0),new i.Point(0,0)])}getSVGCurve(){return`M${this.getSource().toSVG()} C${this.getSourceControl().toSVG()}, ${this.getTargetControl().toSVG()}, ${this.getTarget().toSVG()}`}setPoints(t){if(4!==t.length)throw new Error("BezierCurve must have extactly 4 points");super.setPoints(t)}getSource(){return this.points[r.SOURCE]}getSourceControl(){return this.points[r.SOURCE_CONTROL]}getTargetControl(){return this.points[r.TARGET_CONTROL]}getTarget(){return this.points[r.TARGET]}setSource(t){this.points[r.SOURCE]=t}setSourceControl(t){this.points[r.SOURCE_CONTROL]=t}setTargetControl(t){this.points[r.TARGET_CONTROL]=t}setTarget(t){this.points[r.TARGET]=t}}e.BezierCurve=s}])})); | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports["@projectstorm/react-diagrams-geometry"]=e():t["@projectstorm/react-diagrams-geometry"]=e()}(window,(function(){return function(t){var e={};function i(n){if(e[n])return e[n].exports;var o=e[n]={i:n,l:!1,exports:{}};return t[n].call(o.exports,o,o.exports,i),o.l=!0,o.exports}return i.m=t,i.c=e,i.d=function(t,e,n){i.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},i.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},i.t=function(t,e){if(1&e&&(t=i(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(i.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)i.d(n,o,function(e){return t[e]}.bind(null,o));return n},i.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return i.d(e,"a",e),e},i.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},i.p="",i(i.s=4)}([function(t,e,i){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.Point=void 0;const n=i(2);class o{constructor(t,e){this.x=t,this.y=e}translate(t,e){this.x+=t,this.y+=e}clone(){return new o(this.x,this.y)}toSVG(){return this.x+" "+this.y}asMatrix(){return new n.Matrix([[this.x],[this.y],[1]])}transform(t){let e=t.mmul(this.asMatrix());this.x=e.get(0,0),this.y=e.get(1,0)}static middlePoint(t,e){return new o((e.x+t.x)/2,(e.y+t.y)/2)}static multiply(...t){let e=t[0];for(let i=1;i<t.length;i++)e=e.mmul(t[i]);return e}static scaleMatrix(t,e){return new n.Matrix([[t,0,0],[0,e,0],[0,0,1]])}static translateMatrix(t,e){return new n.Matrix([[1,0,t],[0,1,e],[0,0,1]])}static rotateMatrix(t){return new n.Matrix([[Math.cos(t),-1*Math.sin(t),0],[Math.sin(t),Math.cos(t),0],[0,0,1]])}static createScaleMatrix(t,e,i){return this.multiply(o.translateMatrix(i.x,i.y),o.scaleMatrix(t,e),o.translateMatrix(-i.x,-i.y))}static createRotateMatrix(t,e){return this.multiply(o.translateMatrix(e.x,e.y),o.rotateMatrix(t),o.translateMatrix(-e.x,-e.y))}}e.Point=o},function(t,e,i){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.Polygon=void 0;const n=i(0),o=i(5);class r{constructor(t=[]){this.points=t}serialize(){return o.map(this.points,t=>[t.x,t.y])}deserialize(t){this.points=o.map(t,t=>new n.Point(t[0],t[1]))}scale(t,e,i){let r=n.Point.createScaleMatrix(t,e,i);o.forEach(this.points,t=>{t.transform(r)})}transform(t){o.forEach(this.points,e=>{e.transform(t)})}setPoints(t){this.points=t}getPoints(){return this.points}rotate(t){this.transform(n.Point.createRotateMatrix(t/(180/Math.PI),this.getOrigin()))}translate(t,e){o.forEach(this.points,i=>{i.translate(t,e)})}doClone(t){this.points=o.map(t.points,t=>t.clone())}clone(){let t=Object.create(this);return t.doClone(this),t}getOrigin(){if(0===this.points.length)return null;let t=this.getBoundingBox();return n.Point.middlePoint(t.getTopLeft(),t.getBottomRight())}static boundingBoxFromPolygons(t){return r.boundingBoxFromPoints(o.flatMap(t,t=>t.getPoints()))}static boundingBoxFromPoints(t){if(0===t.length)return new s.Rectangle(0,0,0,0);let e=t[0].x,i=t[0].x,o=t[0].y,r=t[0].y;for(let n=1;n<t.length;n++)t[n].x<e&&(e=t[n].x),t[n].x>i&&(i=t[n].x),t[n].y<o&&(o=t[n].y),t[n].y>r&&(r=t[n].y);return new s.Rectangle(new n.Point(e,o),new n.Point(i,o),new n.Point(i,r),new n.Point(e,r))}getBoundingBox(){let t=this.points[0].x,e=this.points[0].x,i=this.points[0].y,o=this.points[0].y;for(let n=1;n<this.points.length;n++)this.points[n].x<t&&(t=this.points[n].x),this.points[n].x>e&&(e=this.points[n].x),this.points[n].y<i&&(i=this.points[n].y),this.points[n].y>o&&(o=this.points[n].y);return new s.Rectangle(new n.Point(t,i),new n.Point(e,i),new n.Point(e,o),new n.Point(t,o))}}e.Polygon=r;const s=i(3)},function(t,e,i){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.Matrix=void 0;e.Matrix=class{constructor(t){this.matrix=t}mmul(t){return this.matrix=this.matrix.map((e,i)=>t.asArray()[0].map((n,o)=>e.reduce((e,n,r)=>e+this.matrix[i][r]*t.asArray()[r][o],0))),this}asArray(){return this.matrix}get(t,e){return this.asArray()[t][e]}}},function(t,e,i){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.Rectangle=void 0;const n=i(0),o=i(1);class r extends o.Polygon{constructor(t=0,e=0,i=0,o=0){t instanceof n.Point&&e instanceof n.Point&&i instanceof n.Point&&o instanceof n.Point?super([t,e,i,o]):t instanceof n.Point?super([t,new n.Point(t.x+e,t.y),new n.Point(t.x+e,t.y+i),new n.Point(t.x,t.y+i)]):super(r.pointsFromBounds(t,e,i,o))}static pointsFromBounds(t,e,i,o){return[new n.Point(t,e),new n.Point(t+i,e),new n.Point(t+i,e+o),new n.Point(t,e+o)]}updateDimensions(t,e,i,n){this.points=r.pointsFromBounds(t,e,i,n)}setPoints(t){if(4!==t.length)throw"Rectangles must always have 4 points";super.setPoints(t)}containsPoint(t){const e=this.getTopLeft(),i=this.getBottomRight();return t.x>=e.x&&t.x<=i.x&&t.y>=e.y&&t.y<=i.y}getWidth(){return Math.sqrt(Math.pow(this.getTopLeft().x-this.getTopRight().x,2)+Math.pow(this.getTopLeft().y-this.getTopRight().y,2))}getHeight(){return Math.sqrt(Math.pow(this.getBottomLeft().x-this.getTopLeft().x,2)+Math.pow(this.getBottomLeft().y-this.getTopLeft().y,2))}getTopMiddle(){return n.Point.middlePoint(this.getTopLeft(),this.getTopRight())}getBottomMiddle(){return n.Point.middlePoint(this.getBottomLeft(),this.getBottomRight())}getLeftMiddle(){return n.Point.middlePoint(this.getBottomLeft(),this.getTopLeft())}getRightMiddle(){return n.Point.middlePoint(this.getBottomRight(),this.getTopRight())}getTopLeft(){return this.points[0]}getTopRight(){return this.points[1]}getBottomRight(){return this.points[2]}getBottomLeft(){return this.points[3]}}e.Rectangle=r},function(t,e,i){"use strict";var n=this&&this.__createBinding||(Object.create?function(t,e,i,n){void 0===n&&(n=i),Object.defineProperty(t,n,{enumerable:!0,get:function(){return e[i]}})}:function(t,e,i,n){void 0===n&&(n=i),t[n]=e[i]}),o=this&&this.__exportStar||function(t,e){for(var i in t)"default"===i||Object.prototype.hasOwnProperty.call(e,i)||n(e,t,i)};Object.defineProperty(e,"__esModule",{value:!0}),o(i(0),e),o(i(2),e),o(i(1),e),o(i(3),e),o(i(6),e)},function(t,e){t.exports=require("lodash")},function(t,e,i){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.BezierCurve=e.BezierCurvepPoints=void 0;const n=i(0),o=i(1);var r;!function(t){t[t.SOURCE=0]="SOURCE",t[t.SOURCE_CONTROL=1]="SOURCE_CONTROL",t[t.TARGET_CONTROL=2]="TARGET_CONTROL",t[t.TARGET=3]="TARGET"}(r=e.BezierCurvepPoints||(e.BezierCurvepPoints={}));class s extends o.Polygon{constructor(){super([new n.Point(0,0),new n.Point(0,0),new n.Point(0,0),new n.Point(0,0)])}getSVGCurve(){return`M${this.getSource().toSVG()} C${this.getSourceControl().toSVG()}, ${this.getTargetControl().toSVG()}, ${this.getTarget().toSVG()}`}setPoints(t){if(4!==t.length)throw new Error("BezierCurve must have extactly 4 points");super.setPoints(t)}getSource(){return this.points[r.SOURCE]}getSourceControl(){return this.points[r.SOURCE_CONTROL]}getTargetControl(){return this.points[r.TARGET_CONTROL]}getTarget(){return this.points[r.TARGET]}setSource(t){this.points[r.SOURCE]=t}setSourceControl(t){this.points[r.SOURCE_CONTROL]=t}setTargetControl(t){this.points[r.TARGET_CONTROL]=t}setTarget(t){this.points[r.TARGET]=t}}e.BezierCurve=s}])})); | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@projectstorm/geometry", | ||
"version": "6.2.0", | ||
"version": "6.3.0", | ||
"author": "dylanvorster", | ||
@@ -33,6 +33,3 @@ "license": "MIT", | ||
"typings": "./dist/@types/index", | ||
"peerDependencies": { | ||
"ml-matrix": "^6.5.0" | ||
}, | ||
"gitHead": "c5b24f6e7b0fce76e221b348d3f027e6144ef5cb" | ||
"gitHead": "63dbe41df017db10212e93b22b282c0f3c363b1b" | ||
} |
export * from './Point'; | ||
export * from './Matrix'; | ||
export * from './Polygon'; | ||
export * from './Rectangle'; | ||
export * from './BezierCurve'; |
@@ -1,2 +0,2 @@ | ||
import { Matrix } from 'ml-matrix'; | ||
import { Matrix } from './Matrix'; | ||
@@ -3,0 +3,0 @@ export class Point { |
import { Point } from './Point'; | ||
import * as _ from 'lodash'; | ||
import { Matrix } from 'ml-matrix'; | ||
import { Matrix } from './Matrix'; | ||
@@ -5,0 +5,0 @@ export class Polygon { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
68847
0
28
779