@fivem-ts/shared
Version:
FiveM Typescript wrapper shared part
67 lines (66 loc) • 1.99 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Vector2 = void 0;
const _1 = require(".");
class Vector2 extends _1.Vector {
constructor(x, y) {
super(x, y);
}
get Length() {
return Math.sqrt(this.x * this.x + this.y * this.y);
}
get normalize() {
const length = this.Length;
if (length === 0)
return new Vector2(0, 0);
const normalizedX = this.x / length;
const normalizedY = this.y / length;
return new Vector2(normalizedX, normalizedY);
}
clone() {
return new Vector2(this.x, this.y);
}
distanceSquared(vector) {
const dx = this.x - vector.x;
const dy = this.y - vector.y;
return dx * dx + dy * dy;
}
distance(vector) {
return Math.sqrt(this.distanceSquared(vector));
}
crossProduct(vector) {
return this.x * vector.y - this.y * vector.x;
}
dotProduct(vector) {
return this.x * vector.x + this.y * vector.y;
}
add(vector) {
if (typeof vector === 'number') {
return new Vector2(this.x + vector, this.y + vector);
}
return new Vector2(this.x + vector.x, this.y + vector.y);
}
subtract(vector) {
if (typeof vector === 'number') {
return new Vector2(this.x - vector, this.y - vector);
}
return new Vector2(this.x - vector.x, this.y - vector.y);
}
multiply(vector) {
if (typeof vector === 'number') {
return new Vector2(this.x * vector, this.y * vector);
}
return new Vector2(this.x * vector.x, this.y * vector.y);
}
divide(vector) {
if (typeof vector === 'number') {
return new Vector2(this.x / vector, this.y / vector);
}
return new Vector2(this.x / vector.x, this.y / vector.y);
}
replace(vector) {
this.x = vector.x;
this.y = vector.y;
}
}
exports.Vector2 = Vector2;