@gitborlando/geo 2.0.0 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @gitborlando/geo
2
2
 
3
+ ## 2.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 7bd75bc: 新增一些方法
8
+
3
9
  ## 2.0.0
4
10
 
5
11
  ### Major Changes
package/dist/index.d.ts CHANGED
@@ -51,6 +51,7 @@ declare class OBB {
51
51
  collide: (another: OBB) => boolean;
52
52
  static identityOBB(): OBB;
53
53
  static fromRect(rect: IRect, rotation?: number): OBB;
54
+ static fromCenter(center: IXY, width: number, height: number, rotation?: number): OBB;
54
55
  static fromAABB(aabb: AABB): OBB;
55
56
  }
56
57
 
@@ -107,6 +108,7 @@ declare function pow3(number: number): number;
107
108
  declare function multiply(...numbers: number[]): number;
108
109
  declare function divide(a: number, b: number): number;
109
110
  declare function numberHalfFix(number: number): number;
111
+ declare function twoDecimal(number: number): number;
110
112
 
111
113
  type IMatrix = [number, number, number, number, number, number];
112
114
  declare class Matrix {
@@ -238,8 +240,9 @@ declare class XY {
238
240
  y: number;
239
241
  };
240
242
  angle(another: IXY, origin: IXY): number;
243
+ static of(x: number, y: number): XY;
241
244
  static from(xy: IXY): XY;
242
245
  static fromArray(arr: [number, number]): XY;
243
246
  }
244
247
 
245
- export { AABB, Angle, type IMatrix, type IRect, type IRectWithCenter, type IXY, Matrix, OBB, PI, type Point, XY, abs, acos, asin, atan, atan2, ceil, cos, divide, floor, max, min, multiply, numberHalfFix, pointsOnBezierCurves, pow2, pow3, random, round, simplify, simplifyPoints, sin, sqrt, tan, xy_, xy_center, xy_client, xy_distance, xy_divide, xy_dot, xy_from, xy_getRotation, xy_minus, xy_minus_mutate, xy_multiply, xy_multiply_mutate, xy_mutate, xy_opposite, xy_plus, xy_plus_all, xy_plus_mutate, xy_rotate, xy_symmetric, xy_toArray, xy_xAxis, xy_yAxis };
248
+ export { AABB, Angle, type IMatrix, type IRect, type IRectWithCenter, type IXY, Matrix, OBB, PI, type Point, XY, abs, acos, asin, atan, atan2, ceil, cos, divide, floor, max, min, multiply, numberHalfFix, pointsOnBezierCurves, pow2, pow3, random, round, simplify, simplifyPoints, sin, sqrt, tan, twoDecimal, xy_, xy_center, xy_client, xy_distance, xy_divide, xy_dot, xy_from, xy_getRotation, xy_minus, xy_minus_mutate, xy_multiply, xy_multiply_mutate, xy_mutate, xy_opposite, xy_plus, xy_plus_all, xy_plus_mutate, xy_rotate, xy_symmetric, xy_toArray, xy_xAxis, xy_yAxis };
package/dist/index.js CHANGED
@@ -18,6 +18,9 @@ function numberHalfFix(number) {
18
18
  const halfFixed = floatPart >= 0.75 ? 1 : floatPart >= 0.25 ? 0.5 : 0;
19
19
  return integerPart + halfFixed;
20
20
  }
21
+ function twoDecimal(number) {
22
+ return Number(number.toFixed(Number.isInteger(number) ? 0 : 2));
23
+ }
21
24
 
22
25
  // src/angle.ts
23
26
  var { PI, cos, sin, tan, acos, asin, atan, atan2 } = Math;
@@ -204,6 +207,9 @@ var XY = class _XY {
204
207
  Math.atan2(this.y - origin.y, this.x - origin.x) - Math.atan2(another.y - origin.y, another.x - origin.x)
205
208
  );
206
209
  }
210
+ static of(x, y) {
211
+ return new _XY(x, y);
212
+ }
207
213
  static from(xy) {
208
214
  return new _XY(xy.x, xy.y);
209
215
  }
@@ -388,6 +394,12 @@ var OBB = class _OBB {
388
394
  const { x, y, width, height } = rect;
389
395
  return new _OBB(x, y, width, height, rotation);
390
396
  }
397
+ static fromCenter(center, width, height, rotation = 0) {
398
+ const dx = center.x - width / 2;
399
+ const dy = center.y - height / 2;
400
+ const xy = XY.of(dx, dy).rotate(center, rotation);
401
+ return new _OBB(xy.x, xy.y, width, height, rotation);
402
+ }
391
403
  static fromAABB(aabb) {
392
404
  const { minX, minY, maxX, maxY } = aabb;
393
405
  return new _OBB(minX, minY, maxX - minX, maxY - minY, 0);
@@ -533,6 +545,7 @@ export {
533
545
  sin,
534
546
  sqrt,
535
547
  tan,
548
+ twoDecimal,
536
549
  xy_,
537
550
  xy_center,
538
551
  xy_client,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gitborlando/geo",
3
- "version": "2.0.0",
3
+ "version": "2.1.0",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "exports": {
package/src/math.ts CHANGED
@@ -20,3 +20,7 @@ export function numberHalfFix(number: number) {
20
20
  const halfFixed = floatPart >= 0.75 ? 1 : floatPart >= 0.25 ? 0.5 : 0
21
21
  return integerPart + halfFixed
22
22
  }
23
+
24
+ export function twoDecimal(number: number) {
25
+ return Number(number.toFixed(Number.isInteger(number) ? 0 : 2))
26
+ }
package/src/obb.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { AABB } from './aabb'
2
2
  import { Angle } from './angle'
3
3
  import { IRect, IXY } from './types'
4
- import { xy_, xy_dot, xy_minus, xy_rotate } from './xy'
4
+ import { XY, xy_, xy_dot, xy_minus, xy_rotate } from './xy'
5
5
 
6
6
  type IAxis = { widthAxis: IXY; heightAxis: IXY }
7
7
 
@@ -101,6 +101,13 @@ export class OBB {
101
101
  return new OBB(x, y, width, height, rotation)
102
102
  }
103
103
 
104
+ static fromCenter(center: IXY, width: number, height: number, rotation = 0) {
105
+ const dx = center.x - width / 2
106
+ const dy = center.y - height / 2
107
+ const xy = XY.of(dx, dy).rotate(center, rotation)
108
+ return new OBB(xy.x, xy.y, width, height, rotation)
109
+ }
110
+
104
111
  static fromAABB(aabb: AABB): OBB {
105
112
  const { minX, minY, maxX, maxY } = aabb
106
113
  return new OBB(minX, minY, maxX - minX, maxY - minY, 0)
package/src/xy.ts CHANGED
@@ -175,6 +175,10 @@ export class XY {
175
175
  )
176
176
  }
177
177
 
178
+ static of(x: number, y: number) {
179
+ return new XY(x, y)
180
+ }
181
+
178
182
  static from(xy: IXY) {
179
183
  return new XY(xy.x, xy.y)
180
184
  }