region: add make_union function
This commit is contained in:
parent
0016c83dab
commit
01f6e5a1e8
13
region.hpp
13
region.hpp
@ -111,6 +111,19 @@ namespace util {
|
|||||||
void sanity (void) const;
|
void sanity (void) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
/// 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)
|
||||||
|
{
|
||||||
|
const auto p0 = select (r.p < p, r.p, p);
|
||||||
|
const auto p1 = select (r.away () > p, r.away (), p);
|
||||||
|
return { p0, p1 };
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
template <typename T> using region2 = region<2,T>;
|
template <typename T> using region2 = region<2,T>;
|
||||||
template <typename T> using region3 = region<3,T>;
|
template <typename T> using region3 = region<3,T>;
|
||||||
|
|
||||||
|
@ -63,6 +63,28 @@ main (int, char **)
|
|||||||
tap.expect (!r.has (util::point2u {2, 2}), "unsigned region corner has");
|
tap.expect (!r.has (util::point2u {2, 2}), "unsigned region corner has");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ensure make_union 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 (
|
||||||
|
util::make_union (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 }),
|
||||||
|
util::region2f {
|
||||||
|
util::point2f { -3, -2 },
|
||||||
|
util::extent2f { 4, 3 }
|
||||||
|
},
|
||||||
|
"negative expanding union"
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
//CHECK (region<2,intmax_t> (0, 0, 10, 10).includes (point2d (0.4, 0.01)));
|
//CHECK (region<2,intmax_t> (0, 0, 10, 10).includes (point2d (0.4, 0.01)));
|
||||||
//CHECK (region<2,intmax_t> (0, 0, 10, 10).contains (point2d (0.4, 0.01)));
|
//CHECK (region<2,intmax_t> (0, 0, 10, 10).contains (point2d (0.4, 0.01)));
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user