region: add union operator for region/region
This commit is contained in:
parent
e9d5909f21
commit
3722c8aaa3
21
region.hpp
21
region.hpp
@ -201,7 +201,7 @@ namespace util {
|
||||
/// constructs the minimal region that encompasses a region and a point.
|
||||
template <typename T, size_t S>
|
||||
region<S,T>
|
||||
make_union (region<S,T> r, point<S,T> p)
|
||||
operator| (region<S,T> const r, point<S,T> const p)
|
||||
{
|
||||
const auto p0 = select (r.p < p, r.p, p);
|
||||
const auto p1 = select (r.away () > p, r.away (), p);
|
||||
@ -209,6 +209,25 @@ namespace util {
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
template <typename T, size_t S>
|
||||
auto
|
||||
operator| (point<S,T> const p, region<S,T> const r)
|
||||
{
|
||||
return r | p;
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
// construct a minimal bounding region over two supplied regions
|
||||
template <typename T, size_t S>
|
||||
region<S,T>
|
||||
operator| (region<S,T> const a, region<S,T> const b)
|
||||
{
|
||||
return a | b.base () | b.away ();
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
/// returns the squared minimum distance from a region to a given point
|
||||
template <size_t S, typename T>
|
||||
|
@ -59,20 +59,20 @@ main (int, char **)
|
||||
tap.expect (r.inclusive (util::point2f {2, 2}), "region/point inclusive, corner");
|
||||
}
|
||||
|
||||
// ensure make_union behaves as expected
|
||||
// ensure union operator behaves as expected
|
||||
{
|
||||
const util::point2f p { -1 };
|
||||
const util::extent2f e { 2 };
|
||||
const util::region2f r { p, e };
|
||||
|
||||
tap.expect_eq (util::make_union (r, util::point2f { 0, 0 }), r, "identity union");
|
||||
tap.expect_eq (r | util::point2f { 0, 0 }, r, "identity union");
|
||||
tap.expect_eq (
|
||||
util::make_union (r, util::point2f { 2, 3 }),
|
||||
r | util::point2f { 2, 3 },
|
||||
util::region2f { p, util::extent2f { 3, 4 } },
|
||||
"positive expanding union"
|
||||
);
|
||||
tap.expect_eq (
|
||||
util::make_union (r, util::point2f { -3, -2 }),
|
||||
r | util::point2f { -3, -2 },
|
||||
util::region2f {
|
||||
util::point2f { -3, -2 },
|
||||
util::extent2f { 4, 3 }
|
||||
|
Loading…
Reference in New Issue
Block a user