// DR. ROBOTNIK'S RING RACERS //----------------------------------------------------------------------------- // Copyright (C) 2023 by James Robert Roman // // This program is free software distributed under the // terms of the GNU General Public License, version 2. // See the 'LICENSE' file for more details. //----------------------------------------------------------------------------- #ifndef math_line_segment_hpp #define math_line_segment_hpp #include #include #include "vec.hpp" namespace srb2::math { template struct LineSegment { using vec2 = Vec2; using view = std::pair; vec2 a, b; LineSegment(vec2 a_, vec2 b_) : a(a_), b(b_) {} template LineSegment(const LineSegment& b) : LineSegment(b.a, b.b) {} bool horizontal() const { return a.y == b.y; } bool vertical() const { return a.x == b.x; } view by_x() const { return std::minmax(a, b, [](auto& a, auto& b) { return a.x < b.x; }); } view by_y() const { return std::minmax(a, b, [](auto& a, auto& b) { return a.y < b.y; }); } }; }; // namespace srb2 #endif/*math_line_segment_hpp*/