BUGFIX: Elevators did not handle Requests in the correct order
[cs356-p1-elevator.git] / position.cpp
index f1cfc90..1d4a293 100644 (file)
@@ -44,7 +44,18 @@ Position& Position::operator+= (const float rhs)
 
 Position& Position::operator-= (const float rhs)
 {
-       *this += -rhs;
+       int major = (int)rhs;
+       int minor = (int)((rhs - major) * 10);
+
+       major_ -= major;
+       minor_ -= minor;
+
+       /* Check for underflow */
+       if (minor_ < 0)
+       {
+               major_ -= 1;
+               minor_ += 10;
+       }
 
        return *this;
 }
@@ -103,6 +114,11 @@ Position::operator float() const
        return temp;
 }
 
+Position::operator int() const
+{
+       return major_;
+}
+
 std::ostream& operator<< (std::ostream& os, const Position& rhs)
 {
        os << "Position(" << rhs.major_ << "." << rhs.minor_ << ")";