#ifndef Segment_h_ #define Segment_h_ #include #include #include #include "glm/vec2.hpp" class Box; struct Sprite; class Segment { private: glm::vec2 start_, end_; public: Segment(const glm::vec2&, const glm::vec2&); Segment(); Segment(const glm::vec2&); Segment(const Box&, const Box&); Segment(const Sprite&, const Sprite&); glm::vec2 start() const; void start(const glm::vec2&); glm::vec2 end() const; void end(const glm::vec2&); bool intersect(const Segment&, glm::vec2* = nullptr) const; bool intersect(const Segment&, glm::vec2&) const; float dx() const; float dy() const; float length() const; Box box() const; void move(const glm::vec2&); glm::vec2 center() const; glm::vec2 step(float) const; glm::vec2 step_relative(float) const; std::vector subsegments(int) const; inline bool operator<(const Segment& segment) const { return operator<(segment.length()); } /* std::cout << (a < b) << (a > b) << (b < c) << (b <= c) << (c > b) << (c >= b) << (d < 1) << (d < 2) << (d >= a) << (d > c) << std::endl; should print 0101010101 */ template inline bool operator<(const N& other) const { return length() < other; } template inline bool operator>(const N& other) const { return other < length(); } template inline bool operator<=(const N& other) const { return !operator>(other); } template inline bool operator>=(const N& other) const { return !operator<(other); } }; std::ostream& operator<<(std::ostream&, const Segment&); #endif