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

@devexpress/utils

Package Overview
Dependencies
Maintainers
38
Versions
40
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@devexpress/utils - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

lib/geometry/metrics.d.ts

5

lib/geometry/line-equation.d.ts

@@ -8,5 +8,8 @@ import { IPoint } from './interfaces';

constructor(aParam: number, bParam: number, cParam: number);
equals(obj: LineEquation): boolean;
getIntersection(equation: LineEquation): Point | null;
static fromPoints(pointA: IPoint, pointB: IPoint): LineEquation;
static intersection(a: LineEquation, b: LineEquation): Point | null;
static getIntersection(a: LineEquation, b: LineEquation): Point | null;
static equals(a: LineEquation, b: LineEquation): boolean;
}
//# sourceMappingURL=line-equation.d.ts.map

15

lib/geometry/line-equation.js

@@ -12,6 +12,14 @@ "use strict";

}
LineEquation.prototype.equals = function (obj) {
return this.aParam === obj.aParam &&
this.bParam === obj.bParam &&
this.cParam === obj.cParam;
};
LineEquation.prototype.getIntersection = function (equation) {
return LineEquation.getIntersection(this, equation);
};
LineEquation.fromPoints = function (pointA, pointB) {
return new LineEquation(pointB.y - pointA.y, pointA.x - pointB.x, pointB.x * pointA.y - pointA.x * pointB.y);
};
LineEquation.intersection = function (a, b) {
LineEquation.getIntersection = function (a, b) {
var A1 = a.aParam;

@@ -33,4 +41,9 @@ var B1 = a.bParam;

};
LineEquation.equals = function (a, b) {
return a.aParam === b.bParam &&
a.bParam === b.bParam &&
a.cParam === b.cParam;
};
return LineEquation;
}());
exports.LineEquation = LineEquation;
import { ICloneable, IEquatable, ISupportConverting, ISupportCopyFrom, SimpleConverter } from '../types';
import { IPoint } from './interfaces';
import { Vector } from './vector';
export declare type Offset = Point;

