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-rc.9
to
1.0.0-rc.10
+2
-2
package.json
{
"name": "@leafer/math",
"version": "1.0.0-rc.9",
"version": "1.0.0-rc.10",
"description": "@leafer/math",

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

"devDependencies": {
"@leafer/interface": "1.0.0-rc.9"
"@leafer/interface": "1.0.0-rc.10"
}
}

@@ -36,2 +36,7 @@ import { IBounds, IBoundsData, IMatrixData, IPointData, IBoundsDataFn, IObject, IMatrix, IRadiusPointData, IMatrixWithLayoutData } from '@leafer/interface'

public move(x: number, y: number): IBounds {
B.move(this, x, y)
return this
}
public scale(scaleX: number, scaleY?: number): IBounds {

@@ -52,2 +57,7 @@ B.scale(this, scaleX, scaleY)

public toInnerOf(matrix: IMatrixData, to?: IBoundsData): IBounds {
B.toInnerOf(this, matrix, to)
return this
}
public getFitMatrix(put: IBoundsData): IMatrix {

@@ -72,2 +82,6 @@ return B.getFitMatrix(this, put)

public float(maxLength?: number): IBounds {
B.float(this, maxLength)
return this
}

@@ -74,0 +88,0 @@

@@ -6,2 +6,3 @@ import { IPointData, IBoundsData, IMatrixData, IBoundsDataFn, IObject, IMatrix, IOffsetBoundsData, IRadiusPointData, IMatrixWithScaleData } from '@leafer/interface'

import { PointHelper as P } from './PointHelper'
import { MathHelper, getBoundsData } from './MathHelper'

@@ -11,2 +12,4 @@

const { toOuterPoint } = M
const { float } = MathHelper
const { floor, ceil } = Math

@@ -78,5 +81,4 @@ let right: number, bottom: number, boundsRight: number, boundsBottom: number

scale(t: IBoundsData, scaleX: number, scaleY: number = scaleX): void {
if (t.x) t.x *= scaleX
if (t.y) t.y *= scaleY
scale(t: IBoundsData, scaleX: number, scaleY = scaleX): void {
P.scale(t, scaleX, scaleY)
t.width *= scaleX

@@ -86,5 +88,4 @@ t.height *= scaleY

scaleOf(t: IBoundsData, origin: IPointData, scaleX: number, scaleY?: number): void {
t.x += (t.x - origin.x) * (scaleX - 1)
t.y += (t.y - origin.y) * (scaleY - 1)
scaleOf(t: IBoundsData, origin: IPointData, scaleX: number, scaleY = scaleX): void {
P.scaleOf(t, origin, scaleX, scaleY)
t.width *= scaleX

@@ -156,2 +157,8 @@ t.height *= scaleY

toInnerOf(t: IBoundsData, matrix: IMatrixData, to?: IBoundsData): void {
to || (to = t)
B.move(to, -matrix.e, -matrix.f)
B.scale(to, 1 / matrix.a, 1 / matrix.d)
},
getFitMatrix(t: IBoundsData, put: IBoundsData): IMatrix {

@@ -174,6 +181,7 @@ const scale = Math.min(1, Math.min(t.width / put.width, t.height / put.height))

ceil(t: IBoundsData): void {
t.x = Math.floor(t.x)
t.y = Math.floor(t.y)
t.width = Math.ceil(t.width)
t.height = Math.ceil(t.height)
const { x, y } = t
t.x = floor(t.x)
t.y = floor(t.y)
t.width = x > t.x ? ceil(t.width + x - t.x) : ceil(t.width)
t.height = y > t.y ? ceil(t.height + y - t.y) : ceil(t.height)
},

@@ -192,2 +200,8 @@

float(t: IBoundsData, maxLength?: number): void {
t.x = float(t.x, maxLength)
t.y = float(t.y, maxLength)
t.width = float(t.width, maxLength)
t.height = float(t.height, maxLength)
},

@@ -278,2 +292,4 @@ add(t: IBoundsData, bounds: IBoundsData): void {

if (otherMatrix) other = B.tempToOuterOf(other, otherMatrix)
if (!B.hit(t, other)) return getBoundsData()
let { x, y, width, height } = other

@@ -280,0 +296,0 @@

@@ -13,5 +13,5 @@ export { IncrementId } from './IncrementId'

export { MatrixHelper } from './MatrixHelper'
export { MathHelper, OneRadian, PI2, PI_2 } from './MathHelper'
export { MathHelper, OneRadian, PI2, PI_2, getPointData, getBoundsData, getMatrixData } from './MathHelper'
export { StringNumberMap } from './StringNumber'
export { Direction4, Direction9 } from './Direction'

@@ -0,1 +1,3 @@

import { IPointData, IBoundsData, IMatrixData } from '@leafer/interface'
const { round, pow, PI } = Math

@@ -44,3 +46,3 @@

}
return rotation
return MathHelper.float(rotation)
},

@@ -67,2 +69,6 @@

export const PI2 = PI * 2
export const PI_2 = PI / 2
export const PI_2 = PI / 2
export function getPointData(): IPointData { return { x: 0, y: 0 } }
export function getBoundsData(): IBoundsData { return { x: 0, y: 0, width: 0, height: 0 } }
export function getMatrixData(): IMatrixData { return { a: 1, b: 0, c: 0, d: 1, e: 0, f: 0 } }

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

import { IMatrix, IMatrixData, IPointData, ILayoutData } from '@leafer/interface'
import { IMatrix, IMatrixData, IPointData, ILayoutData, IMatrixWithScaleData } from '@leafer/interface'
import { MatrixHelper as M } from './MatrixHelper'

@@ -134,2 +134,5 @@

public withScale(scaleX?: number, scaleY?: number): IMatrixWithScaleData {
return M.withScale(this, scaleX, scaleY)
}

@@ -136,0 +139,0 @@ public reset(): void {

@@ -1,3 +0,3 @@

import { IMatrixData, IPointData, ILayoutData, IMatrixWithLayoutData } from '@leafer/interface'
import { MathHelper, OneRadian, PI_2 } from './MathHelper'
import { IMatrixData, IPointData, ILayoutData, IMatrixWithLayoutData, IMatrixWithOptionScaleData, IScaleData, IMatrixWithScaleData } from '@leafer/interface'
import { MathHelper, OneRadian, PI_2, getBoundsData, getMatrixData } from './MathHelper'

@@ -9,8 +9,4 @@

function get(): IMatrixData {
return { a: 1, b: 0, c: 0, d: 1, e: 0, f: 0 }
}
function getWorld(): IMatrixWithLayoutData {
return { ...get(), x: 0, y: 0, width: 0, height: 0, scaleX: 1, scaleY: 1, rotation: 0, skewX: 0, skewY: 0 }
return { ...getMatrixData(), ...getBoundsData(), scaleX: 1, scaleY: 1, rotation: 0, skewX: 0, skewY: 0 }
}

@@ -20,3 +16,3 @@

defaultMatrix: get(),
defaultMatrix: getMatrixData(),

@@ -36,3 +32,3 @@ defaultWorld: getWorld(),

get,
get: getMatrixData,

@@ -143,3 +139,3 @@ getWorld,

multiplyParent(t: IMatrixData, parent: IMatrixData, to?: IMatrixData, abcdChanged?: boolean | number, childLayout?: ILayoutData): void { // = transform
multiplyParent(t: IMatrixWithOptionScaleData, parent: IMatrixWithOptionScaleData, to?: IMatrixWithOptionScaleData, abcdChanged?: boolean | number, childScaleData?: IScaleData): void { // = transform
const { e, f } = t

@@ -159,3 +155,6 @@

if (childLayout) M.multiplyParentLayout(to as unknown as ILayoutData, parent as unknown as ILayoutData, childLayout)
if (childScaleData) {
to.scaleX = parent.scaleX * childScaleData.scaleX
to.scaleY = parent.scaleY * childScaleData.scaleY
}

@@ -168,3 +167,6 @@ } else {

if (childLayout) M.multiplyParentLayout(to as unknown as ILayoutData, parent as unknown as ILayoutData)
if (childScaleData) {
to.scaleX = parent.scaleX
to.scaleY = parent.scaleY
}
}

@@ -176,20 +178,3 @@

multiplyParentLayout(t: ILayoutData, parent: ILayoutData, child?: ILayoutData): void {
if (child) {
t.scaleX = parent.scaleX * child.scaleX
t.scaleY = parent.scaleY * child.scaleY
t.rotation = parent.rotation + child.rotation
t.skewX = parent.skewX + child.skewX
t.skewY = parent.skewY + child.skewY
} else {
t.scaleX = parent.scaleX
t.scaleY = parent.scaleY
t.rotation = parent.rotation
t.skewX = parent.skewX
t.skewY = parent.skewY
}
},
divide(t: IMatrixData, child: IMatrixData): void {

@@ -338,8 +323,8 @@ M.multiply(t, M.tempInvert(child))

const cosR = cos(rotation)
const cosR = float(cos(rotation)) // when -90 / 90 is 0
const sinR = sin(rotation)
scaleX = float(scaleX), scaleY = float(scaleY)
skewX = float((c / scaleY + sinR) / cosR / OneRadian)
skewY = float((b / scaleX - sinR) / cosR / OneRadian)
skewX = cosR ? float((c / scaleY + sinR) / cosR / OneRadian, 9) : 0
skewY = cosR ? float((b / scaleX - sinR) / cosR / OneRadian, 9) : 0
rotation = float(rotation / OneRadian)

@@ -361,2 +346,19 @@

withScale(t: IMatrixData, scaleX?: number, scaleY = scaleX): IMatrixWithScaleData {
const world = t as unknown as IMatrixWithScaleData
if (!scaleX || !scaleY) {
const { a, b, c, d } = t
if (b || c) {
scaleX = sqrt(a * a + b * b)
scaleY = (a * d - b * c) / scaleX
} else {
scaleX = a
scaleY = d
}
}
world.scaleX = scaleX
world.scaleY = scaleY
return world
},
reset(t: IMatrixData): void {

@@ -363,0 +365,0 @@ M.set(t)

@@ -29,2 +29,17 @@ import { IPoint, IPointData, IMatrixData } from '@leafer/interface'

public move(x: number, y: number): IPoint {
P.move(this, x, y)
return this
}
public scale(scaleX: number, scaleY?: number): IPoint {
P.scale(this, scaleX, scaleY)
return this
}
public scaleOf(origin: IPointData, scaleX: number, scaleY?: number): IPoint {
P.scaleOf(this, origin, scaleX, scaleY)
return this
}
public rotate(rotation: number, origin?: IPointData): IPoint {

@@ -31,0 +46,0 @@ P.rotate(this, rotation, origin)

import { IPointData, IMatrixData, IRadiusPointData, IMatrixWithScaleData } from '@leafer/interface'
import { OneRadian, PI2 } from './MathHelper'
import { OneRadian, PI2, getPointData } from './MathHelper'

@@ -13,3 +13,3 @@ import { MatrixHelper as M } from './MatrixHelper'

defaultPoint: { x: 0, y: 0 } as IPointData,
defaultPoint: getPointData(),

@@ -39,2 +39,13 @@ tempPoint: {} as IPointData,

scale(t: IPointData, scaleX: number, scaleY = scaleX): void {
if (t.x) t.x *= scaleX
if (t.y) t.y *= scaleY
},
scaleOf(t: IPointData, origin: IPointData, scaleX: number, scaleY = scaleX): void {
t.x += (t.x - origin.x) * (scaleX - 1)
t.y += (t.y - origin.y) * (scaleY - 1)
},
rotate(t: IPointData, rotation: number, origin?: IPointData): void {

@@ -41,0 +52,0 @@ if (!origin) origin = P.defaultPoint

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

import { INumberMap, IPoint, IPointData, IMatrixData, IBounds, IBoundsData, IMatrix, IObject, IBoundsDataFn, IRadiusPointData, IMatrixWithLayoutData, IAutoBounds, IAutoBoundsData, ISizeData, ILayoutData, IMatrixWithScaleData, IAround, IOffsetBoundsData, ITwoPointBoundsData } from '@leafer/interface';
import { INumberMap, IPoint, IPointData, IMatrixData, IBounds, IBoundsData, IMatrix, IObject, IBoundsDataFn, IRadiusPointData, IMatrixWithLayoutData, IAutoBounds, IAutoBoundsData, ISizeData, ILayoutData, IMatrixWithScaleData, IAround, IOffsetBoundsData, ITwoPointBoundsData, IMatrixWithOptionScaleData, IScaleData } from '@leafer/interface';

@@ -20,2 +20,5 @@ declare const IncrementId: {

clone(): IPoint;
move(x: number, y: number): IPoint;
scale(scaleX: number, scaleY?: number): IPoint;
scaleOf(origin: IPointData, scaleX: number, scaleY?: number): IPoint;
rotate(rotation: number, origin?: IPointData): IPoint;

@@ -47,5 +50,7 @@ rotateOf(origin: IPointData, rotation: number): IPoint;

clone(): IBounds;
move(x: number, y: number): IBounds;
scale(scaleX: number, scaleY?: number): IBounds;
scaleOf(origin: IPointData, scaleX: number, scaleY?: number): IBounds;
toOuterOf(matrix: IMatrixData, to?: IBoundsData): IBounds;
toInnerOf(matrix: IMatrixData, to?: IBoundsData): IBounds;
getFitMatrix(put: IBoundsData): IMatrix;

@@ -55,2 +60,3 @@ spread(spreadX: number, spreadY?: number): IBounds;

unsign(): IBounds;
float(maxLength?: number): IBounds;
add(bounds: IBoundsData): IBounds;

@@ -118,2 +124,3 @@ addList(boundsList: IBoundsData[]): IBounds;

getLayout(origin?: IPointData, firstSkewY?: boolean): ILayoutData;
withScale(scaleX?: number, scaleY?: number): IMatrixWithScaleData;
reset(): void;

@@ -130,2 +137,4 @@ }

move(t: IPointData, x: number, y: number): void;
scale(t: IPointData, scaleX: number, scaleY?: number): void;
scaleOf(t: IPointData, origin: IPointData, scaleX: number, scaleY?: number): void;
rotate(t: IPointData, rotation: number, origin?: IPointData): void;

@@ -155,6 +164,6 @@ tempToInnerOf(t: IPointData, matrix: IMatrixData): IPointData;

tempPoint: IPointData;
get: typeof get$1;
get: typeof get;
toPoint(around: IAround, bounds: IBoundsData, to?: IPointData, onlySize?: boolean): void;
};
declare function get$1(around: IAround): IPointData;
declare function get(around: IAround): IPointData;

@@ -178,2 +187,3 @@ declare const BoundsHelper: {

toOuterOf(t: IBoundsData, matrix: IMatrixData, to?: IBoundsData): void;
toInnerOf(t: IBoundsData, matrix: IMatrixData, to?: IBoundsData): void;
getFitMatrix(t: IBoundsData, put: IBoundsData): IMatrix;

@@ -184,2 +194,3 @@ getSpread(t: IBoundsData, spreadX: number, spreadY?: number): IBoundsData;

unsign(t: IBoundsData): void;
float(t: IBoundsData, maxLength?: number): void;
add(t: IBoundsData, bounds: IBoundsData): void;

@@ -213,3 +224,16 @@ addList(t: IBoundsData, list: IBoundsData[]): void;

declare function get(): IMatrixData;
declare const MathHelper: {
within(value: number, min: number, max: number): number;
fourNumber(num: number | number[], maxValue?: number): number[];
formatRotation(rotation: number, unsign?: boolean): number;
getGapRotation(addRotation: number, gap: number, oldRotation?: number): number;
float(num: number, maxLength?: number): number;
};
declare const OneRadian: number;
declare const PI2: number;
declare const PI_2: number;
declare function getPointData(): IPointData;
declare function getBoundsData(): IBoundsData;
declare function getMatrixData(): IMatrixData;
declare function getWorld(): IMatrixWithLayoutData;

@@ -221,3 +245,3 @@ declare const MatrixHelper: {

set(t: IMatrixData, a?: number, b?: number, c?: number, d?: number, e?: number, f?: number): void;
get: typeof get;
get: typeof getMatrixData;
getWorld: typeof getWorld;

@@ -237,4 +261,3 @@ copy(t: IMatrixData, matrix: IMatrixData): void;

multiply(t: IMatrixData, child: IMatrixData): void;
multiplyParent(t: IMatrixData, parent: IMatrixData, to?: IMatrixData, abcdChanged?: boolean | number, childLayout?: ILayoutData): void;
multiplyParentLayout(t: ILayoutData, parent: ILayoutData, child?: ILayoutData): void;
multiplyParent(t: IMatrixWithOptionScaleData, parent: IMatrixWithOptionScaleData, to?: IMatrixWithOptionScaleData, abcdChanged?: boolean | number, childScaleData?: IScaleData): void;
divide(t: IMatrixData, child: IMatrixData): void;

@@ -248,16 +271,6 @@ divideParent(t: IMatrixData, parent: IMatrixData): void;

getLayout(t: IMatrixData, origin?: IPointData, firstSkewY?: boolean): ILayoutData;
withScale(t: IMatrixData, scaleX?: number, scaleY?: number): IMatrixWithScaleData;
reset(t: IMatrixData): void;
};
declare const MathHelper: {
within(value: number, min: number, max: number): number;
fourNumber(num: number | number[], maxValue?: number): number[];
formatRotation(rotation: number, unsign?: boolean): number;
getGapRotation(addRotation: number, gap: number, oldRotation?: number): number;
float(num: number, maxLength?: number): number;
};
declare const OneRadian: number;
declare const PI2: number;
declare const PI_2: number;
declare const StringNumberMap: INumberMap;

@@ -283,2 +296,2 @@

export { AroundHelper, AutoBounds, Bounds, BoundsHelper, Direction4, Direction9, IncrementId, MathHelper, Matrix, MatrixHelper, OneRadian, PI2, PI_2, Point, PointHelper, StringNumberMap, TwoPointBoundsHelper };
export { AroundHelper, AutoBounds, Bounds, BoundsHelper, Direction4, Direction9, IncrementId, MathHelper, Matrix, MatrixHelper, OneRadian, PI2, PI_2, Point, PointHelper, StringNumberMap, TwoPointBoundsHelper, getBoundsData, getMatrixData, getPointData };