Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@projectstorm/geometry

Package Overview
Dependencies
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@projectstorm/geometry - npm Package Compare versions

Comparing version 6.7.4 to 7.0.0

dist/@types/Bounds.d.ts

2

dist/@types/index.d.ts

@@ -6,1 +6,3 @@ export * from './Point';

export * from './BezierCurve';
export * from './toolkit';
export * from './Bounds';

@@ -0,1 +1,2 @@

import { Point } from './Point';
export declare class Matrix {

@@ -7,2 +8,8 @@ matrix: number[][];

get(rowIndex: number, columnIndex: number): number;
static multiply(...matrices: Matrix[]): Matrix;
static scaleMatrix(x: number, y: number): Matrix;
static translateMatrix(x: number, y: number): Matrix;
static rotateMatrix(deg: number): Matrix;
static createScaleMatrix(x: any, y: any, origin: Point): Matrix;
static createRotateMatrix(deg: number, origin: Point): Matrix;
}

8

dist/@types/Point.d.ts

@@ -5,3 +5,3 @@ import { Matrix } from './Matrix';

y: number;
constructor(x: number, y: number);
constructor(x?: number, y?: number);
translate(x: number, y: number): void;

@@ -13,8 +13,2 @@ clone(): Point;

static middlePoint(pointA: Point, pointB: Point): Point;
static multiply(...matrices: Matrix[]): Matrix;
static scaleMatrix(x: number, y: number): Matrix;
static translateMatrix(x: number, y: number): Matrix;
static rotateMatrix(deg: number): Matrix;
static createScaleMatrix(x: any, y: any, origin: Point): Matrix;
static createRotateMatrix(deg: number, origin: Point): Matrix;
}
import { Point } from './Point';
import { Matrix } from './Matrix';
import { Bounds } from './Bounds';
export declare class Polygon {

@@ -17,6 +18,3 @@ protected points: Point[];

getOrigin(): Point;
static boundingBoxFromPolygons(polygons: Polygon[]): Rectangle;
static boundingBoxFromPoints(points: Point[]): Rectangle;
getBoundingBox(): Rectangle;
getBoundingBox(): Bounds;
}
import { Rectangle } from './Rectangle';
import { Point } from './Point';
import { Polygon } from './Polygon';
import { Bounds } from './Bounds';
export declare class Rectangle extends Polygon {
constructor(tl: Point, tr: Point, br: Point, bl: Point);
constructor(position: Point, width: number, height: number);
constructor(x?: number, y?: number, width?: number, height?: number);
static pointsFromBounds(x: number, y: number, width: number, height: number): Point[];
static fromPositionAndSize(x: number, y: number, width: number, height: number): Rectangle;
static fromPointAndSize(position: Point, width: number, height: number): Rectangle;
constructor(points?: Bounds);
updateDimensions(x: number, y: number, width: number, height: number): void;

@@ -9,0 +9,0 @@ setPoints(points: Point[]): void;

@@ -1,7 +0,4 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.BezierCurve = exports.BezierCurvepPoints = void 0;
const Point_1 = require("./Point");
const Polygon_1 = require("./Polygon");
var BezierCurvepPoints;
import { Point } from './Point';
import { Polygon } from './Polygon';
export var BezierCurvepPoints;
(function (BezierCurvepPoints) {

@@ -12,6 +9,6 @@ BezierCurvepPoints[BezierCurvepPoints["SOURCE"] = 0] = "SOURCE";

BezierCurvepPoints[BezierCurvepPoints["TARGET"] = 3] = "TARGET";
})(BezierCurvepPoints = exports.BezierCurvepPoints || (exports.BezierCurvepPoints = {}));
class BezierCurve extends Polygon_1.Polygon {
})(BezierCurvepPoints || (BezierCurvepPoints = {}));
export class BezierCurve extends Polygon {
constructor() {
super([new Point_1.Point(0, 0), new Point_1.Point(0, 0), new Point_1.Point(0, 0), new Point_1.Point(0, 0)]);
super([new Point(0, 0), new Point(0, 0), new Point(0, 0), new Point(0, 0)]);
}

@@ -52,3 +49,2 @@ getSVGCurve() {

}
exports.BezierCurve = BezierCurve;
//# sourceMappingURL=BezierCurve.js.map

@@ -1,22 +0,8 @@

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
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);
__exportStar(require("./Rectangle"), exports);
__exportStar(require("./BezierCurve"), exports);
export * from './Point';
export * from './Matrix';
export * from './Polygon';
export * from './Rectangle';
export * from './BezierCurve';
export * from './toolkit';
export * from './Bounds';
//# sourceMappingURL=index.js.map