@@ -8,7 +7,7 @@ export declare class Point implements IPoint, ICloneable<Point>, ISupportCopyFrom<Point>, IEquatable<Point>, ISupportConverting<number> {

y: number;
static empty(): Point;
static zero(): Point;
constructor(x: number, y: number);
static fromNumber(num: number): Point;
isZero(): boolean;
toString(): string;
isEmpty(): boolean;
copyFrom(obj: Point): void;

@@ -20,13 +19,10 @@ clone(): Point;

multiply(multiplierX: number, multiplierY: number): this;
negative(): this;
applyConverter(converter: SimpleConverter): this;
rotate(angle: number, center: Point): this;
static plus(a: IPoint, b: IPoint): Point;
static minus(a: IPoint, b: IPoint): Point;
static distance(a: IPoint, b: IPoint): number;
static center(a: IPoint, b: IPoint): Point;
static xComparer(a: IPoint, b: IPoint): number;
static yComparer(a: IPoint, b: IPoint): number;
static equalsBinary(a: IPoint, b: IPoint): boolean;
readonly vector: Vector;
static equals(a: IPoint, b: IPoint): boolean;
}
//# sourceMappingURL=point.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Point = void 0;
var vector_1 = require("./vector");
var Point = (function () {

@@ -10,21 +9,14 @@ function Point(x, y) {

}
Point.empty = function () {
Point.zero = function () {
return new Point(0, 0);
};
Object.defineProperty(Point.prototype, "vector", {
get: function () {
return new vector_1.Vector(this.x, this.y);
},
enumerable: false,
configurable: true
});
Point.fromNumber = function (num) {
return new Point(num, num);
};
Point.prototype.isZero = function () {
return this.x === 0 && this.y === 0;
};
Point.prototype.toString = function () {
return JSON.stringify(this);
};
Point.prototype.isEmpty = function () {
return this.x === 0 && this.y === 0;
};
Point.prototype.copyFrom = function (obj) {

@@ -55,2 +47,7 @@ this.x = obj.x;

};
Point.prototype.negative = function () {
this.x *= -1;
this.y *= -1;
return this;
};
Point.prototype.applyConverter = function (converter) {

@@ -61,8 +58,2 @@ this.x = converter(this.x);

};
Point.prototype.rotate = function (angle, center) {
var x = center.x + (this.x - center.x) * Math.cos(angle) - (this.y - center.y) * Math.sin(angle);
this.y = center.y + (this.y - center.y) * Math.cos(angle) + (this.x - center.x) * Math.sin(angle);
this.x = x;
return this;
};
Point.plus = function (a, b) {

@@ -74,10 +65,2 @@ return new Point(a.x + b.x, a.y + b.y);

};
Point.distance = function (a, b) {
var xDist = a.x - b.x;
var yDist = a.y - b.y;
return Math.sqrt(xDist * xDist + yDist * yDist);
};
Point.center = function (a, b) {
return new Point(a.x + (b.x - a.x) / 2, a.y + (b.y - a.y) / 2);
};
Point.xComparer = function (a, b) {

@@ -89,3 +72,3 @@ return a.x - b.x;

};
Point.equalsBinary = function (a, b) {
Point.equals = function (a, b) {
return a.x === b.x && a.y === b.y;

@@ -92,0 +75,0 @@ };

@@ -1,23 +0,11 @@

import { ExtendedMinMax } from '../class/min-max';
import { IRectangle } from './interfaces';
import { Point } from './point';
import { Rectangle } from './rectangle';
import { Vector } from './vector';
export declare class Polygon {
points: Point[];
center: Point | null;
static fromRectangle(rect: IRectangle): Polygon;
getEdge(edgeIndex: number): Vector;
init(points: [
Point,
Point,
Point,
Point
], center: Point): this;
rotateAround(point: Point, angle: number, rightSC?: boolean, byClockwise?: boolean): this;
changeCoordinateCenterTo(p: Point): this;
projection(axis: Vector): ExtendedMinMax<Point>;
static collision(a: Polygon, b: Polygon): CollisionResult;
import { Segment } from './segment';
import { PolygonalChain } from './polygonal-chain';
export declare class Polygon<T extends Point = Point> extends PolygonalChain<T> {
points: T[];
static fromRectangle(rect: IRectangle): Polygon<Point>;
getEdge(edgeIndex: number): Segment;
static collision<T1 extends Point, T2 extends Point>(a: Polygon<T1>, b: Polygon<T2>): CollisionResult;
readonly numEdges: number;
readonly bounds: Rectangle;
}

@@ -24,0 +12,0 @@ export declare enum CollisionResult {

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CollisionResult = exports.Polygon = void 0;
var list_1 = require("../utils/list");
var tslib_1 = require("tslib");
var point_1 = require("./point");
var rectangle_1 = require("./rectangle");
var vector_1 = require("./vector");
var Polygon = (function () {
var segment_1 = require("./segment");
var polygonal_chain_1 = require("./polygonal-chain");
var Polygon = (function (_super) {
tslib_1.__extends(Polygon, _super);
function Polygon() {
this.points = [];
this.center = null;
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.points = [];
return _this;
}

@@ -23,3 +26,3 @@ Object.defineProperty(Polygon.prototype, "numEdges", {

var bottom = rect.y + rect.height;
return new Polygon().init([
return new Polygon([
new point_1.Point(rect.x, rect.y),

@@ -29,45 +32,7 @@ new point_1.Point(right, rect.y),

new point_1.Point(rect.x, bottom)
], rectangle_1.Rectangle.center(rect));
]);
};
Polygon.prototype.getEdge = function (edgeIndex) {
return new vector_1.Vector().initByPoint(this.points[edgeIndex], this.points[(edgeIndex + 1) % this.numEdges]);
return new segment_1.Segment(this.points[edgeIndex], this.points[(edgeIndex + 1) % this.numEdges]);
};
Polygon.prototype.init = function (points, center) {
this.points = points;
this.center = center;
return this;
};
Object.defineProperty(Polygon.prototype, "bounds", {
get: function () {
var top = list_1.ListUtils.minByCmp(this.points, point_1.Point.yComparer).y;
var left = list_1.ListUtils.minByCmp(this.points, point_1.Point.xComparer).x;
var right = list_1.ListUtils.maxByCmp(this.points, point_1.Point.xComparer).x;
var bottom = list_1.ListUtils.maxByCmp(this.points, point_1.Point.yComparer).y;
return new rectangle_1.Rectangle(left, top, right - left, bottom - top);
},
enumerable: false,
configurable: true
});
Polygon.prototype.rotateAround = function (point, angle, rightSC, byClockwise) {
if (rightSC === void 0) { rightSC = false; }
if (byClockwise === void 0) { byClockwise = true; }
var center = point.clone();
this.changeCoordinateCenterTo(center);
var sinFi = Math.sin(angle);
var cosFi = Math.cos(angle);
var sign = (rightSC ? 1 : 0) ^ (byClockwise ? 1 : 0) ? -1 : 1;
list_1.ListUtils.forEach(this.points, function (rp) {
return rp.copyFrom(new point_1.Point(rp.x * cosFi + sign * rp.y * sinFi, -sign * rp.x * sinFi + rp.y * cosFi));
});
this.changeCoordinateCenterTo(center.multiply(-1, -1));
return this;
};
Polygon.prototype.changeCoordinateCenterTo = function (p) {
var offset = p.clone().multiply(-1, -1);
list_1.ListUtils.forEach(this.points, function (rp) { return rp.offsetByPoint(offset); });
return this;
};
Polygon.prototype.projection = function (axis) {
return list_1.ListUtils.minMaxExtended(this.points, function (p) { return vector_1.Vector.scalarProduct(p, axis); });
};
Polygon.collision = function (a, b) {

@@ -79,3 +44,4 @@ var edgeCountA = a.numEdges;

var edge = edgeIndex < edgeCountA ? a.getEdge(edgeIndex) : b.getEdge(edgeIndex - edgeCountA);
var axis = new vector_1.Vector(-edge.y, edge.x).normalize();
var edgeVector = vector_1.Vector.fromSegment(edge);
var axis = new vector_1.Vector(-edgeVector.y, edgeVector.x).normalize();
var projectionA = a.projection(axis);

@@ -94,3 +60,3 @@ var projectionB = b.projection(axis);

return Polygon;
}());
}(polygonal_chain_1.PolygonalChain));
exports.Polygon = Polygon;

@@ -97,0 +63,0 @@ var CollisionResult;

@@ -12,4 +12,8 @@ import { Flag } from '../class/flag';

height: number;
static empty(): Rectangle;
constructor(x: number, y: number, width: number, height: number);
createRectangle(): Rectangle;
createSize(): Size;
createPosition(): Point;
createVerticalInterval(): FixedInterval;
createHorizontalInterval(): FixedInterval;
static fromGeometry(point: IPoint, size: ISize): Rectangle;

@@ -28,3 +32,3 @@ static fromPoints(pointA: IPoint, pointB: IPoint): Rectangle;

resize(deltaX: number, deltaY: number): this;
normalizeSize(): this;
nonNegativeSize(): this;
multiply(multiplierX: number, multiplierY: number): this;

@@ -47,5 +51,5 @@ equals(obj: IRectangle): boolean;

static getNonCollapsedIntersection(objA: Rectangle, objB: Rectangle): Rectangle | null;
static isIntersect(rectA: IRectangle, rectB: IRectangle): boolean;
static areIntersected(rectA: IRectangle, rectB: IRectangle): boolean;
static union(rectA: IRectangle, rectB: IRectangle): Rectangle;
static equalsBinary(a: IRectangle, b: IRectangle): boolean;
static equals(a: IRectangle, b: IRectangle): boolean;
static center(rect: IRectangle): Point;

@@ -55,8 +59,3 @@ static containsPoint(rect: IRectangle, point: IPoint): boolean;

readonly bottom: number;
readonly verticalInterval: FixedInterval;
readonly horizontalInterval: FixedInterval;
readonly center: Point;
readonly rectangle: Rectangle;
readonly size: Size;
readonly position: Point;
}

@@ -63,0 +62,0 @@ export declare enum HitTestDeviation {

@@ -16,5 +16,2 @@ "use strict";

}
Rectangle.empty = function () {
return new Rectangle(0, 0, 0, 0);
};
Object.defineProperty(Rectangle.prototype, "right", {

@@ -34,16 +31,2 @@ get: function () {

});
Object.defineProperty(Rectangle.prototype, "verticalInterval", {
get: function () {
return new fixed_1.FixedInterval(this.y, this.height);
},
enumerable: false,
configurable: true
});
Object.defineProperty(Rectangle.prototype, "horizontalInterval", {
get: function () {
return new fixed_1.FixedInterval(this.x, this.width);
},
enumerable: false,
configurable: true
});
Object.defineProperty(Rectangle.prototype, "center", {

@@ -56,23 +39,17 @@ get: function () {

});
Object.defineProperty(Rectangle.prototype, "rectangle", {
get: function () {
return new Rectangle(this.x, this.y, this.width, this.height);
},
enumerable: false,
configurable: true
});
Object.defineProperty(Rectangle.prototype, "size", {
get: function () {
return new size_1.Size(this.width, this.height);
},
enumerable: false,
configurable: true
});
Object.defineProperty(Rectangle.prototype, "position", {
get: function () {
return new point_1.Point(this.x, this.y);
},
enumerable: false,
configurable: true
});
Rectangle.prototype.createRectangle = function () {
return new Rectangle(this.x, this.y, this.width, this.height);
};
Rectangle.prototype.createSize = function () {
return new size_1.Size(this.width, this.height);
};
Rectangle.prototype.createPosition = function () {
return new point_1.Point(this.x, this.y);
};
Rectangle.prototype.createVerticalInterval = function () {
return new fixed_1.FixedInterval(this.y, this.height);
};
Rectangle.prototype.createHorizontalInterval = function () {
return new fixed_1.FixedInterval(this.x, this.width);
};
Rectangle.fromGeometry = function (point, size) {

@@ -140,3 +117,3 @@ return new Rectangle(point.x, point.y, size.width, size.height);

};
Rectangle.prototype.normalizeSize = function () {
Rectangle.prototype.nonNegativeSize = function () {
if (this.width < 0)

@@ -156,6 +133,6 @@ this.width = 0;

Rectangle.prototype.equals = function (obj) {
return Rectangle.equalsBinary(this, obj);
return Rectangle.equals(this, obj);
};
Rectangle.prototype.clone = function () {
var rect = Rectangle.empty();
var rect = new Rectangle(0, 0, 0, 0);
rect.copyFrom(this);

@@ -264,3 +241,3 @@ return rect;

};
Rectangle.isIntersect = function (rectA, rectB) {
Rectangle.areIntersected = function (rectA, rectB) {
return !(rectA.x > rectB.x + rectB.width || rectB.x > rectA.x + rectA.width) &&

@@ -276,3 +253,3 @@ !(rectA.y > rectB.y + rectB.height || rectB.y > rectA.y + rectA.height);

};
Rectangle.equalsBinary = function (a, b) {
Rectangle.equals = function (a, b) {
return a.x === b.x &&

@@ -279,0 +256,0 @@ a.y === b.y &&

import { IPoint, IRectangle } from './interfaces';
import { Point } from './point';
import { Vector } from './vector';
export declare class Segment<T extends Point = Point> {

@@ -8,5 +7,5 @@ startPoint: T;

constructor(startPoint: T, endPoint: T);
intersect<AnotherT extends Point>(segment: Segment<AnotherT>): boolean;
intersectPoint(point: IPoint, accuracy?: number): boolean;
intersectRect(rect: IRectangle): boolean;
isIntersected<AnotherT extends Point>(segment: Segment<AnotherT>): boolean;
containsPoint(point: IPoint, accuracy?: number): boolean;
isIntersectedByRect(rect: IRectangle): boolean;
private intersectCore;

@@ -17,4 +16,3 @@ readonly length: number;

readonly center: Point;
readonly vector: Vector;
}
//# sourceMappingURL=segment.d.ts.map

@@ -5,5 +5,5 @@ "use strict";

var math_1 = require("../utils/math");
var metrics_1 = require("./metrics");
var point_1 = require("./point");
var rectangle_1 = require("./rectangle");
var vector_1 = require("./vector");
var Segment = (function () {

@@ -16,3 +16,3 @@ function Segment(startPoint, endPoint) {

get: function () {
return point_1.Point.distance(this.startPoint, this.endPoint);
return metrics_1.Metrics.euclideanDistance(this.startPoint, this.endPoint);
},

@@ -43,10 +43,3 @@ enumerable: false,

});
Object.defineProperty(Segment.prototype, "vector", {
get: function () {
return new vector_1.Vector(this.endPoint.x - this.startPoint.x, this.endPoint.y - this.startPoint.y);
},
enumerable: false,
configurable: true
});
Segment.prototype.intersect = function (segment) {
Segment.prototype.isIntersected = function (segment) {
return this.startPoint.equals(segment.startPoint) || this.endPoint.equals(segment.startPoint) ||

@@ -56,8 +49,8 @@ this.startPoint.equals(segment.endPoint) || this.endPoint.equals(segment.endPoint) ||

};
Segment.prototype.intersectPoint = function (point, accuracy) {
Segment.prototype.containsPoint = function (point, accuracy) {
if (accuracy === void 0) { accuracy = 0.0000001; }
return this.startPoint.equals(point) || this.endPoint.equals(point) ||
math_1.MathUtils.numberCloseTo(this.length, point_1.Point.distance(this.startPoint, point) + point_1.Point.distance(this.endPoint, point), accuracy);
math_1.MathUtils.numberCloseTo(this.length, metrics_1.Metrics.euclideanDistance(this.startPoint, point) + metrics_1.Metrics.euclideanDistance(this.endPoint, point), accuracy);
};
Segment.prototype.intersectRect = function (rect) {
Segment.prototype.isIntersectedByRect = function (rect) {
if (rectangle_1.Rectangle.containsPoint(rect, this.startPoint) || rectangle_1.Rectangle.containsPoint(rect, this.endPoint))

@@ -69,6 +62,6 @@ return true;

var bottom = rect.y + rect.height;
return this.intersect(new Segment(new point_1.Point(left, top), new point_1.Point(left, bottom))) ||
this.intersect(new Segment(new point_1.Point(right, top), new point_1.Point(right, bottom))) ||
this.intersect(new Segment(new point_1.Point(left, top), new point_1.Point(right, top))) ||
this.intersect(new Segment(new point_1.Point(left, bottom), new point_1.Point(right, bottom)));
return this.isIntersected(new Segment(new point_1.Point(left, top), new point_1.Point(left, bottom))) ||
this.isIntersected(new Segment(new point_1.Point(right, top), new point_1.Point(right, bottom))) ||
this.isIntersected(new Segment(new point_1.Point(left, top), new point_1.Point(right, top))) ||
this.isIntersected(new Segment(new point_1.Point(left, bottom), new point_1.Point(right, bottom)));
};

@@ -75,0 +68,0 @@ Segment.prototype.intersectCore = function (segment) {

@@ -12,3 +12,3 @@ import { ICloneable, IEquatable, ISupportCopyFrom, SimpleConverter } from '../types';

toString(): string;
normalizeSize(): this;
nonNegativeSize(): this;
offset(offsetWidth: number, offsetHeight: number): this;

@@ -20,4 +20,4 @@ multiply(multiplierW: number, multiplierH: number): this;

applyConverter(conv: SimpleConverter): this;
static equalsBinary(a: ISize, b: ISize): boolean;
static equals(a: ISize, b: ISize): boolean;
}
//# sourceMappingURL=size.d.ts.map

@@ -26,3 +26,3 @@ "use strict";

};
Size.prototype.normalizeSize = function () {
Size.prototype.nonNegativeSize = function () {
if (this.width < 0)

@@ -59,3 +59,3 @@ this.width = 0;

};
Size.equalsBinary = function (a, b) {
Size.equals = function (a, b) {
return a.width === b.width && a.height === b.height;

@@ -62,0 +62,0 @@ };

import { Point } from './point';
import { Segment } from './segment';
export declare class Vector {

@@ -6,4 +7,6 @@ x: number;

constructor(x?: number, y?: number);
initByPoint(a: Point, b: Point): Vector;
static fromPoints(begin: Point, end: Point): Vector;
static fromSegment(segment: Segment): Vector;
normalize(): Vector;
negative(): this;
static angleBetween(a: Vector, b: Vector): number;

@@ -10,0 +13,0 @@ static scalarProduct(a: Point | Vector, b: Point | Vector): number;

@@ -18,7 +18,8 @@ "use strict";

});
Vector.prototype.initByPoint = function (a, b) {
this.x = b.x - a.x;
this.y = b.y - a.y;
return this;
Vector.fromPoints = function (begin, end) {
return new Vector(end.x - begin.x, end.y - begin.y);
};
Vector.fromSegment = function (segment) {
return new Vector(segment.endPoint.x - segment.startPoint.x, segment.endPoint.y - segment.startPoint.y);
};
Vector.prototype.normalize = function () {

@@ -32,2 +33,7 @@ var length = this.length;

};
Vector.prototype.negative = function () {
this.x *= -1;
this.y *= -1;
return this;
};
Object.defineProperty(Vector, "axisX", {

@@ -34,0 +40,0 @@ get: function () {

{
"name": "@devexpress/utils",
"version": "1.0.0",
"version": "1.1.0",
"description": "DevExpress utils",

@@ -5,0 +5,0 @@ "author": "DevExpress Inc.",

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

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