/* * Copyright (c) 2022, Andreas Kling * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include namespace Gfx { template class Quad { public: Quad(Point p1, Point p2, Point p3, Point p4) : m_p1(p1) , m_p2(p2) , m_p3(p3) , m_p4(p4) { } Point const& p1() const { return m_p1; } Point const& p2() const { return m_p2; } Point const& p3() const { return m_p3; } Point const& p4() const { return m_p4; } Rect bounding_rect() const { auto top = min(min(m_p1.y(), m_p2.y()), min(m_p3.y(), m_p4.y())); auto right = max(max(m_p1.x(), m_p2.x()), max(m_p3.x(), m_p4.x())); auto bottom = max(max(m_p1.y(), m_p2.y()), max(m_p3.y(), m_p4.y())); auto left = min(min(m_p1.x(), m_p2.x()), min(m_p3.x(), m_p4.x())); return { left, top, right - left, bottom - top }; } bool contains(Point point) const { // FIXME: There's probably a smarter way to do this. return Triangle(m_p1, m_p2, m_p3).contains(point) || Triangle(m_p1, m_p3, m_p4).contains(point) || Triangle(m_p2, m_p4, m_p1).contains(point) || Triangle(m_p2, m_p4, m_p3).contains(point); } private: Point m_p1; Point m_p2; Point m_p3; Point m_p4; }; }