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
|
var Vector2f = (function () {
function Vector2f(x, y) {
var _this = this;
if (((typeof x === 'number') || x === null) && ((typeof y === 'number') || y === null)) {
var __args = Array.prototype.slice.call(arguments);
this.__x = 0;
this.__y = 0;
this.__x = 0;
this.__y = 0;
(function () {
_this.__x = x;
_this.__y = y;
})();
}
else if (((x != null && x instanceof Vector2f) || x === null) && y === undefined) {
var __args = Array.prototype.slice.call(arguments);
var vector_1 = __args[0];
this.__x = 0;
this.__y = 0;
this.__x = 0;
this.__y = 0;
(function () {
_this.__x = new Number(vector_1.x()).valueOf();
_this.__y = new Number(vector_1.y()).valueOf();
})();
}
else if (x === undefined && y === undefined) {
var __args = Array.prototype.slice.call(arguments);
this.__x = 0;
this.__y = 0;
this.__x = 0;
this.__y = 0;
}
else
throw new Error('invalid overload');
}
Vector2f.prototype.equals = function (vector) {
if (this.__x === vector.x() && this.__y === vector.y())
return true;
return false;
};
Vector2f.prototype.x = function () {
return this.__x;
};
Vector2f.prototype.y = function () {
return this.__y;
};
Vector2f.prototype.setX = function (x) {
this.__x = x;
};
Vector2f.prototype.setY = function (y) {
this.__y = y;
};
Vector2f.prototype.addX = function (x) {
this.__x += x;
};
Vector2f.prototype.addY = function (y) {
this.__y += y;
};
Vector2f.prototype.subX = function (x) {
this.__x -= x;
};
Vector2f.prototype.subY = function (y) {
this.__y -= y;
};
Vector2f.prototype.mulX = function (x) {
this.__x *= x;
};
Vector2f.prototype.mulY = function (y) {
this.__y *= y;
};
Vector2f.prototype.divX = function (x) {
this.__x /= x;
};
Vector2f.prototype.divY = function (y) {
this.__y /= y;
};
Vector2f.prototype.setValues = function (x, y) {
this.__x = x;
this.__y = y;
};
Vector2f.prototype.set = function (value) {
this.__x = value.x();
this.__y = value.y();
};
Vector2f.prototype.bigger = function () {
return this.__x > this.__y ? this.__x : this.__y;
};
Vector2f.prototype.smaller = function () {
return this.__x > this.__y ? this.__y : this.__x;
};
Vector2f.prototype.sum = function () {
return this.__x + this.__y;
};
Vector2f.prototype.biggerthan = function (vector) {
return (this.__x > vector.x() && this.__y > vector.y());
};
Vector2f.prototype.smallerthan = function (vector) {
return (this.__x < vector.x() && this.__y < vector.y());
};
Vector2f.prototype.morePositiveValueThan = function (vector) {
return this.__x + this.__y > vector.x() + vector.y();
};
Vector2f.prototype.moreNegativeValueThan = function (vector) {
return this.__x + this.__y < vector.x() + vector.y();
};
Vector2f.prototype.swap = function (vector) {
var x = this.__x;
var y = this.__y;
this.set(vector);
vector.setValues(x, y);
};
Vector2f.prototype.isBetween = function (first, second) {
if (this.__x > first.x() && this.__x < second.x())
if (this.__y > first.y() && this.__y < second.y())
return true;
return false;
};
Vector2f.prototype.awayfrom = function (vector, distance) {
return Math.sqrt(Math.pow(this.__x - vector.x(), 2) + Math.pow(this.__y - vector.y(), 2)) > distance;
};
Vector2f.prototype.normalize = function (vector) {
return Math.sqrt(Math.pow(vector.x(), 2) + Math.pow(vector.y(), 2));
};
Vector2f.prototype.shoot = function (endpos) {
var shoot = new Vector2f(endpos.x() - this.__x, endpos.y() - this.__y);
var norme = this.normalize(shoot);
shoot.divide$float(norme);
return shoot;
};
Vector2f.prototype.randValueBetween = function (value) {
if (value.x() <= this.__x && value.y() <= this.__y)
return new Vector2f(value.x() + Math.random() * (this.__x - value.x()), value.y() + Math.random() * (this.__y - value.y()));
if (value.x() <= this.__x && value.y() >= this.__y)
return new Vector2f(value.x() + Math.random() * (this.__x - value.x()), this.__y + Math.random() * (value.x() - this.__y));
if (value.x() >= this.__x && value.y() <= this.__y)
return new Vector2f(this.__x + Math.random() * (value.x() - this.__x), value.y() + Math.random() * (this.__y - value.y()));
return new Vector2f(this.__x + Math.random() * (value.x() - this.__x), this.__y + Math.random() * (value.y() - this.__y));
};
Vector2f.prototype.scaledCopy = function (value) {
return new Vector2f(this.__x * value, this.__y * value);
};
Vector2f.prototype.divide$Vector2f = function (value) {
this.__x /= value.x();
this.__y /= value.y();
};
Vector2f.prototype.divide$float = function (value) {
this.__x /= value;
this.__y /= value;
};
Vector2f.prototype.divide$float$float = function (x, y) {
this.__x /= x;
this.__y /= y;
};
Vector2f.prototype.divide = function (x, y) {
if (((typeof x === 'number') || x === null) && ((typeof y === 'number') || y === null)) {
return this.divide$float$float(x, y);
}
else if (((x != null && x instanceof Vector2f) || x === null) && y === undefined) {
return this.divide$Vector2f(x);
}
else if (((typeof x === 'number') || x === null) && y === undefined) {
return this.divide$float(x);
}
else
throw new Error('invalid overload');
};
Vector2f.prototype.substract$Vector2f = function (value) {
this.__x -= value.x();
this.__y -= value.y();
};
Vector2f.prototype.substract$float = function (value) {
this.__x -= value;
this.__y -= value;
};
Vector2f.prototype.substract$float$float = function (x, y) {
this.__x -= x;
this.__y -= y;
};
Vector2f.prototype.substract = function (x, y) {
if (((typeof x === 'number') || x === null) && ((typeof y === 'number') || y === null)) {
return this.substract$float$float(x, y);
}
else if (((x != null && x instanceof Vector2f) || x === null) && y === undefined) {
return this.substract$Vector2f(x);
}
else if (((typeof x === 'number') || x === null) && y === undefined) {
return this.substract$float(x);
}
else
throw new Error('invalid overload');
};
Vector2f.prototype.add$Vector2f = function (value) {
this.__x += value.x();
this.__y += value.y();
};
Vector2f.prototype.add$float = function (value) {
this.__x += value;
this.__y += value;
};
Vector2f.prototype.add$float$float = function (x, y) {
this.__x += x;
this.__y += y;
};
Vector2f.prototype.add = function (x, y) {
if (((typeof x === 'number') || x === null) && ((typeof y === 'number') || y === null)) {
return this.add$float$float(x, y);
}
else if (((x != null && x instanceof Vector2f) || x === null) && y === undefined) {
return this.add$Vector2f(x);
}
else if (((typeof x === 'number') || x === null) && y === undefined) {
return this.add$float(x);
}
else
throw new Error('invalid overload');
};
Vector2f.prototype.multiply$Vector2f = function (value) {
this.__x *= value.x();
this.__y *= value.y();
};
Vector2f.prototype.multiply$float = function (value) {
this.__x *= value;
this.__y *= value;
};
Vector2f.prototype.multiply$float$float = function (x, y) {
this.__x *= x;
this.__y *= y;
};
Vector2f.prototype.multiply = function (x, y) {
if (((typeof x === 'number') || x === null) && ((typeof y === 'number') || y === null)) {
return this.multiply$float$float(x, y);
}
else if (((x != null && x instanceof Vector2f) || x === null) && y === undefined) {
return this.multiply$Vector2f(x);
}
else if (((typeof x === 'number') || x === null) && y === undefined) {
return this.multiply$float(x);
}
else
throw new Error('invalid overload');
};
Vector2f.prototype.pow$Vector2f$float = function (v, p) {
return new Vector2f((Math.pow(v.x(), p)), Math.pow(v.y(), p));
};
Vector2f.prototype.pow$Vector2f$Vector2f = function (v, p) {
return new Vector2f((Math.pow(v.x(), p.x())), Math.pow(v.y(), p.y()));
};
Vector2f.prototype.pow = function (v, p) {
if (((v != null && v instanceof Vector2f) || v === null) && ((p != null && p instanceof Vector2f) || p === null)) {
return this.pow$Vector2f$Vector2f(v, p);
}
else if (((v != null && v instanceof Vector2f) || v === null) && ((typeof p === 'number') || p === null)) {
return this.pow$Vector2f$float(v, p);
}
else
throw new Error('invalid overload');
};
Vector2f.prototype.toString = function () {
return new String(this.__x + ":" + this.__y);
};
return Vector2f;
}());
Vector2f["__class"] = "Vector2f"; |