VIPRA Documentation
Loading...
Searching...
No Matches
geometry.hpp
1#pragma once
2
3#include <concepts>
4
5#include "vipra/geometry/circle.hpp"
6#include "vipra/geometry/line.hpp"
7#include "vipra/geometry/rectangle.hpp"
8#include "vipra/geometry/triangle.hpp"
9
10namespace VIPRA::Geometry {
11
12template <typename class_t>
13concept has_sides = requires(class_t instance) {
14 { instance.sides() };
15};
16
17template <has_sides polygon_t, has_sides other_t>
18VIPRA_POLY_FUNC auto do_intersect(polygon_t const& polygon,
19 other_t const& other) noexcept -> bool
20{
21 auto const sideList = polygon.sides();
22 return std::any_of(sideList.begin(), sideList.end(), [&](Line const& side) {
23 auto const otherSides = other.sides();
24 return std::any_of(otherSides.begin(), otherSides.end(), [&](Line const& otherSide) {
25 return otherSide.does_intersect(side);
26 });
27 });
28}
29
30template <has_sides polygon_t>
31VIPRA_POLY_FUNC auto do_intersect(polygon_t const& polygon,
32 Line const& line) noexcept -> bool
33{
34 auto const sideList = polygon.sides();
35 return std::any_of(sideList.begin(), sideList.end(),
36 [&](Line const& side) { return line.does_intersect(side); });
37}
38
39template <has_sides polygon_t>
40VIPRA_POLY_FUNC auto do_intersect(Line const& line,
41 polygon_t const& polygon) noexcept -> bool
42{
43 auto const sideList = polygon.sides();
44 return std::any_of(sideList.begin(), sideList.end(),
45 [&](Line const& side) { return line.does_intersect(side); });
46}
47
48template <has_sides polygon_t>
49VIPRA_POLY_FUNC auto do_intersect(polygon_t const& polygon,
50 Circle const& circle) noexcept -> bool
51{
52 auto const sideList = polygon.sides();
53 return std::any_of(sideList.begin(), sideList.end(),
54 [&](Line const& side) { return circle.does_intersect(side); });
55}
56
57template <has_sides polygon_t>
58VIPRA_POLY_FUNC auto do_intersect(Circle const& circle,
59 polygon_t const& polygon) noexcept -> bool
60{
61 auto const sideList = polygon.sides();
62 return std::any_of(sideList.begin(), sideList.end(),
63 [&](Line const& side) { return circle.does_intersect(side); });
64}
65
66} // namespace VIPRA::Geometry
Definition geometry.hpp:13
Definition line.hpp:11