+#ifndef MSP_GEOMETRY_UNION_H_
+#define MSP_GEOMETRY_UNION_H_
+
+#include "compositeshape.h"
+
+namespace Msp {
+namespace Geometry {
+
+/**
+Joins component shapes together into one.
+*/
+template<typename T, unsigned D>
+struct UnionOps
+{
+ static HyperBox<T, D> combine_aabb(const HyperBox<T, D> &, const HyperBox<T, D> &);
+ 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; }
+};
+
+template<typename T, unsigned D>
+class Union: public CompositeShape<T, D, UnionOps<T, D> >
+{
+public:
+ Union(const Shape<T, D> &, const Shape<T, D> &);
+ Union(const std::vector<Shape<T, D> *> &);
+
+ virtual Union *clone() const;
+};
+
+template<typename T, unsigned D>
+inline Union<T, D>::Union(const Shape<T, D> &s1, const Shape<T, D> &s2):
+ CompositeShape<T, D, UnionOps<T, D> >(s1, s2)
+{ }
+
+template<typename T, unsigned D>
+inline Union<T, D>::Union(const std::vector<Shape<T, D> *> &s):
+ CompositeShape<T, D, UnionOps<T, D> >(s)
+{ }
+
+template<typename T, unsigned D>
+inline Union<T, D> *Union<T, D>::clone() const
+{
+ return new Union<T, D>(this->shapes);
+}
+
+
+template<typename T, unsigned D>
+inline HyperBox<T, D> UnionOps<T, D>::combine_aabb(const HyperBox<T, D> &box1, const HyperBox<T, D> &box2)
+{
+ LinAl::Vector<T, D> dimensions;
+ for(unsigned i=0; i<D; ++i)
+ dimensions[i] = std::max(box1.get_dimension(i), box2.get_dimension(i));
+ return HyperBox<T, D>(dimensions);
+}
+
+} // namespace Geometry
+} // namespace Msp
+
+#endif