66 lines
1.7 KiB
C++
66 lines
1.7 KiB
C++
#ifndef Segment_h_
|
|
#define Segment_h_
|
|
|
|
#include <ostream>
|
|
#include <algorithm>
|
|
#include <cmath>
|
|
|
|
#include "glm/vec2.hpp"
|
|
|
|
class Box;
|
|
struct Sprite;
|
|
|
|
class Segment
|
|
{
|
|
|
|
public:
|
|
|
|
glm::vec2 start, end;
|
|
|
|
Segment(const glm::vec2&, const glm::vec2&);
|
|
Segment();
|
|
Segment(const glm::vec2&);
|
|
Segment(const Box&, const Box&);
|
|
Segment(const Sprite&, const Sprite&);
|
|
glm::vec2 get_start() const;
|
|
void set_start(const glm::vec2&);
|
|
glm::vec2 get_end() const;
|
|
void set_end(const glm::vec2&);
|
|
bool intersect(const Segment&, glm::vec2* = nullptr) const;
|
|
bool intersect(const Segment&, glm::vec2&) const;
|
|
float get_dx() const;
|
|
float get_dy() const;
|
|
float get_length() const;
|
|
Box get_box() const;
|
|
void move(const glm::vec2&);
|
|
glm::vec2 get_center() const;
|
|
glm::vec2 get_step(float) const;
|
|
glm::vec2 get_step_relative(float) const;
|
|
std::vector<Segment> get_subsegments(int) const;
|
|
inline bool operator<(const Segment& segment) const { return operator<(segment.get_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<typename N>
|
|
inline bool operator<(const N& other) const { return get_length() < other; }
|
|
|
|
template<typename N>
|
|
inline bool operator>(const N& other) const { return other < get_length(); }
|
|
|
|
template<typename N>
|
|
inline bool operator<=(const N& other) const { return !operator>(other); }
|
|
|
|
template<typename N>
|
|
inline bool operator>=(const N& other) const { return !operator<(other); }
|
|
|
|
};
|
|
|
|
std::ostream& operator<<(std::ostream&, const Segment&);
|
|
|
|
#endif
|