/* * Copyright (c) 2020, Shannon Booth * Copyright (c) 2022, Andreas Kling * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include namespace Gfx { template class Triangle { public: Triangle(Point a, Point b, Point c) : m_a(a) , m_b(b) , m_c(c) { m_determinant = (m_b.x() - m_a.x()) * (m_c.y() - m_a.y()) - (m_b.y() - m_a.y()) * (m_c.x() - m_a.x()); } Point a() const { return m_a; } Point b() const { return m_b; } Point c() const { return m_c; } bool contains(Point p) const { auto x = p.x(); auto y = p.y(); auto ax = m_a.x(); auto bx = m_b.x(); auto cx = m_c.x(); auto ay = m_a.y(); auto by = m_b.y(); auto cy = m_c.y(); if (m_determinant * ((bx - ax) * (y - ay) - (by - ay) * (x - ax)) <= 0) return false; if (m_determinant * ((cx - bx) * (y - by) - (cy - by) * (x - bx)) <= 0) return false; if (m_determinant * ((ax - cx) * (y - cy) - (ay - cy) * (x - cx)) <= 0) return false; return true; } DeprecatedString to_deprecated_string() const; private: T m_determinant { 0 }; Point m_a; Point m_b; Point m_c; }; }