1 //Copyright (c) 2018 Ultimaker B.V. 2 //CuraEngine is released under the terms of the AGPLv3 or higher. 3 4 #ifndef VELOCITY_H 5 #define VELOCITY_H 6 7 namespace cura 8 { 9 10 /* 11 * Represents a velocity in millimetres per second. 12 * 13 * This is a facade. It behaves like a double, only it can't be negative. 14 */ 15 struct Velocity 16 { 17 /* 18 * \brief Default constructor setting velocity to 0. 19 */ VelocityVelocity20 constexpr Velocity() : value(0.0) {}; 21 22 /* 23 * \brief Casts a double to a Velocity instance. 24 */ VelocityVelocity25 constexpr Velocity(double value) : value(value) {}; 26 27 /* 28 * \brief Casts the Temperature instance to a double. 29 */ 30 constexpr operator double() const 31 { 32 return value; 33 } 34 35 /* 36 * Some operators for arithmetic on velocities. 37 */ 38 Velocity operator *(const Velocity& other) const 39 { 40 return Velocity(value * other.value); 41 } 42 template<typename E> Velocity operator *(const E& other) const 43 { 44 return Velocity(value * other); 45 } 46 Velocity operator /(const Velocity& other) const 47 { 48 return Velocity(value / other.value); 49 } 50 template<typename E> Velocity operator /(const E& other) const 51 { 52 return Velocity(value / other); 53 } 54 Velocity& operator *=(const Velocity& other) 55 { 56 value *= other.value; 57 return *this; 58 } 59 template<typename E> Velocity& operator *=(const E& other) 60 { 61 value *= other; 62 return *this; 63 } 64 Velocity& operator /=(const Velocity& other) 65 { 66 value /= other.value; 67 return *this; 68 } 69 template<typename E> Velocity& operator /=(const E& other) 70 { 71 value /= other; 72 return *this; 73 } 74 75 /* 76 * \brief The actual temperature, as a double. 77 */ 78 double value = 0; 79 }; 80 81 using Acceleration = Velocity; //Use the same logic for acceleration variables. 82 83 } 84 85 #endif //VELOCITY_H