aboutsummaryrefslogtreecommitdiff
path: root/engines/titanic
diff options
context:
space:
mode:
Diffstat (limited to 'engines/titanic')
-rw-r--r--engines/titanic/star_control/fpoint.cpp9
-rw-r--r--engines/titanic/star_control/fpoint.h19
2 files changed, 28 insertions, 0 deletions
diff --git a/engines/titanic/star_control/fpoint.cpp b/engines/titanic/star_control/fpoint.cpp
index f3d7008324..a2829572f8 100644
--- a/engines/titanic/star_control/fpoint.cpp
+++ b/engines/titanic/star_control/fpoint.cpp
@@ -21,8 +21,17 @@
*/
#include "titanic/star_control/fpoint.h"
+#include "common/algorithm.h"
namespace Titanic {
+void FPoint::normalize() {
+ double hyp = sqrt(_x * _x + _y * _y);
+ assert(hyp != 0.0);
+
+ double fraction = 1.0 / hyp;
+ _x *= fraction;
+ _y *= fraction;
+}
} // End of namespace Titanic
diff --git a/engines/titanic/star_control/fpoint.h b/engines/titanic/star_control/fpoint.h
index f2cef18ea5..33181d937b 100644
--- a/engines/titanic/star_control/fpoint.h
+++ b/engines/titanic/star_control/fpoint.h
@@ -34,6 +34,25 @@ public:
public:
FPoint() : _x(0), _y(0) {}
FPoint(double x, double y) : _x(x), _y(y) {}
+
+ bool operator==(const FPoint &p) const { return _x == p._x && _y == p._y; }
+ bool operator!=(const FPoint &p) const { return _x != p._x || _y != p._y; }
+
+ void operator+=(const FPoint &delta) {
+ _x += delta._x;
+ _y += delta._y;
+ }
+
+ void operator-=(const FPoint &delta) {
+ _x -= delta._x;
+ _y -= delta._y;
+ }
+
+ /**
+ * Normalises the X and Y coordinates as fractions relative to the
+ * value of the hypotenuse formed by a triangle from the origin (0,0)
+ */
+ void normalize();
};
} // End of namespace Titanic