You're Invited:Meet the Socket Team at RSAC and BSidesSF 2026, March 23–26.RSVP
Socket
Book a DemoSign in
Socket

@leafer/math

Package Overview
Dependencies
Maintainers
1
Versions
117
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@leafer/math - npm Package Compare versions

Comparing version
1.0.0-alpha.10
to
1.0.0-alpha.21
+2
-2
package.json
{
"name": "@leafer/math",
"version": "1.0.0-alpha.10",
"version": "1.0.0-alpha.21",
"description": "@leafer/math",

@@ -22,4 +22,4 @@ "author": "Chao (Leafer) Wan",

"devDependencies": {
"@leafer/interface": "1.0.0-alpha.10"
"@leafer/interface": "1.0.0-alpha.21"
}
}

@@ -30,10 +30,9 @@ import { IBounds, IBoundsData, IMatrixData, IPointData, IBoundsDataHandle, IObject, IMatrix, IRadiusPointData } from '@leafer/interface'

public timesMatrix(matrix: IMatrixData): IBounds {
B.timesMatrix(this, matrix)
public scale(scale: number): IBounds {
B.scale(this, scale)
return this
}
public divideMatrix(matrix: IMatrixData): IBounds {
B.divideMatrix(this, matrix)
public toWorld(matrix: IMatrixData, to: IBoundsData): IBounds {
B.toWorld(this, matrix, to)
return this

@@ -46,8 +45,10 @@ }

public spread(size: number): void {
public spread(size: number): IBounds {
B.spread(this, size)
return this
}
public ceil(): void {
public ceil(): IBounds {
B.ceil(this)
return this
}

@@ -57,28 +58,30 @@

public add(bounds: IBoundsData): void {
public add(bounds: IBoundsData): IBounds {
B.add(this, bounds)
return this
}
public addList(boundsList: IBounds[]): void {
public addList(boundsList: IBounds[]): IBounds {
B.setByList(this, boundsList, true)
return this
}
public setByList(boundsList: IBounds[], addMode?: boolean): void {
public setByList(boundsList: IBounds[], addMode?: boolean): IBounds {
B.setByList(this, boundsList, addMode)
return this
}
public addListWithHandle(list: IObject[], boundsDataHandle: IBoundsDataHandle): void {
public addListWithHandle(list: IObject[], boundsDataHandle: IBoundsDataHandle): IBounds {
B.setByListWithHandle(this, list, boundsDataHandle, true)
return this
}
public setByListWithHandle(list: IObject[], boundsDataHandle: IBoundsDataHandle, addMode?: boolean): void {
public setByListWithHandle(list: IObject[], boundsDataHandle: IBoundsDataHandle, addMode?: boolean): IBounds {
B.setByListWithHandle(this, list, boundsDataHandle, addMode)
return this
}
public setByBoundsTimesMatrix(fromBounds: IBoundsData, fromMatrix: IMatrixData): void {
B.setByBoundsTimesMatrix(this, fromBounds, fromMatrix)
}
public setByPoints(points: IPointData[]): void {
public setByPoints(points: IPointData[]): IBounds {
B.setByPoints(this, points)
return this
}

@@ -105,2 +108,7 @@

public intersect(bounds: IBoundsData, boundsMatrix?: IMatrixData): IBounds {
B.intersect(this, bounds, boundsMatrix)
return this
}
public getIntersect(bounds: IBoundsData, boundsMatrix?: IMatrixData): IBounds {

@@ -110,8 +118,3 @@ return new Bounds(B.getIntersectData(this, bounds, boundsMatrix))

public setByIntersect(bounds: IBoundsData, boundsMatrix?: IMatrixData): void {
B.setByIntersect(this, bounds, boundsMatrix)
}
public isSame(bounds: IBoundsData): boolean {

@@ -118,0 +121,0 @@ return B.isSame(this, bounds)

@@ -64,19 +64,60 @@ import { IPointData, IBoundsData, IMatrixData, IBoundsDataHandle, IObject, IMatrix, IOffsetBoundsData, IRadiusPointData } from '@leafer/interface'

tempTimesMatrix(t: IBoundsData, matrix: IMatrixData): IBoundsData {
scale(t: IBoundsData, scale: number): void {
t.x *= scale
t.y *= scale
t.width *= scale
t.height *= scale
},
tempToWorld(t: IBoundsData, matrix: IMatrixData): IBoundsData {
B.copy(B.tempBounds, t)
B.setByBoundsTimesMatrix(B.tempBounds, B.tempBounds, matrix)
B.toWorld(B.tempBounds, matrix)
return B.tempBounds
},
timesMatrix(t: IBoundsData, matrix: IMatrixData): void {
B.setByBoundsTimesMatrix(t, t, matrix)
},
getByTimesMatrix(t: IBoundsData, matrix: IMatrixData): IBoundsData {
getWorld(t: IBoundsData, matrix: IMatrixData): IBoundsData {
t = { ...t }
B.setByBoundsTimesMatrix(t, t, matrix)
B.toWorld(t, matrix)
return t
},
divideMatrix(t: IBoundsData, matrix: IMatrixData): void {
toWorld(t: IBoundsData, matrix: IMatrixData, to?: IBoundsData): void {
to || (to = t)
if (matrix.b === 0 && matrix.c === 0) {
to.x = matrix.e + t.x * matrix.a
to.y = matrix.f + t.y * matrix.d
to.width = t.width * matrix.a
to.height = t.height * matrix.d
} else {
point.x = t.x
point.y = t.y
toWorldPoint(matrix, point, toPoint)
setPoint(tempPointBounds, toPoint.x, toPoint.y)
point.x = t.x + t.width
toWorldPoint(matrix, point, toPoint)
addPoint(tempPointBounds, toPoint.x, toPoint.y)
point.y = t.y + t.height
toWorldPoint(matrix, point, toPoint)
addPoint(tempPointBounds, toPoint.x, toPoint.y)
point.x = t.x
toWorldPoint(matrix, point, toPoint)
addPoint(tempPointBounds, toPoint.x, toPoint.y)
toBounds(tempPointBounds, to)
}
},
/**toLocal(t: IBoundsData, matrix: IMatrixData): void {
t.x = (t.x - matrix.e) / matrix.a

@@ -86,3 +127,3 @@ t.y = (t.y - matrix.f) / matrix.d

t.height /= matrix.d
},
},*/

@@ -158,39 +199,2 @@ getFitMatrix(t: IBoundsData, put: IBoundsData): IMatrix {

setByBoundsTimesMatrix(t: IBoundsData, bounds: IBoundsData, matrix: IMatrixData): void {
if (matrix.b === 0 && matrix.c === 0) {
t.x = matrix.e + bounds.x * matrix.a
t.y = matrix.f + bounds.y * matrix.d
t.width = bounds.width * matrix.a
t.height = bounds.height * matrix.d
} else {
point.x = bounds.x
point.y = bounds.y
toWorldPoint(matrix, point, toPoint)
setPoint(tempPointBounds, toPoint.x, toPoint.y)
point.x = bounds.x + bounds.width
toWorldPoint(matrix, point, toPoint)
addPoint(tempPointBounds, toPoint.x, toPoint.y)
point.y = bounds.y + bounds.height
toWorldPoint(matrix, point, toPoint)
addPoint(tempPointBounds, toPoint.x, toPoint.y)
point.x = bounds.x
toWorldPoint(matrix, point, toPoint)
addPoint(tempPointBounds, toPoint.x, toPoint.y)
toBounds(tempPointBounds, t)
}
},
setByPoints(t: IBoundsData, points: IPointData[]): void {

@@ -215,3 +219,3 @@ points.forEach((point, index) => {

hit(t: IBoundsData, other: IBoundsData, otherMatrix?: IMatrixData): boolean {
if (otherMatrix) other = B.tempTimesMatrix(other, otherMatrix)
if (otherMatrix) other = B.tempToWorld(other, otherMatrix)
return !((t.y + t.height < other.y) || (other.y + other.height < t.y) || (t.x + t.width < other.x) || (other.x + other.width < t.x))

@@ -221,3 +225,3 @@ },

includes(t: IBoundsData, other: IBoundsData, otherMatrix?: IMatrixData): boolean {
if (otherMatrix) other = B.tempTimesMatrix(other, otherMatrix)
if (otherMatrix) other = B.tempToWorld(other, otherMatrix)
return (t.x <= other.x) && (t.y <= other.y) && (t.x + t.width >= other.x + other.width) && (t.y + t.height >= other.y + other.height)

@@ -227,3 +231,3 @@ },

getIntersectData(t: IBoundsData, other: IBoundsData, otherMatrix?: IMatrixData): IBoundsData {
if (otherMatrix) other = B.tempTimesMatrix(other, otherMatrix)
if (otherMatrix) other = B.tempToWorld(other, otherMatrix)
let { x, y, width, height } = other

@@ -247,3 +251,3 @@

setByIntersect(t: IBoundsData, other: IBoundsData, otherMatrix?: IMatrixData): void {
intersect(t: IBoundsData, other: IBoundsData, otherMatrix?: IMatrixData): void {
B.copy(t, B.getIntersectData(t, other, otherMatrix))

@@ -250,0 +254,0 @@ },

@@ -49,21 +49,24 @@ import { IMatrix, IMatrixData, IPointData } from '@leafer/interface'

public times(matrix: IMatrixData): void {
public times(matrix: IMatrixData): IMatrix {
M.times(this, matrix)
return this
}
public divide(matrix: IMatrixData): void {
public divide(matrix: IMatrixData): IMatrix {
M.divide(this, matrix)
return this
}
public invert(): void {
public invert(): IMatrix {
M.invert(this)
return this
}
public toWorldPoint(local: IPointData, world?: IPointData): void {
M.toWorldPoint(this, local, world)
public toWorldPoint(local: IPointData, to?: IPointData): void {
M.toWorldPoint(this, local, to)
}
public toLocalPoint(world: IPointData, local?: IPointData): void {
M.toLocalPoint(this, world, local)
public toLocalPoint(world: IPointData, to?: IPointData): void {
M.toLocalPoint(this, world, to)
}

@@ -70,0 +73,0 @@

@@ -92,12 +92,12 @@ import { IMatrix, IMatrixData, IPointData } from '@leafer/interface'

toWorldPoint(t: IMatrixData, local: IPointData, setWorld?: IPointData): void {
toWorldPoint(t: IMatrixData, local: IPointData, to?: IPointData): void {
const { x, y } = local
// world
setWorld || (setWorld = local)
setWorld.x = (x * t.a) + (y * t.c) + t.e
setWorld.y = (x * t.b) + (y * t.d) + t.f
to || (to = local)
to.x = (x * t.a) + (y * t.c) + t.e
to.y = (x * t.b) + (y * t.d) + t.f
},
toLocalPoint(t: IMatrixData, world: IPointData, setLocal?: IPointData, fromOrigin?: boolean): void {
toLocalPoint(t: IMatrixData, world: IPointData, to?: IPointData, fromOrigin?: boolean): void {
const { x, y } = world

@@ -108,10 +108,10 @@ const { a, b, c, d } = t

// local
setLocal || (setLocal = world)
setLocal.x = (x * d - y * c) * s
setLocal.y = (y * a - x * b) * s
to || (to = world)
to.x = (x * d - y * c) * s
to.y = (y * a - x * b) * s
if (!fromOrigin) {
const { e, f } = t
setLocal.x -= (e * d - f * c) * s
setLocal.y -= (f * a - e * b) * s
to.x -= (e * d - f * c) * s
to.y -= (f * a - e * b) * s
}

@@ -118,0 +118,0 @@ },

@@ -26,13 +26,16 @@ import { IPoint, IPointData, IMatrixData } from '@leafer/interface'

public rotate(angle: number, center?: IPointData): void {
public rotate(angle: number, center?: IPointData): IPoint {
P.rotate(this, angle, center)
return this
}
public toLocal(matrix: IMatrixData, setLocal?: IPointData): void {
P.toLocal(this, matrix, setLocal)
public toLocal(matrix: IMatrixData, to?: IPointData): IPoint {
P.toLocal(this, matrix, to)
return this
}
public toWorld(matrix: IMatrixData, setWorld?: IPointData): void {
P.toWorld(this, matrix, setWorld)
public toWorld(matrix: IMatrixData, to?: IPointData): IPoint {
P.toWorld(this, matrix, to)
return this
}

@@ -39,0 +42,0 @@

@@ -52,16 +52,16 @@ import { IPointData, IMatrixData, IRadiusPointData } from '@leafer/interface'

toLocalRadiusPoint(t: IRadiusPointData, matrix: IMatrixData, setLocal?: IRadiusPointData): void {
setLocal || (setLocal = t)
toLocalPoint(matrix, t, setLocal)
setLocal.radiusX = t.radiusX / matrix.a
setLocal.radiusY = t.radiusY / matrix.d
toLocalRadiusPoint(t: IRadiusPointData, matrix: IMatrixData, to?: IRadiusPointData): void {
to || (to = t)
toLocalPoint(matrix, t, to)
to.radiusX = t.radiusX / matrix.a
to.radiusY = t.radiusY / matrix.d
},
toLocal(t: IPointData, matrix: IMatrixData, setLocal?: IPointData): void {
toLocalPoint(matrix, t, setLocal)
toLocal(t: IPointData, matrix: IMatrixData, to?: IPointData): void {
toLocalPoint(matrix, t, to)
},
toWorld(t: IPointData, matrix: IMatrixData, setWorld?: IPointData): void {
toWorldPoint(matrix, t, setWorld)
toWorld(t: IPointData, matrix: IMatrixData, to?: IPointData): void {
toWorldPoint(matrix, t, to)
},

@@ -68,0 +68,0 @@