diff options
author | Matt Strapp <matt@mattstrapp.net> | 2021-09-20 18:15:14 -0500 |
---|---|---|
committer | Matt Strapp <matt@mattstrapp.net> | 2021-09-20 18:15:14 -0500 |
commit | 342403a02f8063903d0f38327430721d4d0ae331 (patch) | |
tree | 29d020a27bc16939c568dd4b29166566d1c0e658 /dev/MinGfx/src/point2.cc | |
parent | Fix parenthesis (diff) | |
download | csci4611-submission-p1.0.tar csci4611-submission-p1.0.tar.gz csci4611-submission-p1.0.tar.bz2 csci4611-submission-p1.0.tar.lz csci4611-submission-p1.0.tar.xz csci4611-submission-p1.0.tar.zst csci4611-submission-p1.0.zip |
do ass1submission-p1.0
Diffstat (limited to '')
-rw-r--r-- | dev/MinGfx/src/point2.cc | 208 |
1 files changed, 104 insertions, 104 deletions
diff --git a/dev/MinGfx/src/point2.cc b/dev/MinGfx/src/point2.cc index 9d98777..b7acf68 100644 --- a/dev/MinGfx/src/point2.cc +++ b/dev/MinGfx/src/point2.cc @@ -1,104 +1,104 @@ -/* - Copyright (c) 2017,2018 Regents of the University of Minnesota. - All Rights Reserved. - See corresponding header file for details. - */ - -#include "point2.h" - -#include <math.h> - -namespace mingfx { - -static const Point2 s_zerop2d = Point2(0,0); -static const Point2 s_onep2d = Point2(1,1); - -const Point2& Point2::Origin() { return s_zerop2d; } -const Point2& Point2::Zero() { return s_zerop2d; } -const Point2& Point2::One() { return s_onep2d; } - - -Point2::Point2() { - p[0] = 0.0; - p[1] = 0.0; -} - -Point2::Point2(float x, float y) { - p[0] = x; - p[1] = y; -} - -Point2::Point2(float *ptr) { - p[0] = ptr[0]; - p[1] = ptr[1]; -} - -Point2::Point2(const Point2& other) { - p[0] = other[0]; - p[1] = other[1]; -} - -Point2::~Point2() { -} - -bool Point2::operator==(const Point2& other) const { - return (fabs(other[0] - p[0]) < MINGFX_MATH_EPSILON && - fabs(other[1] - p[1]) < MINGFX_MATH_EPSILON); -} - -bool Point2::operator!=(const Point2& other) const { - return (fabs(other[0] - p[0]) >= MINGFX_MATH_EPSILON || - fabs(other[1] - p[1]) >= MINGFX_MATH_EPSILON); -} - -Point2& Point2::operator=(const Point2& other) { - p[0] = other[0]; - p[1] = other[1]; - return *this; -} - -float Point2::operator[](const int i) const { - if ((i>=0) && (i<=1)) { - return p[i]; - } - else { - // w component of a point is 1 so return the constant 1.0 - return 1.0; - } -} - -float& Point2::operator[](const int i) { - return p[i]; -} - - -Point2 Point2::Lerp(const Point2 &b, float alpha) const { - float x = (1.0f-alpha)*(*this)[0] + alpha*b[0]; - float y = (1.0f-alpha)*(*this)[1] + alpha*b[1]; - return Point2(x,y); -} - -Point2 Point2::Lerp(const Point2 &a, const Point2 &b, float alpha) { - float x = (1.0f-alpha)*a[0] + alpha*b[0]; - float y = (1.0f-alpha)*a[1] + alpha*b[1]; - return Point2(x,y); -} - - -const float * Point2::value_ptr() const { - return p; -} - - -std::ostream & operator<< ( std::ostream &os, const Point2 &p) { - return os << "(" << p[0] << ", " << p[1] << ")"; -} - -std::istream & operator>> ( std::istream &is, Point2 &p) { - // format: (x, y) - char dummy; - return is >> dummy >> p[0] >> dummy >> p[1] >> dummy; -} - - -} // end namespace +/*
+ Copyright (c) 2017,2018 Regents of the University of Minnesota.
+ All Rights Reserved.
+ See corresponding header file for details.
+ */
+
+#include "point2.h"
+
+#include <math.h>
+
+namespace mingfx {
+
+static const Point2 s_zerop2d = Point2(0,0);
+static const Point2 s_onep2d = Point2(1,1);
+
+const Point2& Point2::Origin() { return s_zerop2d; }
+const Point2& Point2::Zero() { return s_zerop2d; }
+const Point2& Point2::One() { return s_onep2d; }
+
+
+Point2::Point2() {
+ p[0] = 0.0;
+ p[1] = 0.0;
+}
+
+Point2::Point2(float x, float y) {
+ p[0] = x;
+ p[1] = y;
+}
+
+Point2::Point2(float *ptr) {
+ p[0] = ptr[0];
+ p[1] = ptr[1];
+}
+
+Point2::Point2(const Point2& other) {
+ p[0] = other[0];
+ p[1] = other[1];
+}
+
+Point2::~Point2() {
+}
+
+bool Point2::operator==(const Point2& other) const {
+ return (fabs(other[0] - p[0]) < MINGFX_MATH_EPSILON &&
+ fabs(other[1] - p[1]) < MINGFX_MATH_EPSILON);
+}
+
+bool Point2::operator!=(const Point2& other) const {
+ return (fabs(other[0] - p[0]) >= MINGFX_MATH_EPSILON ||
+ fabs(other[1] - p[1]) >= MINGFX_MATH_EPSILON);
+}
+
+Point2& Point2::operator=(const Point2& other) {
+ p[0] = other[0];
+ p[1] = other[1];
+ return *this;
+}
+
+float Point2::operator[](const int i) const {
+ if ((i>=0) && (i<=1)) {
+ return p[i];
+ }
+ else {
+ // w component of a point is 1 so return the constant 1.0
+ return 1.0;
+ }
+}
+
+float& Point2::operator[](const int i) {
+ return p[i];
+}
+
+
+Point2 Point2::Lerp(const Point2 &b, float alpha) const {
+ float x = (1.0f-alpha)*(*this)[0] + alpha*b[0];
+ float y = (1.0f-alpha)*(*this)[1] + alpha*b[1];
+ return Point2(x,y);
+}
+
+Point2 Point2::Lerp(const Point2 &a, const Point2 &b, float alpha) {
+ float x = (1.0f-alpha)*a[0] + alpha*b[0];
+ float y = (1.0f-alpha)*a[1] + alpha*b[1];
+ return Point2(x,y);
+}
+
+
+const float * Point2::value_ptr() const {
+ return p;
+}
+
+
+std::ostream & operator<< ( std::ostream &os, const Point2 &p) {
+ return os << "(" << p[0] << ", " << p[1] << ")";
+}
+
+std::istream & operator>> ( std::istream &is, Point2 &p) {
+ // format: (x, y)
+ char dummy;
+ return is >> dummy >> p[0] >> dummy >> p[1] >> dummy;
+}
+
+
+} // end namespace
|