Skip to content
Snippets Groups Projects
Commit 76e2f2ad authored by Philip Trettner's avatar Philip Trettner
Browse files

Merge branch 'kschuster' into 'develop'

Fixed obtuseness tests to return bool.

See merge request !35
parents 5bc262e4 89b9c0a5
No related branches found
No related tags found
1 merge request!35Fixed obtuseness tests to return bool.
......@@ -3,6 +3,7 @@
#include <typed-geometry/functions/aabb.hh>
#include <typed-geometry/functions/angle.hh>
#include <typed-geometry/functions/area.hh>
#include <typed-geometry/functions/bounds.hh>
#include <typed-geometry/functions/centroid.hh>
#include <typed-geometry/functions/closest_points.hh>
#include <typed-geometry/functions/contains.hh>
......
#pragma once
#include <typed-geometry/functions/interpolate.hh>
#include <typed-geometry/tests/triangle_tests.hh>
#include <typed-geometry/types/objects/sphere.hh>
#include <typed-geometry/types/objects/triangle.hh>
namespace tg
{
template <int D, class ScalarT>
TG_NODISCARD constexpr sphere<D, ScalarT> bounding_sphere_of(triangle<D, ScalarT> const& t)
{
auto e0sqr = distance_sqr(t.pos0, t.pos1);
auto e1sqr = distance_sqr(t.pos1, t.pos2);
auto e2sqr = distance_sqr(t.pos2, t.pos0);
auto const* a = &t.pos2;
auto const* b = &t.pos0;
auto const* c = &t.pos1;
// "rotate" triangle s.t. e0 is the largest edge and
// lies opposite of point a (equivalently, e1 <-> b, e2 <-> c)
if (e2sqr > e1sqr)
{
// make e1 larger than e2
tg::detail::swap(e1sqr, e2sqr);
tg::detail::swap(b, c);
}
if (e1sqr > e0sqr)
{
// make e0 larger than e1
tg::detail::swap(e0sqr, e1sqr);
tg::detail::swap(a, b);
}
if (e0sqr >= e1sqr + e2sqr) // triangle is obtuse or right
{
auto radius = tg::sqrt(e0sqr) / ScalarT(2);
auto center = mix(*b, *c, ScalarT(0.5));
return {center, radius};
}
// compute barycentric coords
auto alpha = e0sqr * (e1sqr + e2sqr - e0sqr);
auto beta = e1sqr * (e2sqr + e0sqr - e1sqr);
auto gamma = e2sqr * (e0sqr + e1sqr - e2sqr);
auto bary_sum = alpha + beta + gamma;
auto center = tg::interpolate(triangle(*a, *b, *c), alpha, beta, gamma) / bary_sum;
auto radius = tg::distance(center, t.pos0);
return {center, radius};
}
}
......@@ -35,25 +35,25 @@ TG_NODISCARD constexpr triangle_obtuseness classify_obtuseness(triangle<D, Scala
}
template <int D, class ScalarT>
TG_NODISCARD constexpr triangle_obtuseness is_obtuse_triangle(triangle<D, ScalarT> const& t)
TG_NODISCARD constexpr bool is_obtuse_triangle(triangle<D, ScalarT> const& t)
{
return classify_obtuseness(t) == triangle_obtuseness::obtuse;
}
template <int D, class ScalarT>
TG_NODISCARD constexpr triangle_obtuseness is_right_triangle(triangle<D, ScalarT> const& t)
TG_NODISCARD constexpr bool is_right_triangle(triangle<D, ScalarT> const& t)
{
return classify_obtuseness(t) == triangle_obtuseness::right;
}
template <int D, class ScalarT>
TG_NODISCARD constexpr triangle_obtuseness is_nonobtuse_triangle(triangle<D, ScalarT> const& t)
TG_NODISCARD constexpr bool is_nonobtuse_triangle(triangle<D, ScalarT> const& t)
{
return classify_obtuseness(t) != triangle_obtuseness::obtuse;
}
template <int D, class ScalarT>
TG_NODISCARD constexpr triangle_obtuseness is_acute_triangle(triangle<D, ScalarT> const& t)
TG_NODISCARD constexpr bool is_acute_triangle(triangle<D, ScalarT> const& t)
{
return classify_obtuseness(t) == triangle_obtuseness::acute;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment