@leafer/math
Advanced tools
+2
-2
| { | ||
| "name": "@leafer/math", | ||
| "version": "1.0.1", | ||
| "version": "1.0.2", | ||
| "description": "@leafer/math", | ||
@@ -25,4 +25,4 @@ "author": "Chao (Leafer) Wan", | ||
| "devDependencies": { | ||
| "@leafer/interface": "1.0.1" | ||
| "@leafer/interface": "1.0.2" | ||
| } | ||
| } |
+5
-5
@@ -1,2 +0,2 @@ | ||
| import { IBounds, IBoundsData, IMatrixData, IPointData, IBoundsDataFn, IObject, IMatrix, IRadiusPointData, IMatrixWithLayoutData, IFourNumber } from '@leafer/interface' | ||
| import { IBounds, IBoundsData, IMatrixData, IPointData, IBoundsDataFn, IObject, IMatrix, IRadiusPointData, IMatrixWithLayoutData, IFourNumber, ISide } from '@leafer/interface' | ||
| import { BoundsHelper as B } from './BoundsHelper' | ||
@@ -65,9 +65,9 @@ | ||
| public spread(fourNumber: IFourNumber): IBounds { | ||
| B.spread(this, fourNumber) | ||
| public spread(fourNumber: IFourNumber, side?: ISide): IBounds { | ||
| B.spread(this, fourNumber, side) | ||
| return this | ||
| } | ||
| public shrink(fourNumber: IFourNumber): IBounds { | ||
| B.shrink(this, fourNumber) | ||
| public shrink(fourNumber: IFourNumber, side?: ISide): IBounds { | ||
| B.shrink(this, fourNumber, side) | ||
| return this | ||
@@ -74,0 +74,0 @@ } |
+17
-11
@@ -1,2 +0,2 @@ | ||
| import { IPointData, IBoundsData, IMatrixData, IFourNumber, IBoundsDataFn, IObject, IMatrix, IOffsetBoundsData, IRadiusPointData, IMatrixWithScaleData } from '@leafer/interface' | ||
| import { IPointData, IBoundsData, IMatrixData, IFourNumber, IBoundsDataFn, IObject, IMatrix, IOffsetBoundsData, IRadiusPointData, IMatrixWithScaleData, ISide } from '@leafer/interface' | ||
| import { Matrix } from './Matrix' | ||
@@ -36,12 +36,18 @@ import { MatrixHelper as M } from './MatrixHelper' | ||
| copyAndSpread(t: IBoundsData, bounds: IBoundsData, spread: IFourNumber, isShrink?: boolean): void { | ||
| copyAndSpread(t: IBoundsData, bounds: IBoundsData, spread: IFourNumber, isShrink?: boolean, side?: ISide): void { | ||
| const { x, y, width, height } = bounds | ||
| if (spread instanceof Array) { | ||
| const four = fourNumber(spread) | ||
| isShrink | ||
| ? B.set(t, bounds.x + four[3], bounds.y + four[0], bounds.width - four[1] - four[3], bounds.height - four[2] - four[0]) | ||
| : B.set(t, bounds.x - four[3], bounds.y - four[0], bounds.width + four[1] + four[3], bounds.height + four[2] + four[0]) | ||
| ? B.set(t, x + four[3], y + four[0], width - four[1] - four[3], height - four[2] - four[0]) | ||
| : B.set(t, x - four[3], y - four[0], width + four[1] + four[3], height + four[2] + four[0]) | ||
| } else { | ||
| if (isShrink) spread = -spread | ||
| B.set(t, bounds.x - spread, bounds.y - spread, bounds.width + spread * 2, bounds.height + spread * 2) | ||
| B.set(t, x - spread, y - spread, width + spread * 2, height + spread * 2) | ||
| } | ||
| if (side) { // 只扩展/收缩一边 | ||
| if (side === 'width') t.y = y, t.height = height | ||
| else t.x = x, t.width = width | ||
| } | ||
| }, | ||
@@ -173,14 +179,14 @@ | ||
| getSpread(t: IBoundsData, spread: IFourNumber): IBoundsData { | ||
| getSpread(t: IBoundsData, spread: IFourNumber, side?: ISide): IBoundsData { | ||
| const n = {} as IBoundsData | ||
| B.copyAndSpread(n, t, spread) | ||
| B.copyAndSpread(n, t, spread, false, side) | ||
| return n | ||
| }, | ||
| spread(t: IBoundsData, spread: IFourNumber): void { | ||
| B.copyAndSpread(t, t, spread) | ||
| spread(t: IBoundsData, spread: IFourNumber, side?: ISide): void { | ||
| B.copyAndSpread(t, t, spread, false, side) | ||
| }, | ||
| shrink(t: IBoundsData, shrink: IFourNumber): void { | ||
| B.copyAndSpread(t, t, shrink, true) | ||
| shrink(t: IBoundsData, shrink: IFourNumber, side?: ISide): void { | ||
| B.copyAndSpread(t, t, shrink, true, side) | ||
| }, | ||
@@ -187,0 +193,0 @@ |
+13
-1
@@ -1,2 +0,2 @@ | ||
| import { IPointData, IBoundsData, IMatrixData, IRangeSize } from '@leafer/interface' | ||
| import { IPointData, IBoundsData, IMatrixData, IRangeSize, IScaleData, ISizeData } from '@leafer/interface' | ||
@@ -63,2 +63,14 @@ const { round, pow, PI } = Math | ||
| return num === -0 ? 0 : num | ||
| }, | ||
| getScaleData(scale: number | IPointData, size: number | ISizeData, originSize: ISizeData, scaleData?: IScaleData): IScaleData { | ||
| if (!scaleData) scaleData = {} as IScaleData | ||
| if (size) { | ||
| scaleData.scaleX = (typeof size === 'number' ? size : size.width) / originSize.width | ||
| scaleData.scaleY = (typeof size === 'number' ? size : size.height) / originSize.height | ||
| } else if (scale) { | ||
| scaleData.scaleX = typeof scale === 'number' ? scale : scale.x | ||
| scaleData.scaleY = typeof scale === 'number' ? scale : scale.y | ||
| } | ||
| return scaleData | ||
| } | ||
@@ -65,0 +77,0 @@ |
+8
-7
@@ -1,2 +0,2 @@ | ||
| import { INumberMap, IPoint, IPointData, IMatrixData, IBounds, IBoundsData, IMatrix, IFourNumber, IObject, IBoundsDataFn, IRadiusPointData, IMatrixWithLayoutData, IAutoBounds, IAutoBoundsData, ISizeData, IMatrixWithScaleData, ILayoutData, IUnitPointData, IAround, IAlign, IOffsetBoundsData, ITwoPointBoundsData, IRangeSize, IMatrixWithOptionScaleData, IScaleData, IScrollPointData } from '@leafer/interface'; | ||
| import { INumberMap, IPoint, IPointData, IMatrixData, IBounds, IBoundsData, IMatrix, IFourNumber, ISide, IObject, IBoundsDataFn, IRadiusPointData, IMatrixWithLayoutData, IAutoBounds, IAutoBoundsData, ISizeData, IMatrixWithScaleData, ILayoutData, IUnitPointData, IAround, IAlign, IOffsetBoundsData, ITwoPointBoundsData, IRangeSize, IScaleData, IMatrixWithOptionScaleData, IScrollPointData } from '@leafer/interface'; | ||
@@ -56,4 +56,4 @@ declare const IncrementId: { | ||
| getFitMatrix(put: IBoundsData, baseScale?: number): IMatrix; | ||
| spread(fourNumber: IFourNumber): IBounds; | ||
| shrink(fourNumber: IFourNumber): IBounds; | ||
| spread(fourNumber: IFourNumber, side?: ISide): IBounds; | ||
| shrink(fourNumber: IFourNumber, side?: ISide): IBounds; | ||
| ceil(): IBounds; | ||
@@ -185,3 +185,3 @@ unsign(): IBounds; | ||
| copy(t: IBoundsData, bounds: IBoundsData): void; | ||
| copyAndSpread(t: IBoundsData, bounds: IBoundsData, spread: IFourNumber, isShrink?: boolean): void; | ||
| copyAndSpread(t: IBoundsData, bounds: IBoundsData, spread: IFourNumber, isShrink?: boolean, side?: ISide): void; | ||
| minX(t: IBoundsData): number; | ||
@@ -201,5 +201,5 @@ minY(t: IBoundsData): number; | ||
| getFitMatrix(t: IBoundsData, put: IBoundsData, baseScale?: number): IMatrix; | ||
| getSpread(t: IBoundsData, spread: IFourNumber): IBoundsData; | ||
| spread(t: IBoundsData, spread: IFourNumber): void; | ||
| shrink(t: IBoundsData, shrink: IFourNumber): void; | ||
| getSpread(t: IBoundsData, spread: IFourNumber, side?: ISide): IBoundsData; | ||
| spread(t: IBoundsData, spread: IFourNumber, side?: ISide): void; | ||
| shrink(t: IBoundsData, shrink: IFourNumber, side?: ISide): void; | ||
| ceil(t: IBoundsData): void; | ||
@@ -244,2 +244,3 @@ unsign(t: IBoundsData): void; | ||
| float(num: number, maxLength?: number): number; | ||
| getScaleData(scale: number | IPointData, size: number | ISizeData, originSize: ISizeData, scaleData?: IScaleData): IScaleData; | ||
| }; | ||
@@ -246,0 +247,0 @@ declare const OneRadian: number; |
65067
1.77%1555
1.11%