15#include "ALineSegment.h"
17#include <range/v3/algorithm/any_of.hpp>
28 return { .p1 = position, .p2 = position + size };
32 return { .p1 = position - size /
static_cast<T
>(2), .p2 = position + size /
static_cast<T
>(2) };
36 bool operator==(
const ARect&)
const noexcept =
default;
50 return { glm::max(p1.x, p2.x), glm::min(p1.y, p2.y) };
55 return { glm::min(p1.x, p2.x), glm::max(p1.y, p2.y) };
60 return glm::all(glm::greaterThan(other, p1)) && glm::all(glm::lessThan(other, p2));
64 bool isIntersects(
APoint2D<T> other)
const noexcept {
65 return glm::all(glm::greaterThanEqual(other, p1)) && glm::all(glm::lessThanEqual(other, p2));
69 std::array<APoint2D<T>, 4> vertices()
const noexcept {
70 return std::array<APoint2D<T>, 4>{
80 return (p1 + p2) /
static_cast<T
>(2);
85 return glm::min(p1, p2);
90 return glm::max(p1, p2);
94 T area()
const noexcept {
95 return size().x * size().y;
125 if (*
this == other) {
130 if (ranges::any_of(other.vertices(), [&](
APoint2D<T> p) { return isIntersects(p); })) {
135 if (ranges::any_of(vertices(), [&](
APoint2D<T> p) {
return other.isIntersects(p); })) {
140 auto verticalLines = [](
const ARect& r) {
141 return std::array<ALineSegment<T>, 2>{ r.leftLineSegment(), r.rightLineSegment() };
143 auto horizontalLines = [](
const ARect& r) {
144 return std::array<ALineSegment<T>, 2>{ r.topLineSegment(), r.bottomLineSegment() };
157 if (ranges::any_of(verticalLines(*
this), [&](
const ALineSegment<T>& l) {
158 return ranges::any_of(horizontalLines(other), [&](
const ALineSegment<T>& r) {
159 return l.isIntersects(r);
175 if (ranges::any_of(horizontalLines(*
this), [&](
const ALineSegment<T>& l) {
176 return ranges::any_of(verticalLines(other), [&](
const ALineSegment<T>& r) {
177 return l.isIntersects(r);
189 return glm::abs(p2 - p1);
192 ARect& translate(glm::ivec2 by)
noexcept {
glm::vec< 2, T > APoint2D
2D point.
Definition: APoint2D.h:21
2D line segment.
Definition: ALineSegment.h:22
Axis aligned 2D rectangle.
Definition: ARect.h:24
bool isIntersects(ARect other) const noexcept
Definition: ARect.h:123