- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
- 99
- 100
- 101
- 102
- 103
- 104
- 105
- 106
- 107
- 108
- 109
- 110
- 111
- 112
- 113
- 114
- 115
- 116
- 117
- 118
- 119
- 120
- 121
- 122
- 123
- 124
- 125
- 126
- 127
- 128
- 129
- 130
- 131
- 132
- 133
- 134
- 135
- 136
- 137
- 138
- 139
- 140
- 141
- 142
- 143
- 144
- 145
- 146
- 147
- 148
- 149
- 150
- 151
- 152
- 153
- 154
- 155
- 156
- 157
- 158
- 159
- 160
- 161
- 162
- 163
- 164
- 165
- 166
- 167
- 168
- 169
- 170
- 171
- 172
- 173
- 174
- 175
- 176
- 177
- 178
- 179
- 180
- 181
- 182
- 183
- 184
- 185
- 186
- 187
- 188
- 189
- 190
- 191
- 192
- 193
- 194
- 195
- 196
- 197
- 198
- 199
- 200
- 201
- 202
- 203
- 204
- 205
- 206
- 207
- 208
- 209
- 210
- 211
- 212
- 213
- 214
- 215
- 216
- 217
- 218
- 219
- 220
- 221
- 222
- 223
- 224
- 225
- 226
- 227
- 228
- 229
- 230
- 231
- 232
- 233
- 234
- 235
- 236
- 237
- 238
- 239
- 240
- 241
- 242
- 243
- 244
- 245
- 246
- 247
- 248
- 249
- 250
- 251
- 252
- 253
- 254
- 255
- 256
- 257
- 258
- 259
- 260
- 261
- 262
- 263
- 264
- 265
- 266
- 267
- 268
- 269
- 270
- 271
- 272
- 273
- 274
- 275
- 276
- 277
- 278
- 279
- 280
- 281
- 282
- 283
- 284
- 285
- 286
- 287
- 288
- 289
- 290
- 291
- 292
- 293
- 294
- 295
- 296
- 297
- 298
- 299
- 300
- 301
- 302
- 303
- 304
- 305
- 306
- 307
- 308
- 309
- 310
- 311
- 312
- 313
- 314
- 315
- 316
- 317
- 318
- 319
- 320
- 321
- 322
- 323
- 324
- 325
- 326
- 327
- 328
- 329
- 330
- 331
- 332
- 333
- 334
- 335
- 336
- 337
- 338
- 339
- 340
- 341
- 342
- 343
- 344
- 345
- 346
- 347
- 348
- 349
- 350
- 351
- 352
- 353
- 354
- 355
- 356
- 357
- 358
- 359
- 360
- 361
- 362
- 363
- 364
- 365
- 366
- 367
- 368
- 369
- 370
- 371
- 372
- 373
- 374
- 375
- 376
- 377
- 378
- 379
- 380
- 381
- 382
- 383
- 384
- 385
- 386
- 387
- 388
- 389
- 390
- 391
- 392
- 393
- 394
- 395
- 396
- 397
- 398
- 399
import type { IPointData } from '@pixi/math';
import { Point, ObservablePoint } from '@pixi/math';
const mixins: any = {
/**
* Adds `other` to `this` point and outputs into `outPoint` or a new Point.
*
* _Note: Only available with **@pixi/math-extras**._
* @method add
* @memberof PIXI.Point#
* @param {IPointData} other - The point to add to `this`.
* @param {IPointData} [outPoint] - A Point-like object in which to store the value,
* optional (otherwise will create a new Point).
* @returns {IPointData} The `outPoint` reference or a new Point, with the result of the addition.
*/
/**
* Adds `other` to `this` point and outputs into `outPoint` or a new Point.
*
* _Note: Only available with **@pixi/math-extras**._
* @method add
* @memberof PIXI.ObservablePoint#
* @param {IPointData} other - The point to add to `this`.
* @param {IPointData} [outPoint] - A Point-like object in which to store the value,
* optional (otherwise will create a new Point).
* @returns {IPointData} The `outPoint` reference or a new Point, with the result of the addition.
*/
add<T extends IPointData>(other: IPointData, outPoint?: T): T
{
if (!outPoint)
{
(outPoint as any) = new Point();
}
outPoint.x = this.x + other.x;
outPoint.y = this.y + other.y;
return outPoint;
},
/**
* Subtracts `other` from `this` point and outputs into `outPoint` or a new Point.
*
* _Note: Only available with **@pixi/math-extras**._
* @method subtract
* @memberof PIXI.Point#
* @param {IPointData} other - The point to subtract to `this`.
* @param {IPointData} [outPoint] - A Point-like object in which to store the value,
* optional (otherwise will create a new Point).
* @returns {IPointData} The `outPoint` reference or a new Point, with the result of the subtraction.
*/
/**
* Subtracts `other` from `this` point and outputs into `outPoint` or a new Point.
*
* _Note: Only available with **@pixi/math-extras**._
* @method subtract
* @memberof PIXI.ObservablePoint#
* @param {IPointData} other - The point to subtract to `this`.
* @param {IPointData} [outPoint] - A Point-like object in which to store the value,
* optional (otherwise will create a new Point).
* @returns {IPointData} The `outPoint` reference or a new Point, with the result of the subtraction.
*/
subtract<T extends IPointData>(other: IPointData, outPoint?: T): T
{
if (!outPoint)
{
(outPoint as any) = new Point();
}
outPoint.x = this.x - other.x;
outPoint.y = this.y - other.y;
return outPoint;
},
/**
* Multiplies component-wise `other` and `this` points and outputs into `outPoint` or a new Point.
*
* _Note: Only available with **@pixi/math-extras**._
* @method multiply
* @memberof PIXI.Point#
* @param {IPointData} other - The point to multiply with `this`.
* @param {IPointData} [outPoint] - A Point-like object in which to store the value,
* optional (otherwise will create a new Point).
* @returns {IPointData} The `outPoint` reference or a new Point, with the component-wise multiplication.
*/
/**
* Multiplies component-wise `other` and `this` points and outputs into `outPoint` or a new Point.
*
* _Note: Only available with **@pixi/math-extras**._
* @method multiply
* @memberof PIXI.ObservablePoint#
* @param {IPointData} other - The point to multiply with `this`.
* @param {IPointData} [outPoint] - A Point-like object in which to store the value,
* optional (otherwise will create a new Point).
* @returns {IPointData} The `outPoint` reference or a new Point, with the component-wise multiplication.
*/
multiply<T extends IPointData>(other: IPointData, outPoint?: T): T
{
if (!outPoint)
{
(outPoint as any) = new Point();
}
outPoint.x = this.x * other.x;
outPoint.y = this.y * other.y;
return outPoint;
},
/**
* Multiplies each component of `this` point with the number `scalar` and outputs into `outPoint` or a new Point.
*
* _Note: Only available with **@pixi/math-extras**._
* @method multiplyScalar
* @memberof PIXI.Point#
* @param {number} scalar - The number to multiply both components of `this`.
* @param {IPointData} [outPoint] - A Point-like object in which to store the value,
* optional (otherwise will create a new Point).
* @returns {IPointData} The `outPoint` reference or a new Point, with the multiplication.
*/
/**
* Multiplies each component of `this` point with the number `scalar` and outputs into `outPoint` or a new Point.
*
* _Note: Only available with **@pixi/math-extras**._
* @method multiplyScalar
* @memberof PIXI.ObservablePoint#
* @param {number} scalar - The number to multiply both components of `this`.
* @param {IPointData} [outPoint] - A Point-like object in which to store the value,
* optional (otherwise will create a new Point).
* @returns {IPointData} The `outPoint` reference or a new Point, with the multiplication.
*/
multiplyScalar<T extends IPointData>(scalar: number, outPoint?: T): T
{
if (!outPoint)
{
(outPoint as any) = new Point();
}
outPoint.x = this.x * scalar;
outPoint.y = this.y * scalar;
return outPoint;
},
/**
* Computes the dot product of `other` with `this` point.
* The dot product is the sum of the products of the corresponding components of two vectors.
*
* _Note: Only available with **@pixi/math-extras**._
* @method dot
* @memberof PIXI.Point#
* @param {IPointData} other - The other point to calculate the dot product with `this`.
* @returns {number} The result of the dot product. This is an scalar value.
*/
/**
* Computes the dot product of `other` with `this` point.
* The dot product is the sum of the products of the corresponding components of two vectors.
*
* _Note: Only available with **@pixi/math-extras**._
* @method dot
* @memberof PIXI.ObservablePoint#
* @param {IPointData} other - The other point to calculate the dot product with `this`.
* @returns {number} The result of the dot product. This is an scalar value.
*/
dot(other: IPointData): number
{
return (this.x * other.x) + (this.y * other.y);
},
/**
* Computes the cross product of `other` with `this` point.
* Given two linearly independent R3 vectors a and b, the cross product, a × b (read "a cross b"),
* is a vector that is perpendicular to both a and b, and thus normal to the plane containing them.
* While cross product only exists on 3D space, we can assume the z component of 2D to be zero and
* the result becomes a vector that will only have magnitude on the z axis.
*
* This function returns the z component of the cross product of the two points.
*
* _Note: Only available with **@pixi/math-extras**._
* @method cross
* @memberof PIXI.Point#
* @param {IPointData} other - The other point to calculate the cross product with `this`.
* @returns {number} The z component of the result of the cross product.
*/
/**
* Computes the cross product of `other` with `this` point.
* Given two linearly independent R3 vectors a and b, the cross product, a × b (read "a cross b"),
* is a vector that is perpendicular to both a and b, and thus normal to the plane containing them.
* While cross product only exists on 3D space, we can assume the z component of 2D to be zero and
* the result becomes a vector that will only have magnitude on the z axis.
*
* This function returns the z component of the cross product of the two points.
*
* _Note: Only available with **@pixi/math-extras**._
* @method cross
* @memberof PIXI.ObservablePoint#
* @param {IPointData} other - The other point to calculate the cross product with `this`.
* @returns {number} The z component of the result of the cross product.
*/
cross(other: IPointData): number
{
/*
* Returns the magnitude of the vector that would result
* from a regular 3D cross product of the input vectors,
* taking their Z values implicitly as 0
* (i.e. treating the 2D space as a plane in the 3D space).
* The 3D cross product will be perpendicular to that plane,
* and thus have 0 X & Y components
* (thus the scalar returned is the Z value of the 3D cross product vector).
*/
return (this.x * other.y) - (this.y * other.x);
},
/**
* Computes a normalized version of `this` point.
*
* A normalized vector is a vector of magnitude (length) 1
*
* _Note: Only available with **@pixi/math-extras**._
* @method normalize
* @memberof PIXI.Point#
* @param {IPointData} [outPoint] - A Point-like object in which to store the value,
* optional (otherwise will create a new Point).
* @returns {IPointData} The normalized point.
*/
/**
* Computes a normalized version of `this` point.
*
* A normalized vector is a vector of magnitude (length) 1
*
* _Note: Only available with **@pixi/math-extras**._
* @method normalize
* @memberof PIXI.ObservablePoint#
* @param {IPointData} [outPoint] - A Point-like object in which to store the value,
* optional (otherwise will create a new Point).
* @returns {IPointData} The normalized point.
*/
normalize<T extends IPointData>(outPoint?: T): T
{
if (!outPoint)
{
(outPoint as any) = new Point();
}
const magnitude = Math.sqrt((this.x * this.x) + (this.y * this.y));
outPoint.x = this.x / magnitude;
outPoint.y = this.y / magnitude;
return outPoint;
},
/**
* Computes the magnitude of this point (Euclidean distance from 0, 0).
*
* Defined as the square root of the sum of the squares of each component.
*
* _Note: Only available with **@pixi/math-extras**._
* @method magnitude
* @memberof PIXI.Point#
* @returns {number} The magnitude (length) of the vector.
*/
/**
* Computes the magnitude of this point (Euclidean distance from 0, 0).
*
* Defined as the square root of the sum of the squares of each component.
*
* _Note: Only available with **@pixi/math-extras**._
* @method magnitude
* @memberof PIXI.ObservablePoint#
* @returns {number} The magnitude (length) of the vector.
*/
magnitude(): number
{
return Math.sqrt((this.x * this.x) + (this.y * this.y));
},
/**
* Computes the square magnitude of this point.
* If you are comparing the lengths of vectors, you should compare the length squared instead
* as it is slightly more efficient to calculate.
*
* Defined as the sum of the squares of each component.
*
* _Note: Only available with **@pixi/math-extras**._
* @method magnitudeSquared
* @memberof PIXI.Point#
* @returns {number} The magnitude squared (length squared) of the vector.
*/
/**
* Computes the square magnitude of this point.
* If you are comparing the lengths of vectors, you should compare the length squared instead
* as it is slightly more efficient to calculate.
*
* Defined as the sum of the squares of each component.
*
* _Note: Only available with **@pixi/math-extras**._
* @method magnitudeSquared
* @memberof PIXI.ObservablePoint#
* @returns {number} The magnitude squared (length squared) of the vector.
*/
magnitudeSquared(): number
{
return (this.x * this.x) + (this.y * this.y);
},
/**
* Computes vector projection of `this` on `onto`.
*
* Imagine a light source, parallel to `onto`, above `this`.
* The light would cast rays perpendicular to `onto`.
* `this.project(onto)` is the shadow cast by `this` on the line defined by `onto` .
*
* _Note: Only available with **@pixi/math-extras**._
* @method project
* @memberof PIXI.Point#
* @param {IPointData} onto - A non zero vector describing a line on which to project `this`.
* @param {IPointData} [outPoint] - A Point-like object in which to store the value,
* optional (otherwise will create a new Point).
* @returns {IPointData} The `this` on `onto` projection.
*/
/**
* Computes vector projection of `this` on `onto`.
*
* Imagine a light source, parallel to `onto`, above `this`.
* The light would cast rays perpendicular to `onto`.
* `this.project(onto)` is the shadow cast by `this` on the line defined by `onto` .
*
* _Note: Only available with **@pixi/math-extras**._
* @method project
* @memberof PIXI.ObservablePoint#
* @param {IPointData} onto - A non zero vector describing a line on which to project `this`.
* @param {IPointData} [outPoint] - A Point-like object in which to store the value,
* optional (otherwise will create a new Point).
* @returns {IPointData} The `this` on `onto` projection.
*/
project<T extends IPointData>(onto: IPointData, outPoint?: T): T
{
if (!outPoint)
{
(outPoint as any) = new Point();
}
// Math says: a Projected over b = [(a·b) / (b·b)] * b;
const normalizedScalarProjection = ((this.x * onto.x) + (this.y * onto.y)) / ((onto.x * onto.x) + (onto.y * onto.y));
outPoint.x = onto.x * normalizedScalarProjection;
outPoint.y = onto.y * normalizedScalarProjection;
return outPoint;
},
/**
* Reflects `this` vector off of a plane orthogonal to `normal`.
* `normal` is not normalized during this process. Consider normalizing your `normal` before use.
*
* Imagine a light source bouncing onto a mirror.
* `this` vector is the light and `normal` is a vector perpendicular to the mirror.
* `this.reflect(normal)` is the reflection of `this` on that mirror.
*
* _Note: Only available with **@pixi/math-extras**._
* @method reflect
* @memberof PIXI.Point#
* @param {IPointData} normal - The normal vector of your reflecting plane.
* @param {IPointData} [outPoint] - A Point-like object in which to store the value,
* optional (otherwise will create a new Point).
* @returns {IPointData} The reflection of `this` on your reflecting plane.
*/
/**
* Reflects `this` vector off of a plane orthogonal to `normal`.
* `normal` is not normalized during this process. Consider normalizing your `normal` before use.
*
* Imagine a light source bouncing onto a mirror.
* `this` vector is the light and `normal` is a vector perpendicular to the mirror.
* `this.reflect(normal)` is the reflection of `this` on that mirror.
*
* _Note: Only available with **@pixi/math-extras**._
* @method reflect
* @memberof PIXI.ObservablePoint#
* @param {IPointData} normal - The normal vector of your reflecting plane.
* @param {IPointData} [outPoint] - A Point-like object in which to store the value,
* optional (otherwise will create a new Point).
* @returns {IPointData} The reflection of `this` on your reflecting plane.
*/
reflect<T extends IPointData>(normal: IPointData, outPoint?: T): T
{
if (!outPoint)
{
(outPoint as any) = new Point();
}
// Given an incident vector i and a normal vector n, returns the reflection vector r = i - 2 * dot(i, n) * n
const dotProduct = (this.x * normal.x) + (this.y * normal.y);
outPoint.x = this.x - (2 * dotProduct * normal.x);
outPoint.y = this.y - (2 * dotProduct * normal.y);
return outPoint;
}
};
Object.assign(Point.prototype, mixins);
Object.assign(ObservablePoint.prototype, mixins);