1 /**
2  * Represents a 2D vector with double-precision.
3  *
4  * @author RGreenlees
5  * @author Kai Burjack
6  * @author F. Neurath
7  */
8 module doml.vector_2d;
9 
10 import Math = doml.math;
11 
12 import doml.vector_2i;
13 import doml.matrix_2d;
14 import doml.matrix_3x2d;
15 
16 /*
17  * The MIT License
18  *
19  * Copyright (c) 2015-2021 Richard Greenlees
20  $@#!$@# Translated by jordan4ibanez
21  *
22  * Permission is hereby granted, free of charge, to any person obtaining a copy
23  * of this software and associated documentation files (the "Software"), to deal
24  * in the Software without restriction, including without limitation the rights
25  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
26  * copies of the Software, and to permit persons to whom the Software is
27  * furnished to do so, subject to the following conditions:
28  *
29  * The above copyright notice and this permission notice shall be included in
30  * all copies or substantial portions of the Software.
31  *
32  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
33  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
34  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
35  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
36  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
37  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
38  * THE SOFTWARE.
39  */
40 
41 /**
42  * Represents a 2D vector with double-precision.
43  *
44  * @author RGreenlees
45  * @author Kai Burjack
46  * @author F. Neurath
47  */
48 struct Vector2d {
49 
50 
51     /**
52      * The x component of the vector.
53      */
54     double x = 0.0;
55     /**
56      * The y component of the vector.
57      */
58     double y = 0.0;
59 
60     /**
61      * Create a new {@link Vector2d} and initialize both of its components with the given value.
62      * 
63      * @param d    
64      *          the value of both components
65      */
66     this(double d) {
67         this.x = d;
68         this.y = d;
69     }
70 
71     /**
72      * Create a new {@link Vector2d} and initialize its components to the given values.
73      * 
74      * @param x
75      *          the x value
76      * @param y
77      *          the y value
78      */
79     this(double x, double y) {
80         this.x = x;
81         this.y = y;
82     }
83 
84     /**
85      * Create a new {@link Vector2d} and initialize its components to the one of the given vector.
86      * 
87      * @param v
88      *          the {@link Vector2d} to copy the values from
89      */
90     this(Vector2d v) {
91         x = v.x;
92         y = v.y;
93     }
94 
95     /**
96      * Create a new {@link Vector2d} and initialize its components to the one of the given vector.
97      * 
98      * @param v
99      *          the {@link Vector2i} to copy the values from
100      */
101     this(Vector2i v) {
102         x = v.x;
103         y = v.y;
104     }
105 
106     /**
107      * Create a new {@link Vector2d} and initialize its two components from the first
108      * two elements of the given array.
109      * 
110      * @param xy
111      *          the array containing at least three elements
112      */
113     this(double[] xy) {
114         this.x = xy[0];
115         this.y = xy[1];
116     }
117 
118     /**
119      * Set the x and y components to the supplied value.
120      *
121      * @param d
122      *          the value of both components
123      * @return this
124      */
125     ref public Vector2d set(double d) return {
126         this.x = d;
127         this.y = d;
128         return this;
129     }
130 
131     /**
132      * Set the x and y components to the supplied values.
133      * 
134      * @param x
135      *          the x value
136      * @param y
137      *          the y value
138      * @return this
139      */
140     ref public Vector2d set(double x, double y) return {
141         this.x = x;
142         this.y = y;
143         return this;
144     }
145 
146     /**
147      * Set this {@link Vector2d} to the values of v.
148      * 
149      * @param v
150      *          the vector to copy from
151      * @return this
152      */
153     ref public Vector2d set(Vector2d v) return {
154         this.x = v.x;
155         this.y = v.y;
156         return this;
157     }
158 
159 
160     /**
161      * Set this {@link Vector2d} to be a clone of <code>v</code>.
162      * 
163      * @param v
164      *          the vector to copy from
165      * @return this
166      */
167     ref public Vector2d set(Vector2i v) return {
168         this.x = v.x;
169         this.y = v.y;
170         return this;
171     }
172 
173     /**
174      * Set the two components of this vector to the first two elements of the given array.
175      * 
176      * @param xy
177      *          the array containing at least three elements
178      * @return this
179      */
180     ref public Vector2d set(double[] xy) return {
181         this.x = xy[0];
182         this.y = xy[1];
183         return this;
184     }
185 
186     public double get(int component) {
187         switch (component) {
188         case 0:
189             return x;
190         case 1:
191             return y;
192         default: 
193             return 0; // do nothing
194         }
195     }
196 
197     public Vector2i get(int mode, ref Vector2i dest) {
198         dest.x = Math.roundUsing(this.x, mode);
199         dest.y = Math.roundUsing(this.y, mode);
200         return dest;
201     }
202 
203     public Vector2d get(ref Vector2d dest) {
204         dest.x = this.x;
205         dest.y = this.y;
206         return dest;
207     }
208 
209     /**
210      * Set the value of the specified component of this vector.
211      *
212      * @param component
213      *          the component whose value to set, within <code>[0..1]</code>
214      * @param value
215      *          the value to set
216      * @return this
217      * @throws IllegalArgumentException if <code>component</code> is not within <code>[0..1]</code>
218      */
219     ref public Vector2d setComponent(int component, double value) return {
220         switch (component) {
221             case 0:
222                 x = value;
223                 break;
224             case 1:
225                 y = value;
226                 break;
227             default: {}
228         }
229         return this;
230     }
231 
232     /**
233      * Set this vector to be one of its perpendicular vectors.
234      * 
235      * @return this
236      */
237     ref public Vector2d perpendicular() return {
238         double xTemp = y;
239         this.y = x * -1;
240         this.x = xTemp;
241         return this;
242     }
243 
244     /**
245      * Subtract <code>v</code> from this vector.
246      * 
247      * @param v
248      *          the vector to subtract
249      * @return this
250      */
251     ref public Vector2d sub(Vector2d v) return {
252         this.x = x - v.x;
253         this.y = y - v.y;
254         return this;
255     }
256 
257     /**
258      * Subtract <code>(x, y)</code> from this vector.
259      * 
260      * @param x
261      *          the x component to subtract
262      * @param y
263      *          the y component to subtract
264      * @return this
265      */
266     ref public Vector2d sub(double x, double y) return {
267         this.x = this.x - x;
268         this.y = this.y - y;
269         return this;
270     }
271 
272     public Vector2d sub(double x, double y, ref Vector2d dest) {
273         dest.x = this.x - x;
274         dest.y = this.y - y;
275         return dest;
276     }
277 
278 
279     public Vector2d sub(Vector2d v, ref Vector2d dest) {
280         dest.x = x - v.x;
281         dest.y = y - v.y;
282         return dest;
283     }
284 
285 
286     /**
287      * Multiply the components of this vector by the given scalar.
288      * 
289      * @param scalar
290      *        the value to multiply this vector's components by
291      * @return this
292      */
293     ref public Vector2d mul(double scalar) return {
294         this.x = x * scalar;
295         this.y = y * scalar;
296         return this;
297     }
298 
299     public Vector2d mul(double scalar, ref Vector2d dest) {
300         dest.x = x * scalar;
301         dest.y = y * scalar;
302         return dest;
303     }
304 
305     /**
306      * Multiply the components of this Vector2d by the given scalar values and store the result in <code>this</code>.
307      * 
308      * @param x
309      *          the x component to multiply this vector by
310      * @param y
311      *          the y component to multiply this vector by
312      * @return this
313      */
314     ref public Vector2d mul(double x, double y) return {
315         this.x = this.x * x;
316         this.y = this.y * y;
317         return this;
318     }
319 
320     public Vector2d mul(double x, double y, ref Vector2d dest) {
321         dest.x = this.x * x;
322         dest.y = this.y * y;
323         return dest;
324     }
325 
326     /**
327      * Multiply this Vector2d component-wise by another Vector2d.
328      * 
329      * @param v
330      *          the vector to multiply by
331      * @return this
332      */
333     ref public Vector2d mul(Vector2d v) return {
334         this.x = x * v.x;
335         this.y = y * v.y;
336         return this;
337     }
338 
339     public Vector2d mul(Vector2d v, ref Vector2d dest) {
340         dest.x = x * v.x;
341         dest.y = y * v.y;
342         return dest;
343     }
344 
345     /**
346      * Divide this Vector2d by the given scalar value.
347      * 
348      * @param scalar
349      *          the scalar to divide this vector by
350      * @return this
351      */
352     ref public Vector2d div(double scalar) return {
353         double inv = 1.0 / scalar;
354         this.x = x * inv;
355         this.y = y * inv;
356         return this;
357     }
358 
359     public Vector2d div(double scalar, ref Vector2d dest) {
360         double inv = 1.0 / scalar;
361         dest.x = x * inv;
362         dest.y = y * inv;
363         return dest;
364     }
365 
366     /**
367      * Divide the components of this Vector2d by the given scalar values and store the result in <code>this</code>.
368      * 
369      * @param x
370      *          the x component to divide this vector by
371      * @param y
372      *          the y component to divide this vector by
373      * @return this
374      */
375     ref public Vector2d div(double x, double y) return {
376         this.x = this.x / x;
377         this.y = this.y / y;
378         return this;
379     }
380 
381     public Vector2d div(double x, double y, ref Vector2d dest) {
382         dest.x = this.x / x;
383         dest.y = this.y / y;
384         return dest;
385     }
386 
387     /**
388      * Divide this Vector2d component-wise by another Vector2d.
389      * 
390      * @param v
391      *          the vector to divide by
392      * @return this
393      */
394     ref public Vector2d div(Vector2d v) return {
395         this.x = x / v.x;
396         this.y = y / v.y;
397         return this;
398     }
399 
400 
401     public Vector2d div(Vector2d v, ref Vector2d dest) {
402         dest.x = x / v.x;
403         dest.y = y / v.y;
404         return dest;
405     }
406 
407     /**
408      * Multiply the given matrix <code>mat</code> with this Vector2d.
409      *
410      * @param mat
411      *          the matrix to multiply this vector by
412      * @return this
413      */
414     ref public Vector2d mul(Matrix2d mat) return {
415         double rx = mat.m00 * x + mat.m10 * y;
416         double ry = mat.m01 * x + mat.m11 * y;
417         this.x = rx;
418         this.y = ry;
419         return this;
420     }
421 
422     public Vector2d mul(Matrix2d mat, ref Vector2d dest) {
423         double rx = mat.m00 * x + mat.m10 * y;
424         double ry = mat.m01 * x + mat.m11 * y;
425         dest.x = rx;
426         dest.y = ry;
427         return dest;
428     }
429     /**
430      * Multiply the transpose of the given matrix with this Vector2d and store the result in <code>this</code>.
431      *
432      * @param mat
433      *          the matrix
434      * @return this
435      */
436     ref public Vector2d mulTranspose(Matrix2d mat) return {
437         double rx = mat.m00 * x + mat.m01 * y;
438         double ry = mat.m10 * x + mat.m11 * y;
439         this.x = rx;
440         this.y = ry;
441         return this;
442     }
443 
444     public Vector2d mulTranspose(Matrix2d mat, ref Vector2d dest) {
445         double rx = mat.m00 * x + mat.m01 * y;
446         double ry = mat.m10 * x + mat.m11 * y;
447         dest.x = rx;
448         dest.y = ry;
449         return dest;
450     }
451 
452     /**
453      * Multiply the given 3x2 matrix <code>mat</code> with <code>this</code>.
454      * <p>
455      * This method assumes the <code>z</code> component of <code>this</code> to be <code>1.0</code>.
456      * 
457      * @param mat
458      *          the matrix to multiply this vector by
459      * @return this
460      */
461     ref public Vector2d mulPosition(Matrix3x2d mat) return {
462         double rx = mat.m00 * x + mat.m10 * y + mat.m20;
463         double ry = mat.m01 * x + mat.m11 * y + mat.m21;
464         this.x = rx;
465         this.y = ry;
466         return this;
467     }
468 
469     public Vector2d mulPosition(Matrix3x2d mat, ref Vector2d dest) {
470         double rx = mat.m00 * x + mat.m10 * y + mat.m20;
471         double ry = mat.m01 * x + mat.m11 * y + mat.m21;
472         dest.x = rx;
473         dest.y = ry;
474         return dest;
475     }
476 
477     /**
478      * Multiply the given 3x2 matrix <code>mat</code> with <code>this</code>.
479      * <p>
480      * This method assumes the <code>z</code> component of <code>this</code> to be <code>0.0</code>.
481      * 
482      * @param mat
483      *          the matrix to multiply this vector by
484      * @return this
485      */
486     ref public Vector2d mulDirection(Matrix3x2d mat) return {
487         double rx = mat.m00 * x + mat.m10 * y;
488         double ry = mat.m01 * x + mat.m11 * y;
489         this.x = rx;
490         this.y = ry;
491         return this;
492     }
493 
494     public Vector2d mulDirection(Matrix3x2d mat, ref Vector2d dest) {
495         double rx = mat.m00 * x + mat.m10 * y;
496         double ry = mat.m01 * x + mat.m11 * y;
497         dest.x = rx;
498         dest.y = ry;
499         return dest;
500     }
501 
502     public double dot(Vector2d v) {
503         return x * v.x + y * v.y;
504     }
505 
506     public double angle(Vector2d v) {
507         double dot = x*v.x + y*v.y;
508         double det = x*v.y - y*v.x;
509         return Math.atan2(det, dot);
510     }
511 
512     public double lengthSquared() {
513         return x * x + y * y;
514     }
515 
516     /**
517      * Get the length squared of a 2-dimensional double-precision vector.
518      *
519      * @param x The vector's x component
520      * @param y The vector's y component
521      *
522      * @return the length squared of the given vector
523      *
524      * @author F. Neurath
525      */
526     public static double lengthSquared(double x, double y) {
527         return x * x + y * y;
528     }
529 
530     public double length() {
531         return Math.sqrt(x * x + y * y);
532     }
533 
534     /**
535      * Get the length of a 2-dimensional double-precision vector.
536      *
537      * @param x The vector's x component
538      * @param y The vector's y component
539      *
540      * @return the length of the given vector
541      *
542      * @author F. Neurath
543      */
544     public static double length(double x, double y) {
545         return Math.sqrt(x * x + y * y);
546     }
547 
548     public double distance(Vector2d v) {
549         double dx = this.x - v.x;
550         double dy = this.y - v.y;
551         return Math.sqrt(dx * dx + dy * dy);
552     }
553 
554     public double distanceSquared(Vector2d v) {
555         double dx = this.x - v.x;
556         double dy = this.y - v.y;
557         return dx * dx + dy * dy;
558     }
559 
560     public double distance(double x, double y) {
561         double dx = this.x - x;
562         double dy = this.y - y;
563         return Math.sqrt(dx * dx + dy * dy);
564     }
565 
566     public double distanceSquared(double x, double y) {
567         double dx = this.x - x;
568         double dy = this.y - y;
569         return dx * dx + dy * dy;
570     }
571 
572     /**
573      * Return the distance between <code>(x1, y1)</code> and <code>(x2, y2)</code>.
574      *
575      * @param x1
576      *          the x component of the first vector
577      * @param y1
578      *          the y component of the first vector
579      * @param x2
580      *          the x component of the second vector
581      * @param y2
582      *          the y component of the second vector
583      * @return the euclidean distance
584      */
585     public static double distance(double x1, double y1, double x2, double y2) {
586         double dx = x1 - x2;
587         double dy = y1 - y2;
588         return Math.sqrt(dx * dx + dy * dy);
589     }
590 
591     /**
592      * Return the squared distance between <code>(x1, y1)</code> and <code>(x2, y2)</code>.
593      *
594      * @param x1
595      *          the x component of the first vector
596      * @param y1
597      *          the y component of the first vector
598      * @param x2
599      *          the x component of the second vector
600      * @param y2
601      *          the y component of the second vector
602      * @return the euclidean distance squared
603      */
604     public static double distanceSquared(double x1, double y1, double x2, double y2) {
605         double dx = x1 - x2;
606         double dy = y1 - y2;
607         return dx * dx + dy * dy;
608     }
609 
610     /**
611      * Normalize this vector.
612      * 
613      * @return this
614      */
615     ref public Vector2d normalize() return {
616         double invLength = Math.invsqrt(x * x + y * y);
617         this.x = x * invLength;
618         this.y = y * invLength;
619         return this;
620     }
621 
622     public Vector2d normalize(ref Vector2d dest) {
623         double invLength = Math.invsqrt(x * x + y * y);
624         dest.x = x * invLength;
625         dest.y = y * invLength;
626         return dest;
627     }
628 
629     /**
630      * Scale this vector to have the given length.
631      * 
632      * @param length
633      *          the desired length
634      * @return this
635      */
636     ref public Vector2d normalize(double length) return {
637         double invLength = Math.invsqrt(x * x + y * y) * length;
638         this.x = x * invLength;
639         this.y = y * invLength;
640         return this;
641     }
642 
643     public Vector2d normalize(double length, ref Vector2d dest) {
644         double invLength = Math.invsqrt(x * x + y * y) * length;
645         dest.x = x * invLength;
646         dest.y = y * invLength;
647         return dest;
648     }
649 
650     /**
651      * Add <code>v</code> to this vector.
652      * 
653      * @param v
654      *          the vector to add
655      * @return this
656      */
657     ref public Vector2d add(Vector2d v) return {
658         this.x = x + v.x;
659         this.y = y + v.y;
660         return this;
661     }
662 
663     /**
664      * Add <code>(x, y)</code> to this vector.
665      * 
666      * @param x
667      *          the x component to add
668      * @param y
669      *          the y component to add
670      * @return this
671      */
672     ref public Vector2d add(double x, double y) return {
673         this.x = this.x + x;
674         this.y = this.y + y;
675         return this;
676     }
677 
678     public Vector2d add(double x, double y, ref Vector2d dest) {
679         dest.x = this.x + x;
680         dest.y = this.y + y;
681         return dest;
682     }
683 
684 
685     public Vector2d add(Vector2d v, ref Vector2d dest) {
686         dest.x = x + v.x;
687         dest.y = y + v.y;
688         return dest;
689     }
690 
691     /**
692      * Set all components to zero.
693      * 
694      * @return this
695      */
696     ref public Vector2d zero() return {
697         this.x = 0;
698         this.y = 0;
699         return this;
700     }
701 
702     /**
703      * Negate this vector.
704      * 
705      * @return this
706      */
707     ref public Vector2d negate() return {
708         this.x = -x;
709         this.y = -y;
710         return this;
711     }
712 
713     public Vector2d negate(ref Vector2d dest) {
714         dest.x = -x;
715         dest.y = -y;
716         return dest;
717     }
718 
719     /**
720      * Linearly interpolate <code>this</code> and <code>other</code> using the given interpolation factor <code>t</code>
721      * and store the result in <code>this</code>.
722      * <p>
723      * If <code>t</code> is <code>0.0</code> then the result is <code>this</code>. If the interpolation factor is <code>1.0</code>
724      * then the result is <code>other</code>.
725      * 
726      * @param other
727      *          the other vector
728      * @param t
729      *          the interpolation factor between 0.0 and 1.0
730      * @return this
731      */
732     ref public Vector2d lerp(Vector2d other, double t) return {
733         this.x = x + (other.x - x) * t;
734         this.y = y + (other.y - y) * t;
735         return this;
736     }
737 
738     public Vector2d lerp(Vector2d other, double t, ref Vector2d dest) {
739         dest.x = x + (other.x - x) * t;
740         dest.y = y + (other.y - y) * t;
741         return dest;
742     }
743 
744     public int hashCode() {
745         immutable int prime = 31;
746         int result = 1;
747         long temp;
748         temp = Math.doubleToLongBits(x);
749         result = prime * result + cast(int) (temp ^ (temp >>> 32));
750         temp = Math.doubleToLongBits(y);
751         result = prime * result + cast(int) (temp ^ (temp >>> 32));
752         return result;
753     }
754 
755     public bool equals(Vector2d v, double delta) {
756         if (this == v)
757             return true;
758         if (!Math.equals(x, v.x, delta))
759             return false;
760         if (!Math.equals(y, v.y, delta))
761             return false;
762         return true;
763     }
764 
765     public bool equals(double x, double y) {
766         if (Math.doubleToLongBits(this.x) != Math.doubleToLongBits(x))
767             return false;
768         if (Math.doubleToLongBits(this.y) != Math.doubleToLongBits(y))
769             return false;
770         return true;
771     }
772 
773     /**
774      * Add the component-wise multiplication of <code>a * b</code> to this vector.
775      * 
776      * @param a
777      *          the first multiplicand
778      * @param b
779      *          the second multiplicand
780      * @return this
781      */
782     ref public Vector2d fma(Vector2d a, Vector2d b) return {
783         this.x = x + a.x * b.x;
784         this.y = y + a.y * b.y;
785         return this;
786     }
787 
788     /**
789      * Add the component-wise multiplication of <code>a * b</code> to this vector.
790      * 
791      * @param a
792      *          the first multiplicand
793      * @param b
794      *          the second multiplicand
795      * @return this
796      */
797     ref public Vector2d fma(double a, Vector2d b) return {
798         this.x = x + a * b.x;
799         this.y = y + a * b.y;
800         return this;
801     }
802 
803     public Vector2d fma(Vector2d a, Vector2d b, ref Vector2d dest) {
804         dest.x = x + a.x * b.x;
805         dest.y = y + a.y * b.y;
806         return dest;
807     }
808 
809     public Vector2d fma(double a, Vector2d b, ref Vector2d dest) {
810         dest.x = x + a * b.x;
811         dest.y = y + a * b.y;
812         return dest;
813     }
814 
815     /**
816      * Set the components of this vector to be the component-wise minimum of this and the other vector.
817      *
818      * @param v
819      *          the other vector
820      * @return this
821      */
822     ref public Vector2d min(Vector2d v) return {
823         this.x = x < v.x ? x : v.x;
824         this.y = y < v.y ? y : v.y;
825         return this;
826     }
827 
828     public Vector2d min(Vector2d v, ref Vector2d dest) {
829         dest.x = x < v.x ? x : v.x;
830         dest.y = y < v.y ? y : v.y;
831         return dest;
832     }
833 
834     /**
835      * Set the components of this vector to be the component-wise maximum of this and the other vector.
836      *
837      * @param v
838      *          the other vector
839      * @return this
840      */
841     ref public Vector2d max(Vector2d v) return {
842         this.x = x > v.x ? x : v.x;
843         this.y = y > v.y ? y : v.y;
844         return this;
845     }
846 
847     public Vector2d max(Vector2d v, ref Vector2d dest) {
848         dest.x = x > v.x ? x : v.x;
849         dest.y = y > v.y ? y : v.y;
850         return dest;
851     }
852 
853     public int maxComponent() {
854         double absX = Math.abs(x);
855         double absY = Math.abs(y);
856         if (absX >= absY)
857             return 0;
858         return 1;
859     }
860 
861     public int minComponent() {
862         double absX = Math.abs(x);
863         double absY = Math.abs(y);
864         if (absX < absY)
865             return 0;
866         return 1;
867     }
868 
869     /**
870      * Set each component of this vector to the largest (closest to positive
871      * infinity) {@code double} value that is less than or equal to that
872      * component and is equal to a mathematical integer.
873      *
874      * @return this
875      */
876     ref public Vector2d floor() return {
877         this.x = Math.floor(x);
878         this.y = Math.floor(y);
879         return this;
880     }
881 
882     public Vector2d floor(ref Vector2d dest) {
883         dest.x = Math.floor(x);
884         dest.y = Math.floor(y);
885         return dest;
886     }
887 
888     /**
889      * Set each component of this vector to the smallest (closest to negative
890      * infinity) {@code double} value that is greater than or equal to that
891      * component and is equal to a mathematical integer.
892      *
893      * @return this
894      */
895     ref public Vector2d ceil() return {
896         this.x = Math.ceil(x);
897         this.y = Math.ceil(y);
898         return this;
899     }
900 
901     public Vector2d ceil(ref Vector2d dest) {
902         dest.x = Math.ceil(x);
903         dest.y = Math.ceil(y);
904         return dest;
905     }
906 
907     /**
908      * Set each component of this vector to the closest double that is equal to
909      * a mathematical integer, with ties rounding to positive infinity.
910      *
911      * @return this
912      */
913     ref public Vector2d round() return {
914         this.x = Math.round(x);
915         this.y = Math.round(y);
916         return this;
917     }
918 
919     public Vector2d round(ref Vector2d dest) {
920         dest.x = Math.round(x);
921         dest.y = Math.round(y);
922         return dest;
923     }
924 
925     public bool isFinite() {
926         return Math.isFinite(x) && Math.isFinite(y);
927     }
928 
929     /**
930      * Set <code>this</code> vector's components to their respective absolute values.
931      * 
932      * @return this
933      */
934     ref public Vector2d absolute() return {
935         this.x = Math.abs(this.x);
936         this.y = Math.abs(this.y);
937         return this;
938     }
939 
940     public Vector2d absolute(ref Vector2d dest) {
941         dest.x = Math.abs(this.x);
942         dest.y = Math.abs(this.y);
943         return dest;
944     }
945 
946 }