X-Git-Url: http://git.tdb.fi/?p=libs%2Fmath.git;a=blobdiff_plain;f=source%2Fgeometry%2Funion.h;h=8c02f2b808dc8a18301653c77e8175e83b2ea555;hp=fadeff2ac9270dd71718aade2e733504e6a44e5b;hb=2826730b5d68d1ad74dc6363af43ca796f96caa2;hpb=68389c29cf88d6522dcfa00b5e2a5166e3947210 diff --git a/source/geometry/union.h b/source/geometry/union.h index fadeff2..8c02f2b 100644 --- a/source/geometry/union.h +++ b/source/geometry/union.h @@ -6,26 +6,27 @@ namespace Msp { namespace Geometry { -/** -Joins component shapes together into one. -*/ template struct UnionOps { - static HyperBox combine_aabb(const HyperBox &, const HyperBox &); - static bool init_inside() { return false; } - static bool combine_inside(bool a, bool b) { return a || b; } - static bool is_inside_decided(bool a) { return a; } - static bool init_surface() { return true; } - static bool combine_surface(bool a, bool b) { return a && !b; } + static BoundingBox combine_aabb(const BoundingBox &a, const BoundingBox &b) { return a|b; } + static Coverage combine_coverage(Coverage a, Coverage b) { return std::max(a, b); } + static bool shortcircuit(bool c) { return c; } }; +/** +Joins component shapes together into one. +*/ template class Union: public CompositeShape > { +private: + Union() { } public: Union(const Shape &, const Shape &); - Union(const std::vector *> &); + + template + static Union from_iterator_range(const Iter &, const Iter &); virtual Union *clone() const; }; @@ -36,24 +37,18 @@ inline Union::Union(const Shape &s1, const Shape &s2): { } template -inline Union::Union(const std::vector *> &s): - CompositeShape >(s) -{ } - -template -inline Union *Union::clone() const +template +inline Union Union::from_iterator_range(const Iter &begin, const Iter &end) { - return new Union(this->shapes); + Union shape; + shape.init_from_iter_range(begin, end); + return shape; } - template -inline HyperBox UnionOps::combine_aabb(const HyperBox &box1, const HyperBox &box2) +inline Union *Union::clone() const { - LinAl::Vector dimensions; - for(unsigned i=0; i(dimensions); + return new Union(*this); } } // namespace Geometry