@@ -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()}(self,(()=>(()=>{"use strict";var t={419:(t,e,i)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.BezierCurve=e.BezierCurvepPoints=void 0;const o=i(397),n=i(312);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 n.Polygon{constructor(){super([new o.Point(0,0),new o.Point(0,0),new o.Point(0,0),new o.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},848:(t,e)=>{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(((o,n)=>e.reduce(((e,o,r)=>e+this.matrix[i][r]*t.asArray()[r][n]),0))))),this}asArray(){return this.matrix}get(t,e){return this.asArray()[t][e]}}},397:(t,e,i)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.Point=void 0;const o=i(848);class n{constructor(t,e){this.x=t,this.y=e}translate(t,e){this.x+=t,this.y+=e}clone(){return new n(this.x,this.y)}toSVG(){return this.x+" "+this.y}asMatrix(){return new o.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 n((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 o.Matrix([[t,0,0],[0,e,0],[0,0,1]])}static translateMatrix(t,e){return new o.Matrix([[1,0,t],[0,1,e],[0,0,1]])}static rotateMatrix(t){return new o.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(n.translateMatrix(i.x,i.y),n.scaleMatrix(t,e),n.translateMatrix(-i.x,-i.y))}static createRotateMatrix(t,e){return this.multiply(n.translateMatrix(e.x,e.y),n.rotateMatrix(t),n.translateMatrix(-e.x,-e.y))}}e.Point=n},312:(t,e,i)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.Polygon=void 0;const o=i(397),n=i(517);class r{constructor(t=[]){this.points=t}serialize(){return n.map(this.points,(t=>[t.x,t.y]))}deserialize(t){this.points=n.map(t,(t=>new o.Point(t[0],t[1])))}scale(t,e,i){let r=o.Point.createScaleMatrix(t,e,i);n.forEach(this.points,(t=>{t.transform(r)}))}transform(t){n.forEach(this.points,(e=>{e.transform(t)}))}setPoints(t){this.points=t}getPoints(){return this.points}rotate(t){this.transform(o.Point.createRotateMatrix(t/(180/Math.PI),this.getOrigin()))}translate(t,e){n.forEach(this.points,(i=>{i.translate(t,e)}))}doClone(t){this.points=n.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 o.Point.middlePoint(t.getTopLeft(),t.getBottomRight())}static boundingBoxFromPolygons(t){return r.boundingBoxFromPoints(n.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,n=t[0].y,r=t[0].y;for(let o=1;o<t.length;o++)t[o].x<e&&(e=t[o].x),t[o].x>i&&(i=t[o].x),t[o].y<n&&(n=t[o].y),t[o].y>r&&(r=t[o].y);return new s.Rectangle(new o.Point(e,n),new o.Point(i,n),new o.Point(i,r),new o.Point(e,r))}getBoundingBox(){let t=this.points[0].x,e=this.points[0].x,i=this.points[0].y,n=this.points[0].y;for(let o=1;o<this.points.length;o++)this.points[o].x<t&&(t=this.points[o].x),this.points[o].x>e&&(e=this.points[o].x),this.points[o].y<i&&(i=this.points[o].y),this.points[o].y>n&&(n=this.points[o].y);return new s.Rectangle(new o.Point(t,i),new o.Point(e,i),new o.Point(e,n),new o.Point(t,n))}}e.Polygon=r;const s=i(114)},114:(t,e,i)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.Rectangle=void 0;const o=i(397),n=i(312);class r extends n.Polygon{constructor(t=0,e=0,i=0,n=0){t instanceof o.Point&&e instanceof o.Point&&i instanceof o.Point&&n instanceof o.Point?super([t,e,i,n]):t instanceof o.Point?super([t,new o.Point(t.x+e,t.y),new o.Point(t.x+e,t.y+i),new o.Point(t.x,t.y+i)]):super(r.pointsFromBounds(t,e,i,n))}static pointsFromBounds(t,e,i,n){return[new o.Point(t,e),new o.Point(t+i,e),new o.Point(t+i,e+n),new o.Point(t,e+n)]}updateDimensions(t,e,i,o){this.points=r.pointsFromBounds(t,e,i,o)}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 o.Point.middlePoint(this.getTopLeft(),this.getTopRight())}getBottomMiddle(){return o.Point.middlePoint(this.getBottomLeft(),this.getBottomRight())}getLeftMiddle(){return o.Point.middlePoint(this.getBottomLeft(),this.getTopLeft())}getRightMiddle(){return o.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},418:function(t,e,i){var o=this&&this.__createBinding||(Object.create?function(t,e,i,o){void 0===o&&(o=i);var n=Object.getOwnPropertyDescriptor(e,i);n&&!("get"in n?!e.__esModule:n.writable||n.configurable)||(n={enumerable:!0,get:function(){return e[i]}}),Object.defineProperty(t,o,n)}:function(t,e,i,o){void 0===o&&(o=i),t[o]=e[i]}),n=this&&this.__exportStar||function(t,e){for(var i in t)"default"===i||Object.prototype.hasOwnProperty.call(e,i)||o(e,t,i)};Object.defineProperty(e,"__esModule",{value:!0}),n(i(397),e),n(i(848),e),n(i(312),e),n(i(114),e),n(i(419),e)},517:t=>{t.exports=require("lodash")}},e={};var i=function i(o){var n=e[o];if(void 0!==n)return n.exports;var r=e[o]={exports:{}};return t[o].call(r.exports,r,r.exports,i),r.exports}(418);return i})()));
!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()}(self,(()=>(()=>{"use strict";var t={d:(e,r)=>{for(var i in r)t.o(r,i)&&!t.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:r[i]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},e={};t.r(e),t.d(e,{BezierCurve:()=>p,BezierCurvepPoints:()=>g,BoundsCorner:()=>s,Matrix:()=>r,Point:()=>i,Polygon:()=>u,Rectangle:()=>l,boundingBoxFromPoints:()=>T,boundingBoxFromPolygons:()=>h,boundsFromPositionAndSize:()=>n,createEmptyBounds:()=>a});class r{constructor(t){this.matrix=t}mmul(t){return this.matrix=this.matrix.map(((e,r)=>t.asArray()[0].map(((i,o)=>e.reduce(((e,i,s)=>e+this.matrix[r][s]*t.asArray()[s][o]),0))))),this}asArray(){return this.matrix}get(t,e){return this.asArray()[t][e]}static multiply(...t){let e=t[0];for(let r=1;r<t.length;r++)e=e.mmul(t[r]);return e}static scaleMatrix(t,e){return new r([[t,0,0],[0,e,0],[0,0,1]])}static translateMatrix(t,e){return new r([[1,0,t],[0,1,e],[0,0,1]])}static rotateMatrix(t){return new r([[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(r.translateMatrix(i.x,i.y),r.scaleMatrix(t,e),r.translateMatrix(-i.x,-i.y))}static createRotateMatrix(t,e){return this.multiply(r.translateMatrix(e.x,e.y),r.rotateMatrix(t),r.translateMatrix(-e.x,-e.y))}}class i{constructor(t=0,e=0){this.x=t,this.y=e}translate(t,e){this.x+=t,this.y+=e}clone(){return new i(this.x,this.y)}toSVG(){return this.x+" "+this.y}asMatrix(){return new r([[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 i((e.x+t.x)/2,(e.y+t.y)/2)}}const o=require("lodash");var s;!function(t){t.TOP_LEFT="TL",t.TOP_RIGHT="TR",t.BOTTOM_RIGHT="BR",t.BOTTOM_LEFT="BL"}(s||(s={}));const n=(t,e,r,o)=>({[s.TOP_LEFT]:new i(t,e),[s.TOP_RIGHT]:new i(t+r,e),[s.BOTTOM_RIGHT]:new i(t+r,e+o),[s.BOTTOM_LEFT]:new i(t,e+o)}),a=()=>({[s.TOP_LEFT]:new i,[s.TOP_RIGHT]:new i,[s.BOTTOM_RIGHT]:new i,[s.BOTTOM_LEFT]:new i}),T=t=>{if(0===t.length)return a();let e=t[0].x,r=t[0].x,o=t[0].y,n=t[0].y;for(let i=1;i<t.length;i++)t[i].x<e&&(e=t[i].x),t[i].x>r&&(r=t[i].x),t[i].y<o&&(o=t[i].y),t[i].y>n&&(n=t[i].y);return{[s.TOP_LEFT]:new i(e,o),[s.TOP_RIGHT]:new i(r,o),[s.BOTTOM_RIGHT]:new i(r,n),[s.BOTTOM_LEFT]:new i(e,n)}},h=t=>T(o.flatMap(t,(t=>t.getPoints())));class u{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(t[0],t[1])))}scale(t,e,i){let s=r.createScaleMatrix(t,e,i);o.forEach(this.points,(t=>{t.transform(s)}))}transform(t){o.forEach(this.points,(e=>{e.transform(t)}))}setPoints(t){this.points=t}getPoints(){return this.points}rotate(t){this.transform(r.createRotateMatrix(t/(180/Math.PI),this.getOrigin()))}translate(t,e){o.forEach(this.points,(r=>{r.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=T(this.points);return i.middlePoint(t[s.TOP_LEFT],t[s.BOTTOM_RIGHT])}getBoundingBox(){return T(this.points)}}class l extends u{static fromPositionAndSize(t,e,r,i){return new l(n(t,e,r,i))}static fromPointAndSize(t,e,r){return new l(n(t.x,t.y,e,r))}constructor(t){t||(t=a()),super([t[s.TOP_LEFT],t[s.TOP_RIGHT],t[s.BOTTOM_RIGHT],t[s.BOTTOM_LEFT]])}updateDimensions(t,e,r,i){const o=n(t,e,r,i);this.setPoints([o[s.TOP_LEFT],o[s.TOP_RIGHT],o[s.BOTTOM_RIGHT],o[s.BOTTOM_LEFT]])}setPoints(t){if(4!==t.length)throw"Rectangles must always have 4 points";super.setPoints(t)}containsPoint(t){const e=this.getTopLeft(),r=this.getBottomRight();return t.x>=e.x&&t.x<=r.x&&t.y>=e.y&&t.y<=r.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.middlePoint(this.getTopLeft(),this.getTopRight())}getBottomMiddle(){return i.middlePoint(this.getBottomLeft(),this.getBottomRight())}getLeftMiddle(){return i.middlePoint(this.getBottomLeft(),this.getTopLeft())}getRightMiddle(){return i.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]}}var g;!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"}(g||(g={}));class p extends u{constructor(){super([new i(0,0),new i(0,0),new i(0,0),new i(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[g.SOURCE]}getSourceControl(){return this.points[g.SOURCE_CONTROL]}getTargetControl(){return this.points[g.TARGET_CONTROL]}getTarget(){return this.points[g.TARGET]}setSource(t){this.points[g.SOURCE]=t}setSourceControl(t){this.points[g.SOURCE_CONTROL]=t}setTargetControl(t){this.points[g.TARGET_CONTROL]=t}setTarget(t){this.points[g.TARGET]=t}}return e})()));
//# sourceMappingURL=index.umd.js.map

@@ -1,5 +0,2 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Matrix = void 0;
class Matrix {
export class Matrix {
constructor(matrix) {

@@ -18,4 +15,37 @@ this.matrix = matrix;

}
static multiply(...matrices) {
let m = matrices[0];
for (let i = 1; i < matrices.length; i++) {
m = m.mmul(matrices[i]);
}
return m;
}
static scaleMatrix(x, y) {
return new Matrix([
[x, 0, 0],
[0, y, 0],
[0, 0, 1]
]);
}
static translateMatrix(x, y) {
return new Matrix([
[1, 0, x],
[0, 1, y],
[0, 0, 1]
]);
}
static rotateMatrix(deg) {
return new Matrix([
[Math.cos(deg), -1 * Math.sin(deg), 0],
[Math.sin(deg), Math.cos(deg), 0],
[0, 0, 1]
]);
}
static createScaleMatrix(x, y, origin) {
return this.multiply(Matrix.translateMatrix(origin.x, origin.y), Matrix.scaleMatrix(x, y), Matrix.translateMatrix(-origin.x, -origin.y));
}
static createRotateMatrix(deg, origin) {
return this.multiply(Matrix.translateMatrix(origin.x, origin.y), Matrix.rotateMatrix(deg), Matrix.translateMatrix(-origin.x, -origin.y));
}
}
exports.Matrix = Matrix;
//# sourceMappingURL=Matrix.js.map

@@ -1,7 +0,4 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Point = void 0;
const Matrix_1 = require("./Matrix");
class Point {
constructor(x, y) {
import { Matrix } from './Matrix';
export class Point {
constructor(x = 0, y = 0) {
this.x = x;

@@ -21,3 +18,3 @@ this.y = y;

asMatrix() {
return new Matrix_1.Matrix([[this.x], [this.y], [1]]);
return new Matrix([[this.x], [this.y], [1]]);
}

@@ -32,38 +29,3 @@ transform(matrix) {

}
static multiply(...matrices) {
let m = matrices[0];
for (let i = 1; i < matrices.length; i++) {
m = m.mmul(matrices[i]);
}
return m;
}
static scaleMatrix(x, y) {
return new Matrix_1.Matrix([
[x, 0, 0],
[0, y, 0],
[0, 0, 1]
]);
}
static translateMatrix(x, y) {
return new Matrix_1.Matrix([
[1, 0, x],
[0, 1, y],
[0, 0, 1]
]);
}
static rotateMatrix(deg) {
return new Matrix_1.Matrix([
[Math.cos(deg), -1 * Math.sin(deg), 0],
[Math.sin(deg), Math.cos(deg), 0],
[0, 0, 1]
]);
}
static createScaleMatrix(x, y, origin) {
return this.multiply(Point.translateMatrix(origin.x, origin.y), Point.scaleMatrix(x, y), Point.translateMatrix(-origin.x, -origin.y));
}
static createRotateMatrix(deg, origin) {
return this.multiply(Point.translateMatrix(origin.x, origin.y), Point.rotateMatrix(deg), Point.translateMatrix(-origin.x, -origin.y));
}
}
exports.Point = Point;
//# sourceMappingURL=Point.js.map

@@ -1,7 +0,7 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Polygon = void 0;
const Point_1 = require("./Point");
const _ = require("lodash");
class Polygon {
import { Point } from './Point';
import * as _ from 'lodash';
import { Matrix } from './Matrix';
import { boundingBoxFromPoints } from './toolkit';
import { BoundsCorner } from './Bounds';
export class Polygon {
constructor(points = []) {

@@ -17,7 +17,7 @@ this.points = points;

this.points = _.map(data, (point) => {
return new Point_1.Point(point[0], point[1]);
return new Point(point[0], point[1]);
});
}
scale(x, y, origin) {
let matrix = Point_1.Point.createScaleMatrix(x, y, origin);
let matrix = Matrix.createScaleMatrix(x, y, origin);
_.forEach(this.points, (point) => {

@@ -39,3 +39,3 @@ point.transform(matrix);

rotate(degrees) {
this.transform(Point_1.Point.createRotateMatrix(degrees / (180 / Math.PI), this.getOrigin()));
this.transform(Matrix.createRotateMatrix(degrees / (180 / Math.PI), this.getOrigin()));
}

@@ -61,58 +61,9 @@ translate(offsetX, offsetY) {

}
let dimensions = this.getBoundingBox();
return Point_1.Point.middlePoint(dimensions.getTopLeft(), dimensions.getBottomRight());
let dimensions = boundingBoxFromPoints(this.points);
return Point.middlePoint(dimensions[BoundsCorner.TOP_LEFT], dimensions[BoundsCorner.BOTTOM_RIGHT]);
}
static boundingBoxFromPolygons(polygons) {
return Polygon.boundingBoxFromPoints(_.flatMap(polygons, (polygon) => {
return polygon.getPoints();
}));
}
static boundingBoxFromPoints(points) {
if (points.length === 0) {
return new Rectangle_1.Rectangle(0, 0, 0, 0);
}
let minX = points[0].x;
let maxX = points[0].x;
let minY = points[0].y;
let maxY = points[0].y;
for (let i = 1; i < points.length; i++) {
if (points[i].x < minX) {
minX = points[i].x;
}
if (points[i].x > maxX) {
maxX = points[i].x;
}
if (points[i].y < minY) {
minY = points[i].y;
}
if (points[i].y > maxY) {
maxY = points[i].y;
}
}
return new Rectangle_1.Rectangle(new Point_1.Point(minX, minY), new Point_1.Point(maxX, minY), new Point_1.Point(maxX, maxY), new Point_1.Point(minX, maxY));
}
getBoundingBox() {
let minX = this.points[0].x;
let maxX = this.points[0].x;
let minY = this.points[0].y;
let maxY = this.points[0].y;
for (let i = 1; i < this.points.length; i++) {
if (this.points[i].x < minX) {
minX = this.points[i].x;
}
if (this.points[i].x > maxX) {
maxX = this.points[i].x;
}
if (this.points[i].y < minY) {
minY = this.points[i].y;
}
if (this.points[i].y > maxY) {
maxY = this.points[i].y;
}
}
return new Rectangle_1.Rectangle(new Point_1.Point(minX, minY), new Point_1.Point(maxX, minY), new Point_1.Point(maxX, maxY), new Point_1.Point(minX, maxY));
return boundingBoxFromPoints(this.points);
}
}
exports.Polygon = Polygon;
const Rectangle_1 = require("./Rectangle");
//# sourceMappingURL=Polygon.js.map

@@ -1,23 +0,30 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Rectangle = void 0;
const Point_1 = require("./Point");
const Polygon_1 = require("./Polygon");
class Rectangle extends Polygon_1.Polygon {
constructor(a = 0, b = 0, c = 0, d = 0) {
if (a instanceof Point_1.Point && b instanceof Point_1.Point && c instanceof Point_1.Point && d instanceof Point_1.Point) {
super([a, b, c, d]);
import { Point } from './Point';
import { Polygon } from './Polygon';
import { BoundsCorner, boundsFromPositionAndSize, createEmptyBounds } from './Bounds';
export class Rectangle extends Polygon {
static fromPositionAndSize(x, y, width, height) {
return new Rectangle(boundsFromPositionAndSize(x, y, width, height));
}
static fromPointAndSize(position, width, height) {
return new Rectangle(boundsFromPositionAndSize(position.x, position.y, width, height));
}
constructor(points) {
if (!points) {
points = createEmptyBounds();
}
else if (a instanceof Point_1.Point) {
super([a, new Point_1.Point(a.x + b, a.y), new Point_1.Point(a.x + b, a.y + c), new Point_1.Point(a.x, a.y + c)]);
}
else {
super(Rectangle.pointsFromBounds(a, b, c, d));
}
super([
points[BoundsCorner.TOP_LEFT],
points[BoundsCorner.TOP_RIGHT],
points[BoundsCorner.BOTTOM_RIGHT],
points[BoundsCorner.BOTTOM_LEFT]
]);
}
static pointsFromBounds(x, y, width, height) {
return [new Point_1.Point(x, y), new Point_1.Point(x + width, y), new Point_1.Point(x + width, y + height), new Point_1.Point(x, y + height)];
}
updateDimensions(x, y, width, height) {
this.points = Rectangle.pointsFromBounds(x, y, width, height);
const points = boundsFromPositionAndSize(x, y, width, height);
this.setPoints([
points[BoundsCorner.TOP_LEFT],
points[BoundsCorner.TOP_RIGHT],
points[BoundsCorner.BOTTOM_RIGHT],
points[BoundsCorner.BOTTOM_LEFT]
]);
}

@@ -43,12 +50,12 @@ setPoints(points) {

getTopMiddle() {
return Point_1.Point.middlePoint(this.getTopLeft(), this.getTopRight());
return Point.middlePoint(this.getTopLeft(), this.getTopRight());
}
getBottomMiddle() {
return Point_1.Point.middlePoint(this.getBottomLeft(), this.getBottomRight());
return Point.middlePoint(this.getBottomLeft(), this.getBottomRight());
}
getLeftMiddle() {
return Point_1.Point.middlePoint(this.getBottomLeft(), this.getTopLeft());
return Point.middlePoint(this.getBottomLeft(), this.getTopLeft());
}
getRightMiddle() {
return Point_1.Point.middlePoint(this.getBottomRight(), this.getTopRight());
return Point.middlePoint(this.getBottomRight(), this.getTopRight());
}

@@ -68,3 +75,2 @@ getTopLeft() {

}
exports.Rectangle = Rectangle;
//# sourceMappingURL=Rectangle.js.map
{
"name": "@projectstorm/geometry",
"version": "6.7.4",
"author": "dylanvorster",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/projectstorm/react-diagrams.git"
},
"scripts": {
"clean": "rimraf ./dist",
"build": "../../node_modules/.bin/webpack"
},
"publishConfig": {
"access": "public"
},
"keywords": [
"web",
"diagram",
"diagrams",
"react",
"typescript",
"flowchart",
"simple",
"links",
"nodes"
],
"main": "./dist/index.umd.js",
"module": "./dist/index.js",
"typings": "./dist/@types/index",
"gitHead": "dfcf82e69259b6bda0daecd330538b3bd4f043df"
}
"name": "@projectstorm/geometry",
"version": "7.0.0",
"author": "dylanvorster",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/projectstorm/react-diagrams.git"
},
"publishConfig": {
"access": "public"
},
"keywords": [
"web",
"diagram",
"diagrams",
"react",
"typescript",
"flowchart",
"simple",
"links",
"nodes"
],
"main": "./dist/index.umd.js",
"module": "./dist/index.js",
"typings": "./dist/@types/index",
"dependencies": {
"lodash": "^4.17.21"
},
"devDependencies": {
"@types/lodash": "^4.14.191"
},
"scripts": {
"clean": "rimraf ./dist",
"build": "../../node_modules/.bin/webpack"
}
}

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

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

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc