ladybird/Userland/Libraries/LibGfx/Triangle.h
Ali Mohammad Pur 5e1499d104 Everywhere: Rename {Deprecated => Byte}String
This commit un-deprecates DeprecatedString, and repurposes it as a byte
string.
As the null state has already been removed, there are no other
particularly hairy blockers in repurposing this type as a byte string
(what it _really_ is).

This commit is auto-generated:
  $ xs=$(ack -l \bDeprecatedString\b\|deprecated_string AK Userland \
    Meta Ports Ladybird Tests Kernel)
  $ perl -pie 's/\bDeprecatedString\b/ByteString/g;
    s/deprecated_string/byte_string/g' $xs
  $ clang-format --style=file -i \
    $(git diff --name-only | grep \.cpp\|\.h)
  $ gn format $(git ls-files '*.gn' '*.gni')
2023-12-17 18:25:10 +03:30

61 lines
1.3 KiB
C++

/*
* Copyright (c) 2020, Shannon Booth <shannon@serenityos.org>
* Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/Forward.h>
#include <LibGfx/Point.h>
namespace Gfx {
template<typename T>
class Triangle {
public:
Triangle(Point<T> a, Point<T> b, Point<T> 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<T> a() const { return m_a; }
Point<T> b() const { return m_b; }
Point<T> c() const { return m_c; }
bool contains(Point<T> 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;
}
ByteString to_byte_string() const;
private:
T m_determinant { 0 };
Point<T> m_a;
Point<T> m_b;
Point<T> m_c;
};
}