@gitborlando/geo 2.1.0 → 3.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 +13 -0
- package/__test__/xy.test.ts +2 -2
- package/dist/index.d.ts +24 -23
- package/dist/index.js +39 -45
- package/package.json +1 -1
- package/src/xy.ts +43 -49
package/CHANGELOG.md
CHANGED
package/__test__/xy.test.ts
CHANGED
|
@@ -124,7 +124,7 @@ describe('XY class', () => {
|
|
|
124
124
|
})
|
|
125
125
|
|
|
126
126
|
it('should create from array correctly', () => {
|
|
127
|
-
const xy = XY.
|
|
127
|
+
const xy = XY.tuple([15, 25])
|
|
128
128
|
expect(xy.x).toBe(15)
|
|
129
129
|
expect(xy.y).toBe(25)
|
|
130
130
|
})
|
|
@@ -137,7 +137,7 @@ describe('XY class', () => {
|
|
|
137
137
|
|
|
138
138
|
it('should calculate distance correctly', () => {
|
|
139
139
|
const xy = new XY(0, 0)
|
|
140
|
-
const distance = xy.
|
|
140
|
+
const distance = xy.getDistance({ x: 3, y: 4 })
|
|
141
141
|
expect(distance).toBe(5)
|
|
142
142
|
})
|
|
143
143
|
})
|
package/dist/index.d.ts
CHANGED
|
@@ -212,37 +212,38 @@ declare class XY {
|
|
|
212
212
|
x: number;
|
|
213
213
|
y: number;
|
|
214
214
|
constructor(x: number, y: number);
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
minus(another: IXY): this;
|
|
226
|
-
multiply(...numbers: number[]): this;
|
|
227
|
-
divide(...numbers: number[]): this;
|
|
228
|
-
distance(another: IXY): number;
|
|
229
|
-
rotate(origin: IXY, rotation: number): {
|
|
215
|
+
plus(...others: IXY[]): XY;
|
|
216
|
+
minus(...others: IXY[]): XY;
|
|
217
|
+
multiply(...numbers: number[]): XY;
|
|
218
|
+
divide(...numbers: number[]): XY;
|
|
219
|
+
rotate(origin: IXY, rotation: number): XY;
|
|
220
|
+
symmetric(another: IXY, origin: IXY): XY;
|
|
221
|
+
getDot(another: IXY): number;
|
|
222
|
+
getDistance(another: IXY): number;
|
|
223
|
+
getAngle(another: IXY, origin: IXY): number;
|
|
224
|
+
primitive(): {
|
|
230
225
|
x: number;
|
|
231
226
|
y: number;
|
|
232
227
|
};
|
|
233
|
-
|
|
234
|
-
opposite(): {
|
|
228
|
+
static _(x?: number, y?: number): {
|
|
235
229
|
x: number;
|
|
236
230
|
y: number;
|
|
237
231
|
};
|
|
238
|
-
symmetric(another: IXY, origin: IXY): {
|
|
239
|
-
x: number;
|
|
240
|
-
y: number;
|
|
241
|
-
};
|
|
242
|
-
angle(another: IXY, origin: IXY): number;
|
|
243
232
|
static of(x: number, y: number): XY;
|
|
244
233
|
static from(xy: IXY): XY;
|
|
245
|
-
static
|
|
234
|
+
static center(xy: {
|
|
235
|
+
centerX: number;
|
|
236
|
+
centerY: number;
|
|
237
|
+
}): XY;
|
|
238
|
+
static leftTop(e: {
|
|
239
|
+
left: number;
|
|
240
|
+
top: number;
|
|
241
|
+
}): XY;
|
|
242
|
+
static client(e: {
|
|
243
|
+
clientX: number;
|
|
244
|
+
clientY: number;
|
|
245
|
+
}): XY;
|
|
246
|
+
static tuple(arr: [number, number]): XY;
|
|
246
247
|
}
|
|
247
248
|
|
|
248
249
|
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
|
@@ -149,72 +149,66 @@ var XY = class _XY {
|
|
|
149
149
|
this.x = x;
|
|
150
150
|
this.y = y;
|
|
151
151
|
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
return
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
return
|
|
161
|
-
}
|
|
162
|
-
center(xy) {
|
|
163
|
-
this.x = xy.centerX;
|
|
164
|
-
this.y = xy.centerY;
|
|
165
|
-
return this;
|
|
166
|
-
}
|
|
167
|
-
plus(another) {
|
|
168
|
-
this.x = this.x + another.x;
|
|
169
|
-
this.y = this.y + another.y;
|
|
170
|
-
return this;
|
|
171
|
-
}
|
|
172
|
-
minus(another) {
|
|
173
|
-
this.x = this.x - another.x;
|
|
174
|
-
this.y = this.y - another.y;
|
|
175
|
-
return this;
|
|
152
|
+
plus(...others) {
|
|
153
|
+
const x = others.reduce((sum, cur) => sum + cur.x, this.x);
|
|
154
|
+
const y = others.reduce((sum, cur) => sum + cur.y, this.y);
|
|
155
|
+
return _XY.of(x, y);
|
|
156
|
+
}
|
|
157
|
+
minus(...others) {
|
|
158
|
+
const x = others.reduce((sum, cur) => sum - cur.x, this.x);
|
|
159
|
+
const y = others.reduce((sum, cur) => sum - cur.y, this.y);
|
|
160
|
+
return _XY.of(x, y);
|
|
176
161
|
}
|
|
177
162
|
multiply(...numbers) {
|
|
178
163
|
const n = numbers.reduce((a, b) => a * b, 1);
|
|
179
|
-
this.x
|
|
180
|
-
this.y = this.y * n;
|
|
181
|
-
return this;
|
|
164
|
+
return _XY.of(this.x * n, this.y * n);
|
|
182
165
|
}
|
|
183
166
|
divide(...numbers) {
|
|
184
167
|
const n = numbers.reduce((a, b) => a * b, 1);
|
|
185
|
-
this.x
|
|
186
|
-
this.y = this.y / n;
|
|
187
|
-
return this;
|
|
188
|
-
}
|
|
189
|
-
distance(another) {
|
|
190
|
-
return sqrt((this.x - another.x) ** 2 + (this.y - another.y) ** 2);
|
|
168
|
+
return _XY.of(this.x / n, this.y / n);
|
|
191
169
|
}
|
|
192
170
|
rotate(origin, rotation) {
|
|
193
|
-
if (rotation === 0) return this;
|
|
194
|
-
return Angle.rotatePoint(this.x, this.y, origin.x, origin.y, rotation);
|
|
171
|
+
if (rotation === 0) return _XY.from(this);
|
|
172
|
+
return _XY.from(Angle.rotatePoint(this.x, this.y, origin.x, origin.y, rotation));
|
|
195
173
|
}
|
|
196
|
-
|
|
197
|
-
return
|
|
174
|
+
symmetric(another, origin) {
|
|
175
|
+
return _XY.of(2 * origin.x - another.x, 2 * origin.y - another.y);
|
|
198
176
|
}
|
|
199
|
-
|
|
200
|
-
return
|
|
177
|
+
getDot(another) {
|
|
178
|
+
return this.x * another.x + this.y * another.y;
|
|
201
179
|
}
|
|
202
|
-
|
|
203
|
-
return
|
|
180
|
+
getDistance(another) {
|
|
181
|
+
return sqrt((this.x - another.x) ** 2 + (this.y - another.y) ** 2);
|
|
204
182
|
}
|
|
205
|
-
|
|
183
|
+
getAngle(another, origin) {
|
|
206
184
|
return Angle.angleFy(
|
|
207
185
|
Math.atan2(this.y - origin.y, this.x - origin.x) - Math.atan2(another.y - origin.y, another.x - origin.x)
|
|
208
186
|
);
|
|
209
187
|
}
|
|
188
|
+
primitive() {
|
|
189
|
+
return { x: this.x, y: this.y };
|
|
190
|
+
}
|
|
191
|
+
static _(x = 0, y = 0) {
|
|
192
|
+
return { x, y };
|
|
193
|
+
}
|
|
210
194
|
static of(x, y) {
|
|
211
195
|
return new _XY(x, y);
|
|
212
196
|
}
|
|
213
197
|
static from(xy) {
|
|
214
|
-
|
|
198
|
+
if (xy instanceof _XY) return xy;
|
|
199
|
+
return _XY.of(xy.x, xy.y);
|
|
200
|
+
}
|
|
201
|
+
static center(xy) {
|
|
202
|
+
return _XY.of(xy.centerX, xy.centerY);
|
|
203
|
+
}
|
|
204
|
+
static leftTop(e) {
|
|
205
|
+
return _XY.of(e.left, e.top);
|
|
206
|
+
}
|
|
207
|
+
static client(e) {
|
|
208
|
+
return _XY.of(e.clientX, e.clientY);
|
|
215
209
|
}
|
|
216
|
-
static
|
|
217
|
-
return
|
|
210
|
+
static tuple(arr) {
|
|
211
|
+
return _XY.of(arr[0], arr[1]);
|
|
218
212
|
}
|
|
219
213
|
};
|
|
220
214
|
|
package/package.json
CHANGED
package/src/xy.ts
CHANGED
|
@@ -102,88 +102,82 @@ export class XY {
|
|
|
102
102
|
public x: number,
|
|
103
103
|
public y: number,
|
|
104
104
|
) {}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
return this
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
client(e: { clientX: number; clientY: number }) {
|
|
113
|
-
this.x = e.clientX
|
|
114
|
-
this.y = e.clientY
|
|
115
|
-
return this
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
center(xy: { centerX: number; centerY: number }) {
|
|
119
|
-
this.x = xy.centerX
|
|
120
|
-
this.y = xy.centerY
|
|
121
|
-
return this
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
plus(another: IXY) {
|
|
125
|
-
this.x = this.x + another.x
|
|
126
|
-
this.y = this.y + another.y
|
|
127
|
-
return this
|
|
105
|
+
plus(...others: IXY[]) {
|
|
106
|
+
const x = others.reduce((sum, cur) => sum + cur.x, this.x)
|
|
107
|
+
const y = others.reduce((sum, cur) => sum + cur.y, this.y)
|
|
108
|
+
return XY.of(x, y)
|
|
128
109
|
}
|
|
129
110
|
|
|
130
|
-
minus(
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
return
|
|
111
|
+
minus(...others: IXY[]) {
|
|
112
|
+
const x = others.reduce((sum, cur) => sum - cur.x, this.x)
|
|
113
|
+
const y = others.reduce((sum, cur) => sum - cur.y, this.y)
|
|
114
|
+
return XY.of(x, y)
|
|
134
115
|
}
|
|
135
116
|
|
|
136
117
|
multiply(...numbers: number[]) {
|
|
137
118
|
const n = numbers.reduce((a, b) => a * b, 1)
|
|
138
|
-
this.x
|
|
139
|
-
this.y = this.y * n
|
|
140
|
-
return this
|
|
119
|
+
return XY.of(this.x * n, this.y * n)
|
|
141
120
|
}
|
|
142
121
|
|
|
143
122
|
divide(...numbers: number[]) {
|
|
144
123
|
const n = numbers.reduce((a, b) => a * b, 1)
|
|
145
|
-
this.x
|
|
146
|
-
this.y = this.y / n
|
|
147
|
-
return this
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
distance(another: IXY) {
|
|
151
|
-
return sqrt((this.x - another.x) ** 2 + (this.y - another.y) ** 2)
|
|
124
|
+
return XY.of(this.x / n, this.y / n)
|
|
152
125
|
}
|
|
153
126
|
|
|
154
127
|
rotate(origin: IXY, rotation: number) {
|
|
155
|
-
if (rotation === 0) return this
|
|
156
|
-
return Angle.rotatePoint(this.x, this.y, origin.x, origin.y, rotation)
|
|
128
|
+
if (rotation === 0) return XY.from(this)
|
|
129
|
+
return XY.from(Angle.rotatePoint(this.x, this.y, origin.x, origin.y, rotation))
|
|
157
130
|
}
|
|
158
131
|
|
|
159
|
-
|
|
160
|
-
return
|
|
132
|
+
symmetric(another: IXY, origin: IXY) {
|
|
133
|
+
return XY.of(2 * origin.x - another.x, 2 * origin.y - another.y)
|
|
161
134
|
}
|
|
162
135
|
|
|
163
|
-
|
|
164
|
-
return
|
|
136
|
+
getDot(another: IXY) {
|
|
137
|
+
return this.x * another.x + this.y * another.y
|
|
165
138
|
}
|
|
166
139
|
|
|
167
|
-
|
|
168
|
-
return
|
|
140
|
+
getDistance(another: IXY) {
|
|
141
|
+
return sqrt((this.x - another.x) ** 2 + (this.y - another.y) ** 2)
|
|
169
142
|
}
|
|
170
143
|
|
|
171
|
-
|
|
144
|
+
getAngle(another: IXY, origin: IXY) {
|
|
172
145
|
return Angle.angleFy(
|
|
173
146
|
Math.atan2(this.y - origin.y, this.x - origin.x) -
|
|
174
147
|
Math.atan2(another.y - origin.y, another.x - origin.x),
|
|
175
148
|
)
|
|
176
149
|
}
|
|
177
150
|
|
|
151
|
+
primitive() {
|
|
152
|
+
return { x: this.x, y: this.y }
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
static _(x: number = 0, y: number = 0) {
|
|
156
|
+
return { x, y }
|
|
157
|
+
}
|
|
158
|
+
|
|
178
159
|
static of(x: number, y: number) {
|
|
179
160
|
return new XY(x, y)
|
|
180
161
|
}
|
|
181
162
|
|
|
182
163
|
static from(xy: IXY) {
|
|
183
|
-
|
|
164
|
+
if (xy instanceof XY) return xy
|
|
165
|
+
return XY.of(xy.x, xy.y)
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
static center(xy: { centerX: number; centerY: number }) {
|
|
169
|
+
return XY.of(xy.centerX, xy.centerY)
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
static leftTop(e: { left: number; top: number }) {
|
|
173
|
+
return XY.of(e.left, e.top)
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
static client(e: { clientX: number; clientY: number }) {
|
|
177
|
+
return XY.of(e.clientX, e.clientY)
|
|
184
178
|
}
|
|
185
179
|
|
|
186
|
-
static
|
|
187
|
-
return
|
|
180
|
+
static tuple(arr: [number, number]) {
|
|
181
|
+
return XY.of(arr[0], arr[1])
|
|
188
182
|
}
|
|
189
183
|
}
|