libcruft-util/cruft/util/geom/tri.cpp

36 lines
1010 B
C++

/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* Copyright 2016-2018 Danny Robson <danny@nerdcruft.net>
*/
#include "tri.hpp"
///////////////////////////////////////////////////////////////////////////////
template <typename T>
bool
cruft::geom::inclusive (tri2<T> const &obj, point2<T> const &p)
{
// Assumes ccw winding
CHECK (cross (obj.b - obj.a, obj.c - obj.a) > 0);
auto const sign = [] (
cruft::point2f const p_,
cruft::point2f const a_,
cruft::point2f const b_)
{
return cross (p_ - a_, b_ - a_);
};
return sign (p, obj.a, obj.b) <= 0
and sign (p, obj.b, obj.c) <= 0
and sign (p, obj.c, obj.a) <= 0;
}
//-----------------------------------------------------------------------------
template bool cruft::geom::inclusive (tri2<f32> const&, point2<f32> const&);