@gitborlando/geo 2.1.0 → 3.0.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 +6 -0
- package/__test__/xy.test.ts +2 -2
- package/dist/index.d.ts +22 -29
- package/dist/index.js +32 -45
- package/package.json +1 -1
- package/src/xy.ts +34 -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,30 @@ 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
|
-
plus(another: IXY): this;
|
|
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): {
|
|
230
|
-
x: number;
|
|
231
|
-
y: number;
|
|
232
|
-
};
|
|
233
|
-
dot(another: IXY): number;
|
|
234
|
-
opposite(): {
|
|
235
|
-
x: number;
|
|
236
|
-
y: number;
|
|
237
|
-
};
|
|
238
|
-
symmetric(another: IXY, origin: IXY): {
|
|
239
|
-
x: number;
|
|
240
|
-
y: number;
|
|
241
|
-
};
|
|
242
|
-
angle(another: IXY, origin: IXY): 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;
|
|
243
224
|
static of(x: number, y: number): XY;
|
|
244
225
|
static from(xy: IXY): XY;
|
|
245
|
-
static
|
|
226
|
+
static center(xy: {
|
|
227
|
+
centerX: number;
|
|
228
|
+
centerY: number;
|
|
229
|
+
}): XY;
|
|
230
|
+
static leftTop(e: {
|
|
231
|
+
left: number;
|
|
232
|
+
top: number;
|
|
233
|
+
}): XY;
|
|
234
|
+
static client(e: {
|
|
235
|
+
clientX: number;
|
|
236
|
+
clientY: number;
|
|
237
|
+
}): XY;
|
|
238
|
+
static tuple(arr: [number, number]): XY;
|
|
246
239
|
}
|
|
247
240
|
|
|
248
241
|
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,60 +149,38 @@ 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
|
);
|
|
@@ -211,10 +189,19 @@ var XY = class _XY {
|
|
|
211
189
|
return new _XY(x, y);
|
|
212
190
|
}
|
|
213
191
|
static from(xy) {
|
|
214
|
-
return
|
|
192
|
+
return _XY.of(xy.x, xy.y);
|
|
193
|
+
}
|
|
194
|
+
static center(xy) {
|
|
195
|
+
return _XY.of(xy.centerX, xy.centerY);
|
|
196
|
+
}
|
|
197
|
+
static leftTop(e) {
|
|
198
|
+
return _XY.of(e.left, e.top);
|
|
199
|
+
}
|
|
200
|
+
static client(e) {
|
|
201
|
+
return _XY.of(e.clientX, e.clientY);
|
|
215
202
|
}
|
|
216
|
-
static
|
|
217
|
-
return
|
|
203
|
+
static tuple(arr) {
|
|
204
|
+
return _XY.of(arr[0], arr[1]);
|
|
218
205
|
}
|
|
219
206
|
};
|
|
220
207
|
|
package/package.json
CHANGED
package/src/xy.ts
CHANGED
|
@@ -102,73 +102,46 @@ 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
|
|
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)
|
|
116
109
|
}
|
|
117
110
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
return
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
plus(another: IXY) {
|
|
125
|
-
this.x = this.x + another.x
|
|
126
|
-
this.y = this.y + another.y
|
|
127
|
-
return this
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
minus(another: IXY) {
|
|
131
|
-
this.x = this.x - another.x
|
|
132
|
-
this.y = this.y - another.y
|
|
133
|
-
return this
|
|
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),
|
|
@@ -180,10 +153,22 @@ export class XY {
|
|
|
180
153
|
}
|
|
181
154
|
|
|
182
155
|
static from(xy: IXY) {
|
|
183
|
-
return
|
|
156
|
+
return XY.of(xy.x, xy.y)
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
static center(xy: { centerX: number; centerY: number }) {
|
|
160
|
+
return XY.of(xy.centerX, xy.centerY)
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
static leftTop(e: { left: number; top: number }) {
|
|
164
|
+
return XY.of(e.left, e.top)
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
static client(e: { clientX: number; clientY: number }) {
|
|
168
|
+
return XY.of(e.clientX, e.clientY)
|
|
184
169
|
}
|
|
185
170
|
|
|
186
|
-
static
|
|
187
|
-
return
|
|
171
|
+
static tuple(arr: [number, number]) {
|
|
172
|
+
return XY.of(arr[0], arr[1])
|
|
188
173
|
}
|
|
189
174
|
}
|