diff --git a/include/Library/Mathematics/Geometry/3D/Intersection.hpp b/include/Library/Mathematics/Geometry/3D/Intersection.hpp index c71daa87..f3d81f21 100755 --- a/include/Library/Mathematics/Geometry/3D/Intersection.hpp +++ b/include/Library/Mathematics/Geometry/3D/Intersection.hpp @@ -12,19 +12,26 @@ //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +#include +#include #include +#include #include #include +#include +#include #include #include -#include #include #include #include #include #include +#include +#include #include +#include //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -40,9 +47,12 @@ namespace d3 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// using library::core::types::Unique ; +using library::core::types::Index ; +using library::core::types::Size ; using library::core::ctnr::Array ; using library::math::geom::d3::Object ; +using library::math::geom::d3::objects::Composite ; //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -61,12 +71,15 @@ class Intersection Point, PointSet, Line, - LineString, Ray, Segment, + LineString, + Polygon, Plane, + Cuboid, Sphere, Ellipsoid, + Pyramid, Complex } ; @@ -75,7 +88,7 @@ class Intersection /// /// @param [in] anObjectArray An array of objects - Intersection ( const Array>& anObjectArray ) ; + Intersection ( Array>&& anObjectArray ) ; /// @brief Copy constructor /// @@ -117,6 +130,15 @@ class Intersection Intersection operator + ( const Intersection& anIntersection ) const ; + /// @brief Addition assignment operator (intersection concatenation) + /// + /// Concatenate (merge) intersection with another intersection. + /// + /// @param [in] anIntersection An intersection + /// @return Reference to concatenated intersection + + Intersection& operator += ( const Intersection& anIntersection ) ; + /// @brief Output stream operator /// /// @code @@ -142,45 +164,25 @@ class Intersection bool isEmpty ( ) const ; - /// @brief Returns true if intersection can be converted to underlying object + /// @brief Check if intersection is complex /// - /// @return True if intersection can be converted to underlying object - - template - bool is ( ) const - { - return (!objects_.isEmpty()) && (dynamic_cast(objects_.accessFirst().get()) != nullptr) ; - } - - /// @brief Get intersection type + /// A complex intersection contains more than one object. /// - /// @return Intersection type + /// @return True if intersection is complex - Intersection::Type getType ( ) const ; + bool isComplex ( ) const ; - /// @brief Access intersection as its underlying object + /// @brief Access composite object /// - /// @return Reference to underlying object - - template - const Type& as ( ) const - { + /// @return Reference to composite object - if (objects_.isEmpty()) - { - throw library::core::error::RuntimeError("Cannot convert intersection: it is empty.") ; - } + const Composite& accessComposite ( ) const ; - const Type* objectPtr = dynamic_cast(objects_.accessFirst().get()) ; - - if (objectPtr == nullptr) - { - throw library::core::error::RuntimeError("Cannot convert intersection: wrong type.") ; - } - - return *objectPtr ; + /// @brief Get intersection type + /// + /// @return Intersection type - } + Intersection::Type getType ( ) const ; /// @brief Constructs an undefined intersection /// @@ -242,7 +244,7 @@ class Intersection Intersection::Type type_ ; - Array> objects_ ; + Composite composite_ ; Intersection ( ) ; diff --git a/include/Library/Mathematics/Geometry/3D/Object.hpp b/include/Library/Mathematics/Geometry/3D/Object.hpp index c3f30cf6..c316f444 100755 --- a/include/Library/Mathematics/Geometry/3D/Object.hpp +++ b/include/Library/Mathematics/Geometry/3D/Object.hpp @@ -15,6 +15,8 @@ #include #include +#include + //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// namespace library @@ -45,7 +47,7 @@ class Object public: - /// @brief Default constructor + /// @brief Default constructor (default) Object ( ) = default ; @@ -88,6 +90,16 @@ class Object virtual bool isDefined ( ) const = 0 ; + /// @brief Returns true if object can be converted to type + /// + /// @return True if object can be converted to type + + template + bool is ( ) const + { + return dynamic_cast(this) != nullptr ; + } + /// @brief Check if object intersects another object /// /// @code @@ -114,6 +126,25 @@ class Object virtual bool contains ( const Object& anObject ) const ; + /// @brief Access object as its underlying type + /// + /// @return Reference to underlying type + + template + const Type& as ( ) const + { + + const Type* objectPtr = dynamic_cast(this) ; + + if (objectPtr == nullptr) + { + throw library::core::error::RuntimeError("Cannot convert object to underlying type.") ; + } + + return *objectPtr ; + + } + /// @brief Compute intersection of object with another object /// /// @code diff --git a/include/Library/Mathematics/Geometry/3D/Objects/Composite.hpp b/include/Library/Mathematics/Geometry/3D/Objects/Composite.hpp new file mode 100755 index 00000000..77e4d53d --- /dev/null +++ b/include/Library/Mathematics/Geometry/3D/Objects/Composite.hpp @@ -0,0 +1,298 @@ +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +/// @project Library/Mathematics +/// @file Library/Mathematics/Geometry/3D/Objects/Composite.hpp +/// @author Lucas Brémond +/// @license TBD + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +#ifndef __Library_Mathematics_Geometry_3D_Objects_Composite__ +#define __Library_Mathematics_Geometry_3D_Objects_Composite__ + +#include + +#include +#include +#include +#include +#include + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +namespace library +{ +namespace math +{ +namespace geom +{ +namespace d3 +{ +namespace objects +{ + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +using library::core::types::Unique ; +using library::core::types::Index ; +using library::core::types::Size ; +using library::core::ctnr::Array ; + +using library::math::geom::d3::Object ; + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +/// @brief Composite object + +class Composite : public Object +{ + + public: + + typedef Array>::ConstIterator ConstIterator ; + + /// @brief Constructor + /// + /// @param [in] anObject An object + + explicit Composite ( const Object& anObject ) ; + + /// @brief Constructor + /// + /// @param [in] anObjectUPtr A unique pointer to object + + explicit Composite ( const Unique& anObjectUPtr ) ; + + /// @brief Constructor + /// + /// @param [in] anObjectArray An array of unique pointers to object + + explicit Composite ( Array>&& anObjectArray ) ; + + /// @brief Copy constructor + /// + /// @param [in] aComposite A composite + + Composite ( const Composite& aComposite ) ; + + /// @brief Clone composite + /// + /// @return Pointer to cloned composite + + virtual Composite* clone ( ) const override ; + + /// @brief Copy assignment operator + /// + /// @param [in] aComposite A composite + /// @return Reference to composite + + Composite& operator = ( const Composite& aComposite ) ; + + /// @brief Equal to operator + /// + /// @param [in] aComposite A composite object + /// @return True if composites are equal + + bool operator == ( const Composite& aComposite ) const ; + + /// @brief Not equal to operator + /// + /// @param [in] aComposite A composite object + /// @return True if composites not are equal + + bool operator != ( const Composite& aComposite ) const ; + + /// @brief Addition operator (composite concatenation) + /// + /// Concatenate (merge) composite with another composite. + /// + /// @param [in] aComposite A composite + /// @return Concatenated composite + + Composite operator + ( const Composite& aComposite ) const ; + + /// @brief Addition assignment operator (composite concatenation) + /// + /// Concatenate (merge) composite with another composite. + /// + /// @param [in] aComposite A composite + /// @return Reference to concatenated composite + + Composite& operator += ( const Composite& aComposite ) ; + + /// @brief Check if composite is defined + /// + /// @code + /// Composite(...).isDefined() ; + /// @endcode + /// + /// @return True if composite is defined + + virtual bool isDefined ( ) const override ; + + /// @brief Returns true if composite can be converted to underlying object + /// + /// Only valid if the composite only contains one object. + /// + /// @return True if composite can be converted to underlying object + + template + bool is ( ) const + { + + if (!this->isDefined()) + { + throw library::core::error::runtime::Undefined("Composite") ; + } + + return (objects_.getSize() == 1) && (dynamic_cast(objects_.accessFirst().get()) != nullptr) ; + + } + + /// @brief Access composite as its underlying object + /// + /// Only valid if the composite only contains one object. + /// + /// @return Reference to underlying object + + template + const Type& as ( ) const + { + + if (!this->isDefined()) + { + throw library::core::error::runtime::Undefined("Composite") ; + } + + if (objects_.getSize() != 1) + { + throw library::core::error::RuntimeError("Cannot convert composite: it is complex.") ; + } + + const Type* objectPtr = dynamic_cast(objects_.accessFirst().get()) ; + + if (objectPtr == nullptr) + { + throw library::core::error::RuntimeError("Cannot convert composite: wrong type.") ; + } + + return *objectPtr ; + + } + + /// @brief Check if composite intersects object + /// + /// @param [in] anObject An object + /// @return True if composite intersects object + + bool intersects ( const Object& anObject ) const ; + + /// @brief Check if composite intersects composite + /// + /// @param [in] aComposite A composite + /// @return True if composite intersects composite + + bool intersects ( const Composite& aComposite ) const ; + + /// @brief Check if composite contains object + /// + /// @param [in] anObject An object + /// @return True if composite contains object + + bool contains ( const Object& anObject ) const ; + + /// @brief Check if composite contains composite + /// + /// @param [in] aComposite A composite + /// @return True if composite contains composite + + bool contains ( const Composite& aComposite ) const ; + + /// @brief Access object at index + /// + /// @param [in] anIndex An object index + /// @return Reference to object + + const Object& accessObjectAt ( const Index& anIndex ) const ; + + /// @brief Access objects in composite + /// + /// @return Reference to objects in composite + + const Array>& accessObjects ( ) const ; + + /// @brief Get number of objects in composite + /// + /// @return Number of objects in composite + + Size getObjectCount ( ) const ; + + /// @brief Compute intersection of composite with object + /// + /// @param [in] anObject An object + /// @return Intersection of composite with object + + Intersection intersectionWith ( const Object& anObject ) const ; + + /// @brief Compute intersection of composite with composite + /// + /// @param [in] aComposite A composite + /// @return Intersection of composite with composite + + Intersection intersectionWith ( const Composite& aComposite ) const ; + + /// @brief Get const iterator to begin + /// + /// @return Const iterator to begin + + Composite::ConstIterator begin ( ) const ; + + /// @brief Get const iterator to end + /// + /// @return Const iterator to end + + Composite::ConstIterator end ( ) const ; + + /// @brief Print composite + /// + /// @param [in] anOutputStream An output stream + /// @param [in] (optional) displayDecorators If true, display decorators + + virtual void print ( std::ostream& anOutputStream, + bool displayDecorators = true ) const override ; + + /// @brief Apply transformation to composite + /// + /// @param [in] aTransformation A transformation + + virtual void applyTransformation ( const Transformation& aTransformation ) override ; + + /// @brief Constructs an undefined composite + /// + /// @code + /// Composite composite = Composite::Undefined() ; // Undefined + /// @endcode + /// + /// @return Undefined composite + + static Composite Undefined ( ) ; + + private: + + Array> objects_ ; + +} ; + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +} +} +} +} +} + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +#endif + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// \ No newline at end of file diff --git a/share/python/src/LibraryMathematicsPy/Geometry/3D/Intersection.cpp b/share/python/src/LibraryMathematicsPy/Geometry/3D/Intersection.cpp index 55c96157..f3d69eb5 100755 --- a/share/python/src/LibraryMathematicsPy/Geometry/3D/Intersection.cpp +++ b/share/python/src/LibraryMathematicsPy/Geometry/3D/Intersection.cpp @@ -25,6 +25,8 @@ inline void LibraryMathematicsPy_Geometry_3D_Intersection ( using library::math::geom::d3::objects::Line ; using library::math::geom::d3::objects::Ray ; using library::math::geom::d3::objects::Segment ; + using library::math::geom::d3::objects::LineString ; + using library::math::geom::d3::objects::Polygon ; using library::math::geom::d3::objects::Plane ; using library::math::geom::d3::objects::Sphere ; using library::math::geom::d3::objects::Ellipsoid ; @@ -42,26 +44,11 @@ inline void LibraryMathematicsPy_Geometry_3D_Intersection ( .def("isDefined", &Intersection::isDefined) .def("isEmpty", &Intersection::isEmpty) + .def("isComplex", &Intersection::isComplex) - .def("isPoint", +[] (const Intersection& anIntersection) -> bool { return anIntersection.is() ; }) - .def("isPointSet", +[] (const Intersection& anIntersection) -> bool { return anIntersection.is() ; }) - .def("isLine", +[] (const Intersection& anIntersection) -> bool { return anIntersection.is() ; }) - .def("isRay", +[] (const Intersection& anIntersection) -> bool { return anIntersection.is() ; }) - .def("isSegment", +[] (const Intersection& anIntersection) -> bool { return anIntersection.is() ; }) - .def("isPlane", +[] (const Intersection& anIntersection) -> bool { return anIntersection.is() ; }) - .def("isSphere", +[] (const Intersection& anIntersection) -> bool { return anIntersection.is() ; }) - .def("isEllipsoid", +[] (const Intersection& anIntersection) -> bool { return anIntersection.is() ; }) + .def("accessComposite", &Intersection::accessComposite, return_value_policy()) .def("getType", &Intersection::getType) - - .def("asPoint", +[] (const Intersection& anIntersection) -> Point { return anIntersection.as() ; }) - .def("asPointSet", +[] (const Intersection& anIntersection) -> PointSet { return anIntersection.as() ; }) - .def("asLine", +[] (const Intersection& anIntersection) -> Line { return anIntersection.as() ; }) - .def("asRay", +[] (const Intersection& anIntersection) -> Ray { return anIntersection.as() ; }) - .def("asSegment", +[] (const Intersection& anIntersection) -> Segment { return anIntersection.as() ; }) - .def("asPlane", +[] (const Intersection& anIntersection) -> Plane { return anIntersection.as() ; }) - .def("asSphere", +[] (const Intersection& anIntersection) -> Sphere { return anIntersection.as() ; }) - .def("asEllipsoid", +[] (const Intersection& anIntersection) -> Ellipsoid { return anIntersection.as() ; }) .def("Undefined", &Intersection::Undefined).staticmethod("Undefined") .def("Empty", &Intersection::Empty).staticmethod("Empty") diff --git a/share/python/src/LibraryMathematicsPy/Geometry/3D/Object.cpp b/share/python/src/LibraryMathematicsPy/Geometry/3D/Object.cpp index 445d645d..d08c2453 100755 --- a/share/python/src/LibraryMathematicsPy/Geometry/3D/Object.cpp +++ b/share/python/src/LibraryMathematicsPy/Geometry/3D/Object.cpp @@ -17,6 +17,17 @@ inline void LibraryMathematicsPy_Geometry_3D_Object ( ) using namespace boost::python ; using library::math::geom::d3::Object ; + using library::math::geom::d3::objects::Point ; + using library::math::geom::d3::objects::PointSet ; + using library::math::geom::d3::objects::Line ; + using library::math::geom::d3::objects::Ray ; + using library::math::geom::d3::objects::Segment ; + using library::math::geom::d3::objects::LineString ; + using library::math::geom::d3::objects::Polygon ; + using library::math::geom::d3::objects::Plane ; + using library::math::geom::d3::objects::Sphere ; + using library::math::geom::d3::objects::Ellipsoid ; + using library::math::geom::d3::objects::Pyramid ; scope in_Object = class_("Object", no_init) @@ -27,9 +38,32 @@ inline void LibraryMathematicsPy_Geometry_3D_Object ( ) .def(self_ns::repr(self_ns::self)) .def("isDefined", &Object::isDefined) + .def("isPoint", +[] (const Object& anObject) -> bool { return anObject.is() ; }) + .def("isPointSet", +[] (const Object& anObject) -> bool { return anObject.is() ; }) + .def("isLine", +[] (const Object& anObject) -> bool { return anObject.is() ; }) + .def("isRay", +[] (const Object& anObject) -> bool { return anObject.is() ; }) + .def("isSegment", +[] (const Object& anObject) -> bool { return anObject.is() ; }) + .def("isLineString", +[] (const Object& anObject) -> bool { return anObject.is() ; }) + .def("isPolygon", +[] (const Object& anObject) -> bool { return anObject.is() ; }) + .def("isPlane", +[] (const Object& anObject) -> bool { return anObject.is() ; }) + .def("isSphere", +[] (const Object& anObject) -> bool { return anObject.is() ; }) + .def("isEllipsoid", +[] (const Object& anObject) -> bool { return anObject.is() ; }) + .def("isPyramid", +[] (const Object& anObject) -> bool { return anObject.is() ; }) .def("intersects", &Object::intersects) .def("contains", &Object::contains) + .def("asPoint", +[] (const Object& anObject) -> Point { return anObject.as() ; }) + .def("asPointSet", +[] (const Object& anObject) -> PointSet { return anObject.as() ; }) + .def("asLine", +[] (const Object& anObject) -> Line { return anObject.as() ; }) + .def("asRay", +[] (const Object& anObject) -> Ray { return anObject.as() ; }) + .def("asSegment", +[] (const Object& anObject) -> Segment { return anObject.as() ; }) + .def("asLineString", +[] (const Object& anObject) -> LineString { return anObject.as() ; }) + .def("asPolygon", +[] (const Object& anObject) -> Polygon { return anObject.as() ; }) + .def("asPlane", +[] (const Object& anObject) -> Plane { return anObject.as() ; }) + .def("asSphere", +[] (const Object& anObject) -> Sphere { return anObject.as() ; }) + .def("asEllipsoid", +[] (const Object& anObject) -> Ellipsoid { return anObject.as() ; }) + .def("asPyramid", +[] (const Object& anObject) -> Pyramid { return anObject.as() ; }) + // .def("intersectionWith", &Object::intersectionWith) .def("applyTransformation", &Object::applyTransformation) diff --git a/share/python/src/LibraryMathematicsPy/Geometry/3D/Objects/Composite.cpp b/share/python/src/LibraryMathematicsPy/Geometry/3D/Objects/Composite.cpp new file mode 100755 index 00000000..7b47d069 --- /dev/null +++ b/share/python/src/LibraryMathematicsPy/Geometry/3D/Objects/Composite.cpp @@ -0,0 +1,89 @@ +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +/// @project Library/Mathematics +/// @file LibraryMathematicsPy/Geometry/3D/Objects/Composite.cpp +/// @author Lucas Brémond +/// @license TBD + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +#include +#include + +#include + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +inline void LibraryMathematicsPy_Geometry_3D_Objects_Composite ( ) +{ + + using namespace boost::python ; + + using library::core::types::Shared ; + using library::core::types::Real ; + + using library::math::obj::Vector3d ; + using library::math::geom::d3::Object ; + using library::math::geom::d3::objects::Point ; + using library::math::geom::d3::objects::PointSet ; + using library::math::geom::d3::objects::Line ; + using library::math::geom::d3::objects::Ray ; + using library::math::geom::d3::objects::Segment ; + using library::math::geom::d3::objects::Plane ; + using library::math::geom::d3::objects::Sphere ; + using library::math::geom::d3::objects::Cuboid ; + using library::math::geom::d3::objects::Pyramid ; + using library::math::geom::d3::objects::Composite ; + using library::math::geom::d3::Intersection ; + using library::math::geom::d3::trf::rot::Quaternion ; + + scope in_Composite = class_, bases>("Composite", no_init) + + .def(self == self) + .def(self != self) + + .def(self_ns::str(self_ns::self)) + .def(self_ns::repr(self_ns::self)) + + .def("isDefined", &Composite::isDefined) + + .def("isPoint", +[] (const Composite& aComposite) -> bool { return aComposite.is() ; }) + .def("isPointSet", +[] (const Composite& aComposite) -> bool { return aComposite.is() ; }) + .def("isLine", +[] (const Composite& aComposite) -> bool { return aComposite.is() ; }) + .def("isRay", +[] (const Composite& aComposite) -> bool { return aComposite.is() ; }) + .def("isLineString", +[] (const Composite& aComposite) -> bool { return aComposite.is() ; }) + .def("isSegment", +[] (const Composite& aComposite) -> bool { return aComposite.is() ; }) + .def("isPolygon", +[] (const Composite& aComposite) -> bool { return aComposite.is() ; }) + .def("isPlane", +[] (const Composite& aComposite) -> bool { return aComposite.is() ; }) + .def("isSphere", +[] (const Composite& aComposite) -> bool { return aComposite.is() ; }) + .def("isEllipsoid", +[] (const Composite& aComposite) -> bool { return aComposite.is() ; }) + .def("isPyramid", +[] (const Composite& aComposite) -> bool { return aComposite.is() ; }) + + .def("intersects", &Composite::intersects) + .def("contains", &Composite::contains) + + .def("asPoint", +[] (const Composite& aComposite) -> Point { return aComposite.as() ; }) + .def("asPointSet", +[] (const Composite& aComposite) -> PointSet { return aComposite.as() ; }) + .def("asLine", +[] (const Composite& aComposite) -> Line { return aComposite.as() ; }) + .def("asRay", +[] (const Composite& aComposite) -> Ray { return aComposite.as() ; }) + .def("asSegment", +[] (const Composite& aComposite) -> Segment { return aComposite.as() ; }) + .def("asLineString", +[] (const Composite& aComposite) -> LineString { return aComposite.as() ; }) + .def("asPolygon", +[] (const Composite& aComposite) -> Polygon { return aComposite.as() ; }) + .def("asPlane", +[] (const Composite& aComposite) -> Plane { return aComposite.as() ; }) + .def("asSphere", +[] (const Composite& aComposite) -> Sphere { return aComposite.as() ; }) + .def("asEllipsoid", +[] (const Composite& aComposite) -> Ellipsoid { return aComposite.as() ; }) + .def("asPyramid", +[] (const Composite& aComposite) -> Pyramid { return aComposite.as() ; }) + + .def("accessObjectAt", &Composite::accessObjectAt, return_value_policy()) + .def("accessObjects", &Composite::accessObjects, return_value_policy()) + .def("getObjectCount", &Composite::getObjectCount) + + .def("applyTransformation", &Composite::applyTransformation) + + .def("Undefined", &Composite::Undefined).staticmethod("Undefined") + + ; + +} + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// \ No newline at end of file diff --git a/src/Library/Mathematics/Geometry/2D/Objects/LineString.cpp b/src/Library/Mathematics/Geometry/2D/Objects/LineString.cpp index 2ebd9aae..1cea123b 100644 --- a/src/Library/Mathematics/Geometry/2D/Objects/LineString.cpp +++ b/src/Library/Mathematics/Geometry/2D/Objects/LineString.cpp @@ -75,7 +75,7 @@ bool LineString::isNear ( return false ; } - for (auto pointTuple : library::core::ctnr::iterators::Zip(points_, aLineString.points_)) + for (const auto pointTuple : library::core::ctnr::iterators::Zip(points_, aLineString.points_)) { if (!std::get<0>(pointTuple).isNear(std::get<1>(pointTuple), aTolerance)) diff --git a/src/Library/Mathematics/Geometry/3D/Intersection.cpp b/src/Library/Mathematics/Geometry/3D/Intersection.cpp index 8af09603..fe8a6edc 100644 --- a/src/Library/Mathematics/Geometry/3D/Intersection.cpp +++ b/src/Library/Mathematics/Geometry/3D/Intersection.cpp @@ -25,24 +25,18 @@ namespace d3 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - Intersection::Intersection ( const Array>& anObjectArray ) + Intersection::Intersection ( Array>&& anObjectArray ) : type_(Intersection::TypeFromObjects(anObjectArray)), - objects_(Array>::Empty()) + composite_(std::move(anObjectArray)) { - objects_.reserve(anObjectArray.getSize()) ; - std::transform(anObjectArray.begin(), anObjectArray.end(), std::back_inserter(objects_), [] (const Unique& anObjectUPtr) -> Unique { return Unique(anObjectUPtr->clone()) ; }) ; - } Intersection::Intersection ( const Intersection& anIntersection ) : type_(anIntersection.type_), - objects_(Array>::Empty()) + composite_(anIntersection.composite_) { - objects_.reserve(anIntersection.objects_.getSize()) ; - std::transform(anIntersection.objects_.begin(), anIntersection.objects_.end(), std::back_inserter(objects_), [] (const Unique& anObjectUPtr) -> Unique { return Unique(anObjectUPtr->clone()) ; }) ; - } Intersection::~Intersection ( ) @@ -57,10 +51,7 @@ Intersection& Intersection::operator = ( { type_ = anIntersection.type_ ; - - objects_.clear() ; - objects_.reserve(anIntersection.objects_.getSize()) ; - std::transform(anIntersection.objects_.begin(), anIntersection.objects_.end(), std::back_inserter(objects_), [] (const Unique& anObjectUPtr) -> Unique { return Unique(anObjectUPtr->clone()) ; }) ; + composite_ = anIntersection.composite_ ; } @@ -76,16 +67,7 @@ bool Intersection::operator == ( return false ; } - if (type_ != anIntersection.type_) - { - return false ; - } - - // [TBI] - - throw library::core::error::runtime::ToBeImplemented("Intersection :: operator ==") ; - - return false ; + return (type_ == anIntersection.type_) && (composite_ == anIntersection.composite_) ; } @@ -97,24 +79,37 @@ bool Intersection::operator != ( Intersection Intersection::operator + ( const Intersection& anIntersection ) const { - if ((!this->isDefined()) || (!anIntersection.isDefined())) + if (!anIntersection.isDefined()) { throw library::core::error::runtime::Undefined("Intersection") ; } Intersection intersection ; - intersection.type_ = Intersection::Type::Complex ; + intersection.composite_ = composite_ + anIntersection.composite_ ; - intersection.objects_.reserve(objects_.getSize() + anIntersection.objects_.getSize()) ; + intersection.type_ = Intersection::TypeFromObjects(intersection.composite_.accessObjects()) ; - std::transform(objects_.begin(), objects_.end(), std::back_inserter(intersection.objects_), [] (const Unique& anObjectUPtr) -> Unique { return Unique(anObjectUPtr->clone()) ; }) ; - std::transform(anIntersection.objects_.begin(), anIntersection.objects_.end(), std::back_inserter(intersection.objects_), [] (const Unique& anObjectUPtr) -> Unique { return Unique(anObjectUPtr->clone()) ; }) ; - return intersection ; } +Intersection& Intersection::operator += ( const Intersection& anIntersection ) +{ + + if (!anIntersection.isDefined()) + { + throw library::core::error::runtime::Undefined("Intersection") ; + } + + composite_ += anIntersection.composite_ ; + + type_ = Intersection::TypeFromObjects(composite_.accessObjects()) ; + + return *this ; + +} + std::ostream& operator << ( std::ostream& anOutputStream, const Intersection& anIntersection ) { @@ -122,18 +117,10 @@ std::ostream& operator << ( library::core::utils::Print::Header(anOutputStream, "Intersection") ; library::core::utils::Print::Line(anOutputStream) << "Type:" << Intersection::StringFromType(anIntersection.type_) ; + + library::core::utils::Print::Line(anOutputStream) << "Composite:" ; - if (!anIntersection.objects_.isEmpty()) - { - - library::core::utils::Print::Separator(anOutputStream, "Objects") ; - - for (const auto& objectUPtr : anIntersection.objects_) - { - anOutputStream << (*objectUPtr) ; - } - - } + anIntersection.composite_.print(anOutputStream, false) ; library::core::utils::Print::Footer(anOutputStream) ; @@ -143,7 +130,7 @@ std::ostream& operator << ( bool Intersection::isDefined ( ) const { - return type_ != Intersection::Type::Undefined ; + return (type_ != Intersection::Type::Undefined) && composite_.isDefined() ; } bool Intersection::isEmpty ( ) const @@ -151,6 +138,23 @@ bool Intersection::isEmpty ( ) return type_ == Intersection::Type::Empty ; } +bool Intersection::isComplex ( ) const +{ + return type_ == Intersection::Type::Complex ; +} + +const Composite& Intersection::accessComposite ( ) const +{ + + if (!this->isDefined()) + { + throw library::core::error::runtime::Undefined("Intersection") ; + } + + return composite_ ; + +} + Intersection::Type Intersection::getType ( ) const { @@ -176,7 +180,7 @@ Intersection Intersection::Undefined ( ) Intersection Intersection::Empty ( ) { - return Intersection(Array>::Empty()) ; + return { Array>::Empty() } ; } Intersection Intersection::Point ( const objects::Point& aPoint ) @@ -186,7 +190,7 @@ Intersection Intersection::Point ( intersection.type_ = Intersection::Type::Point ; - intersection.objects_.emplace_back(Unique(aPoint.clone())) ; + intersection.composite_ = Composite { aPoint } ; return intersection ; @@ -199,7 +203,7 @@ Intersection Intersection::PointSet ( intersection.type_ = Intersection::Type::PointSet ; - intersection.objects_.emplace_back(Unique(aPointSet.clone())) ; + intersection.composite_ = Composite { aPointSet } ; return intersection ; @@ -212,7 +216,7 @@ Intersection Intersection::LineString ( intersection.type_ = Intersection::Type::LineString ; - intersection.objects_.emplace_back(Unique(aLineString.clone())) ; + intersection.composite_ = Composite { aLineString } ; return intersection ; @@ -239,15 +243,18 @@ String Intersection::StringFromType ( case Intersection::Type::Line: return "Line" ; - case Intersection::Type::LineString: - return "LineString" ; - case Intersection::Type::Ray: return "Ray" ; case Intersection::Type::Segment: return "Segment" ; + case Intersection::Type::LineString: + return "LineString" ; + + case Intersection::Type::Polygon: + return "Polygon" ; + case Intersection::Type::Plane: return "Plane" ; @@ -257,6 +264,9 @@ String Intersection::StringFromType ( case Intersection::Type::Ellipsoid: return "Ellipsoid" ; + case Intersection::Type::Pyramid: + return "Pyramid" ; + case Intersection::Type::Complex: return "Complex" ; @@ -272,7 +282,7 @@ String Intersection::StringFromType ( Intersection::Intersection ( ) : type_(Intersection::Type::Undefined), - objects_(Array>::Empty()) + composite_(Composite::Undefined()) { } @@ -315,18 +325,46 @@ Intersection::Type Intersection::TypeFromObject ( return Intersection::Type::Point ; } - // if (dynamic_cast(anObjectUPtr.get())) - // { - // return Intersection::Type::PointSet ; - // } + if (dynamic_cast(anObjectUPtr.get())) + { + return Intersection::Type::PointSet ; + } - // [TBI] + if (dynamic_cast(anObjectUPtr.get())) + { + return Intersection::Type::Line ; + } + + if (dynamic_cast(anObjectUPtr.get())) + { + return Intersection::Type::Ray ; + } if (dynamic_cast(anObjectUPtr.get())) { return Intersection::Type::Segment ; } + if (dynamic_cast(anObjectUPtr.get())) + { + return Intersection::Type::LineString ; + } + + if (dynamic_cast(anObjectUPtr.get())) + { + return Intersection::Type::Polygon ; + } + + if (dynamic_cast(anObjectUPtr.get())) + { + return Intersection::Type::Plane ; + } + + if (dynamic_cast(anObjectUPtr.get())) + { + return Intersection::Type::Cuboid ; + } + if (dynamic_cast(anObjectUPtr.get())) { return Intersection::Type::Sphere ; @@ -337,6 +375,11 @@ Intersection::Type Intersection::TypeFromObject ( return Intersection::Type::Ellipsoid ; } + if (dynamic_cast(anObjectUPtr.get())) + { + return Intersection::Type::Pyramid ; + } + return Intersection::Type::Undefined ; } diff --git a/src/Library/Mathematics/Geometry/3D/Object.cpp b/src/Library/Mathematics/Geometry/3D/Object.cpp index e829e907..1ea0983e 100644 --- a/src/Library/Mathematics/Geometry/3D/Object.cpp +++ b/src/Library/Mathematics/Geometry/3D/Object.cpp @@ -8,14 +8,18 @@ //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// #include +#include #include #include #include -#include +#include #include +#include +#include #include #include #include +#include #include #include @@ -44,14 +48,18 @@ bool Object::operator == ( { using library::math::geom::d3::objects::Point ; + using library::math::geom::d3::objects::PointSet ; using library::math::geom::d3::objects::Line ; using library::math::geom::d3::objects::Ray ; using library::math::geom::d3::objects::Segment ; - using library::math::geom::d3::objects::Plane ; + using library::math::geom::d3::objects::LineString ; using library::math::geom::d3::objects::Polygon ; + using library::math::geom::d3::objects::Plane ; + using library::math::geom::d3::objects::Cuboid ; using library::math::geom::d3::objects::Sphere ; using library::math::geom::d3::objects::Ellipsoid ; using library::math::geom::d3::objects::Pyramid ; + using library::math::geom::d3::objects::Composite ; if ((!this->isDefined()) || (!anObject.isDefined())) { @@ -75,6 +83,18 @@ bool Object::operator == ( } + // PointSet + + if (const PointSet* objectPtr = dynamic_cast(this)) + { + + if (const PointSet* otherObjectPtr = dynamic_cast(&anObject)) + { + return (*objectPtr) == (*otherObjectPtr) ; + } + + } + // Line if (const Line* objectPtr = dynamic_cast(this)) @@ -111,12 +131,12 @@ bool Object::operator == ( } - // Plane + // LineString - if (const Plane* objectPtr = dynamic_cast(this)) + if (const LineString* objectPtr = dynamic_cast(this)) { - if (const Plane* otherObjectPtr = dynamic_cast(&anObject)) + if (const LineString* otherObjectPtr = dynamic_cast(&anObject)) { return (*objectPtr) == (*otherObjectPtr) ; } @@ -135,6 +155,30 @@ bool Object::operator == ( } + // Plane + + if (const Plane* objectPtr = dynamic_cast(this)) + { + + if (const Plane* otherObjectPtr = dynamic_cast(&anObject)) + { + return (*objectPtr) == (*otherObjectPtr) ; + } + + } + + // Cuboid + + if (const Cuboid* objectPtr = dynamic_cast(this)) + { + + if (const Cuboid* otherObjectPtr = dynamic_cast(&anObject)) + { + return (*objectPtr) == (*otherObjectPtr) ; + } + + } + // Sphere if (const Sphere* objectPtr = dynamic_cast(this)) @@ -171,6 +215,21 @@ bool Object::operator == ( } + // Composite + + if (const Composite* objectPtr = dynamic_cast(this)) + { + + if (const Composite* otherObjectPtr = dynamic_cast(&anObject)) + { + return (*objectPtr) == (*otherObjectPtr) ; + } + + } + + std::cout << (*this) << std::endl ; + std::cout << anObject << std::endl ; + throw library::core::error::runtime::ToBeImplemented("Object :: operator ==") ; return false ; @@ -196,14 +255,18 @@ bool Object::intersects ( { using library::math::geom::d3::objects::Point ; + using library::math::geom::d3::objects::PointSet ; using library::math::geom::d3::objects::Line ; using library::math::geom::d3::objects::Ray ; using library::math::geom::d3::objects::Segment ; - using library::math::geom::d3::objects::Plane ; + using library::math::geom::d3::objects::LineString ; using library::math::geom::d3::objects::Polygon ; + using library::math::geom::d3::objects::Plane ; + using library::math::geom::d3::objects::Cuboid ; using library::math::geom::d3::objects::Sphere ; using library::math::geom::d3::objects::Ellipsoid ; using library::math::geom::d3::objects::Pyramid ; + using library::math::geom::d3::objects::Composite ; if (!anObject.isDefined()) { @@ -303,6 +366,9 @@ bool Object::intersects ( } + std::cout << (*this) << std::endl ; + std::cout << anObject << std::endl ; + throw library::core::error::runtime::ToBeImplemented("Object :: intersects") ; return false ; @@ -313,14 +379,18 @@ bool Object::contains ( { using library::math::geom::d3::objects::Point ; + using library::math::geom::d3::objects::PointSet ; using library::math::geom::d3::objects::Line ; using library::math::geom::d3::objects::Ray ; using library::math::geom::d3::objects::Segment ; - using library::math::geom::d3::objects::Plane ; + using library::math::geom::d3::objects::LineString ; using library::math::geom::d3::objects::Polygon ; + using library::math::geom::d3::objects::Plane ; + using library::math::geom::d3::objects::Cuboid ; using library::math::geom::d3::objects::Sphere ; using library::math::geom::d3::objects::Ellipsoid ; using library::math::geom::d3::objects::Pyramid ; + using library::math::geom::d3::objects::Composite ; if (!anObject.isDefined()) { @@ -379,14 +449,18 @@ Intersection Object::intersectionWith ( { using library::math::geom::d3::objects::Point ; + using library::math::geom::d3::objects::PointSet ; using library::math::geom::d3::objects::Line ; using library::math::geom::d3::objects::Ray ; using library::math::geom::d3::objects::Segment ; - using library::math::geom::d3::objects::Plane ; + using library::math::geom::d3::objects::LineString ; using library::math::geom::d3::objects::Polygon ; + using library::math::geom::d3::objects::Plane ; + using library::math::geom::d3::objects::Cuboid ; using library::math::geom::d3::objects::Sphere ; using library::math::geom::d3::objects::Ellipsoid ; using library::math::geom::d3::objects::Pyramid ; + using library::math::geom::d3::objects::Composite ; if (!anObject.isDefined()) { @@ -435,6 +509,9 @@ Intersection Object::intersectionWith ( } + std::cout << (*this) << std::endl ; + std::cout << anObject << std::endl ; + throw library::core::error::runtime::ToBeImplemented("Object :: intersectionWith") ; return Intersection::Undefined() ; diff --git a/src/Library/Mathematics/Geometry/3D/Objects/Composite.cpp b/src/Library/Mathematics/Geometry/3D/Objects/Composite.cpp new file mode 100644 index 00000000..b8235a90 --- /dev/null +++ b/src/Library/Mathematics/Geometry/3D/Objects/Composite.cpp @@ -0,0 +1,428 @@ +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +/// @project Library/Mathematics +/// @file Library/Mathematics/Geometry/3D/Objects/Composite.cpp +/// @author Lucas Brémond +/// @license TBD + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +#include +#include +#include + +#include +#include + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +namespace library +{ +namespace math +{ +namespace geom +{ +namespace d3 +{ +namespace objects +{ + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + Composite::Composite ( const Object& anObject ) + : Object(), + objects_(Array>::Empty()) +{ + + objects_.emplace_back(Unique(anObject.clone())) ; + +} + + Composite::Composite ( const Unique& anObjectUPtr ) + : Object(), + objects_(Array>::Empty()) +{ + + objects_.emplace_back(Unique(anObjectUPtr->clone())) ; + +} + + Composite::Composite ( Array>&& anObjectArray ) + : Object(), + objects_(Array>::Empty()) +{ + + objects_.reserve(anObjectArray.getSize()) ; + + std::transform(anObjectArray.begin(), anObjectArray.end(), std::back_inserter(objects_), [] (const Unique& anObjectUPtr) -> Unique { return Unique(anObjectUPtr->clone()) ; }) ; + +} + + Composite::Composite ( const Composite& aComposite ) + : Object(), + objects_(Array>::Empty()) +{ + + objects_.reserve(aComposite.objects_.getSize()) ; + + std::transform(aComposite.objects_.begin(), aComposite.objects_.end(), std::back_inserter(objects_), [] (const Unique& anObjectUPtr) -> Unique { return Unique(anObjectUPtr->clone()) ; }) ; + +} + +Composite* Composite::clone ( ) const +{ + return new Composite(*this) ; +} + +Composite& Composite::operator = ( const Composite& aComposite ) +{ + + if (this != &aComposite) + { + + objects_.clear() ; + + objects_.reserve(aComposite.objects_.getSize()) ; + + std::transform(aComposite.objects_.begin(), aComposite.objects_.end(), std::back_inserter(objects_), [] (const Unique& anObjectUPtr) -> Unique { return Unique(anObjectUPtr->clone()) ; }) ; + + } + + return *this ; + +} + +bool Composite::operator == ( const Composite& aComposite ) const +{ + + if ((!this->isDefined()) || (!aComposite.isDefined())) + { + return false ; + } + + if (objects_.getSize() != aComposite.objects_.getSize()) + { + return false ; + } + + for (const auto objectTuple : library::core::ctnr::iterators::Zip(objects_, aComposite.objects_)) + { + + if ((*std::get<0>(objectTuple)) != (*std::get<1>(objectTuple))) + { + return false ; + } + + } + + return true ; + +} + +bool Composite::operator != ( const Composite& aComposite ) const +{ + return !((*this) == aComposite) ; +} + +Composite Composite::operator + ( const Composite& aComposite ) const +{ + + if (!aComposite.isDefined()) + { + throw library::core::error::runtime::Undefined("Composite") ; + } + + Composite composite = Composite::Undefined() ; + + composite.objects_.reserve(objects_.getSize() + aComposite.objects_.getSize()) ; + + std::transform(objects_.begin(), objects_.end(), std::back_inserter(composite.objects_), [] (const Unique& anObjectUPtr) -> Unique { return Unique(anObjectUPtr->clone()) ; }) ; + std::transform(aComposite.objects_.begin(), aComposite.objects_.end(), std::back_inserter(composite.objects_), [] (const Unique& anObjectUPtr) -> Unique { return Unique(anObjectUPtr->clone()) ; }) ; + + return composite ; + +} + +Composite& Composite::operator += ( const Composite& aComposite ) +{ + + if (!aComposite.isDefined()) + { + throw library::core::error::runtime::Undefined("Composite") ; + } + + objects_.reserve(objects_.getSize() + aComposite.objects_.getSize()) ; + + std::transform(aComposite.objects_.begin(), aComposite.objects_.end(), std::back_inserter(objects_), [] (const Unique& anObjectUPtr) -> Unique { return Unique(anObjectUPtr->clone()) ; }) ; + + return *this ; + +} + +bool Composite::isDefined ( ) const +{ + return (!objects_.isEmpty()) && std::all_of(objects_.begin(), objects_.end(), [] (const Unique& anObjectUPtr) -> bool { return anObjectUPtr->isDefined() ; }) ; ; +} + +bool Composite::intersects ( const Object& anObject ) const +{ + + if (!anObject.isDefined()) + { + throw library::core::error::runtime::Undefined("Object") ; + } + + if (!this->isDefined()) + { + throw library::core::error::runtime::Undefined("Composite") ; + } + + return std::any_of(objects_.begin(), objects_.end(), [&anObject] (const Unique& anObjectUPtr) -> bool { return anObjectUPtr->intersects(anObject) ; }) ; + +} + +bool Composite::intersects ( const Composite& aComposite ) const +{ + + if (!aComposite.isDefined()) + { + throw library::core::error::runtime::Undefined("Composite") ; + } + + if (!this->isDefined()) + { + throw library::core::error::runtime::Undefined("Composite") ; + } + + return std::any_of(aComposite.objects_.begin(), aComposite.objects_.end(), [this] (const Unique& anObjectUPtr) -> bool { return this->intersects(*anObjectUPtr) ; }) ; + +} + +bool Composite::contains ( const Object& anObject ) const +{ + + if (!anObject.isDefined()) + { + throw library::core::error::runtime::Undefined("Object") ; + } + + if (!this->isDefined()) + { + throw library::core::error::runtime::Undefined("Composite") ; + } + + return std::all_of(objects_.begin(), objects_.end(), [&anObject] (const Unique& anObjectUPtr) -> bool { return anObjectUPtr->contains(anObject) ; }) ; + +} + +bool Composite::contains ( const Composite& aComposite ) const +{ + + if (!aComposite.isDefined()) + { + throw library::core::error::runtime::Undefined("Composite") ; + } + + if (!this->isDefined()) + { + throw library::core::error::runtime::Undefined("Composite") ; + } + + return std::all_of(aComposite.objects_.begin(), aComposite.objects_.end(), [this] (const Unique& anObjectUPtr) -> bool { return this->contains(*anObjectUPtr) ; }) ; + +} + +const Object& Composite::accessObjectAt ( const Index& anIndex ) const +{ + + if (!this->isDefined()) + { + throw library::core::error::runtime::Undefined("Composite") ; + } + + if (anIndex >= objects_.getSize()) + { + throw library::core::error::RuntimeError("Object index [{}] out of bounds [{}].", anIndex, objects_.getSize()) ; + } + + return *(objects_.at(anIndex).get()) ; + +} + +const Array>& Composite::accessObjects ( ) const +{ + + if (!this->isDefined()) + { + throw library::core::error::runtime::Undefined("Composite") ; + } + + return objects_ ; + +} + +Size Composite::getObjectCount ( ) const +{ + + if (!this->isDefined()) + { + throw library::core::error::runtime::Undefined("Composite") ; + } + + return objects_.getSize() ; + +} + +Intersection Composite::intersectionWith ( const Object& anObject ) const +{ + + if (!anObject.isDefined()) + { + throw library::core::error::runtime::Undefined("Object") ; + } + + if (!this->isDefined()) + { + throw library::core::error::runtime::Undefined("Composite") ; + } + + Intersection intersection = Intersection::Empty() ; + + for (const auto& objectUPtr : objects_) + { + + const Intersection objectToObjectIntersection = objectUPtr->intersectionWith(anObject) ; + + if (objectToObjectIntersection.isDefined() && (!objectToObjectIntersection.isEmpty())) + { + intersection += objectToObjectIntersection ; + } + + } + + return intersection ; + +} + +Intersection Composite::intersectionWith ( const Composite& aComposite ) const +{ + + if (!aComposite.isDefined()) + { + throw library::core::error::runtime::Undefined("Composite") ; + } + + if (!this->isDefined()) + { + throw library::core::error::runtime::Undefined("Composite") ; + } + + Intersection intersection = Intersection::Empty() ; + + for (const auto& objectUPtr : aComposite.objects_) + { + + const Intersection compositeToObjectIntersection = this->intersectionWith(*objectUPtr) ; + + if (compositeToObjectIntersection.isDefined() && (!compositeToObjectIntersection.isEmpty())) + { + intersection += compositeToObjectIntersection ; + } + + } + + return intersection ; + +} + +Composite::ConstIterator Composite::begin ( ) const +{ + + if (!this->isDefined()) + { + throw library::core::error::runtime::Undefined("Composite") ; + } + + return objects_.begin() ; + +} + +Composite::ConstIterator Composite::end ( ) const +{ + + if (!this->isDefined()) + { + throw library::core::error::runtime::Undefined("Composite") ; + } + + return objects_.end() ; + +} + +void Composite::print ( std::ostream& anOutputStream, + bool displayDecorators ) const +{ + + displayDecorators ? library::core::utils::Print::Header(anOutputStream, "Composite") : void () ; + + if (!objects_.isEmpty()) + { + + library::core::utils::Print::Separator(anOutputStream, "Objects") ; + + for (const auto& objectUPtr : objects_) + { + anOutputStream << (*objectUPtr) ; + } + + } + else + { + library::core::utils::Print::Line(anOutputStream) << "Empty" ; + } + + displayDecorators ? library::core::utils::Print::Footer(anOutputStream) : void () ; + +} + +void Composite::applyTransformation ( const Transformation& aTransformation ) +{ + + using library::math::geom::d3::trf::rot::RotationMatrix ; + + if (!aTransformation.isDefined()) + { + throw library::core::error::runtime::Undefined("Transformation") ; + } + + if (!this->isDefined()) + { + throw library::core::error::runtime::Undefined("Composite") ; + } + + if (aTransformation.isIdentity()) + { + return ; + } + + for (auto& objectUPtr : objects_) + { + objectUPtr->applyTransformation(aTransformation) ; + } + +} + +Composite Composite::Undefined ( ) +{ + return Composite { Array>::Empty() } ; +} + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +} +} +} +} +} + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// \ No newline at end of file diff --git a/src/Library/Mathematics/Geometry/3D/Objects/LineString.cpp b/src/Library/Mathematics/Geometry/3D/Objects/LineString.cpp index 3526aaea..a6f2599f 100644 --- a/src/Library/Mathematics/Geometry/3D/Objects/LineString.cpp +++ b/src/Library/Mathematics/Geometry/3D/Objects/LineString.cpp @@ -75,7 +75,7 @@ bool LineString::isNear ( return false ; } - for (auto pointTuple : library::core::ctnr::iterators::Zip(points_, aLineString.points_)) + for (const auto pointTuple : library::core::ctnr::iterators::Zip(points_, aLineString.points_)) { if (!std::get<0>(pointTuple).isNear(std::get<1>(pointTuple), aTolerance)) diff --git a/src/Library/Mathematics/Geometry/3D/Objects/Polygon.cpp b/src/Library/Mathematics/Geometry/3D/Objects/Polygon.cpp index 0eac597f..50368356 100644 --- a/src/Library/Mathematics/Geometry/3D/Objects/Polygon.cpp +++ b/src/Library/Mathematics/Geometry/3D/Objects/Polygon.cpp @@ -107,8 +107,8 @@ bool Polygon::isNear ( const Array firstVertices = this->getVertices() ; const Array secondVertices = aPolygon.getVertices() ; - // for (auto vertexTuple : library::core::ctnr::iterators::Zip(this->getVertices(), aPolygon.getVertices())) - for (auto vertexTuple : library::core::ctnr::iterators::Zip(firstVertices, secondVertices)) + // for (const auto vertexTuple : library::core::ctnr::iterators::Zip(this->getVertices(), aPolygon.getVertices())) + for (const auto vertexTuple : library::core::ctnr::iterators::Zip(firstVertices, secondVertices)) { if (!std::get<0>(vertexTuple).isNear(std::get<1>(vertexTuple), aTolerance)) diff --git a/src/Library/Mathematics/Geometry/3D/Objects/Pyramid.cpp b/src/Library/Mathematics/Geometry/3D/Objects/Pyramid.cpp index b4c52466..e8b4e1d9 100644 --- a/src/Library/Mathematics/Geometry/3D/Objects/Pyramid.cpp +++ b/src/Library/Mathematics/Geometry/3D/Objects/Pyramid.cpp @@ -276,14 +276,14 @@ Intersection Pyramid::intersectionWith ( if (!intersection.isEmpty()) { - if (intersection.is()) + if (intersection.accessComposite().is()) { - firstIntersectionPoints.add(intersection.as()) ; + firstIntersectionPoints.add(intersection.accessComposite().as()) ; } - else if (intersection.is()) + else if (intersection.accessComposite().is()) { - const PointSet& pointSet = intersection.as() ; + const PointSet& pointSet = intersection.accessComposite().as() ; bool secondIntersectionPointAdded = false ; diff --git a/test/Library/Mathematics/Geometry/3D/Objects/Composite.test.cpp b/test/Library/Mathematics/Geometry/3D/Objects/Composite.test.cpp new file mode 100644 index 00000000..ed65a75a --- /dev/null +++ b/test/Library/Mathematics/Geometry/3D/Objects/Composite.test.cpp @@ -0,0 +1,1040 @@ +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +/// @project Library/Mathematics +/// @file Library/Mathematics/Geometry/3D/Objects/Composite.test.cpp +/// @author Lucas Brémond +/// @license TBD + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +TEST (Library_Mathematics_Geometry_3D_Objects_Composite, Constructor) +{ + + using library::core::types::Unique ; + using library::core::types::Real ; + using library::core::ctnr::Array ; + + using library::math::obj::Vector3d ; + using library::math::geom::d3::Object ; + using library::math::geom::d3::objects::Point ; + using library::math::geom::d3::objects::Polygon ; + using library::math::geom::d3::objects::Cuboid ; + using library::math::geom::d3::objects::Pyramid ; + using library::math::geom::d3::objects::Composite ; + + { + + const Polygon base = { { { { 0.0, 0.0 }, { 1.0, 0.0 }, { 1.0, 1.0 }, { 0.0, 1.0 } } }, { 0.0, 0.0, 0.0 }, { 1.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 } } ; + const Point apex = { 0.0, 0.0, 1.0 } ; + + const Pyramid pyramid = { base, apex } ; + + EXPECT_NO_THROW(Composite composite(pyramid) ;) ; + + } + + { + + const Polygon base = { { { { 0.0, 0.0 }, { 1.0, 0.0 }, { 1.0, 1.0 }, { 0.0, 1.0 } } }, { 0.0, 0.0, 0.0 }, { 1.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 } } ; + const Point apex = { 0.0, 0.0, 1.0 } ; + + const Unique pyramidUPtr = std::make_unique(base, apex) ; + + EXPECT_NO_THROW(Composite composite(pyramidUPtr) ;) ; + + } + + { + + const Polygon base = { { { { 0.0, 0.0 }, { 1.0, 0.0 }, { 1.0, 1.0 }, { 0.0, 1.0 } } }, { 0.0, 0.0, 0.0 }, { 1.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 } } ; + const Point apex = { 0.0, 0.0, 1.0 } ; + + Unique pyramidUPtr = std::make_unique(base, apex) ; + + const Point center = { 0.0, 0.0, 0.0 } ; + const std::array axes = { Vector3d { 1.0, 0.0, 0.0 }, Vector3d { 0.0, 1.0, 0.0 }, Vector3d { 0.0, 0.0, 1.0 } } ; + const std::array extent = { 1.0, 2.0, 3.0 } ; + + Unique cuboidUPtr = std::make_unique(center, axes, extent) ; + + Array> objects = Array>::Empty() ; + + objects.emplace_back(std::move(pyramidUPtr)) ; + objects.emplace_back(std::move(cuboidUPtr)) ; + + EXPECT_NO_THROW(Composite composite(std::move(objects)) ;) ; + + } + +} + +TEST (Library_Mathematics_Geometry_3D_Objects_Composite, Clone) +{ + + using library::math::obj::Vector3d ; + using library::math::geom::d3::Object ; + using library::math::geom::d3::objects::Point ; + using library::math::geom::d3::objects::Polygon ; + using library::math::geom::d3::objects::Pyramid ; + using library::math::geom::d3::objects::Composite ; + + { + + const Polygon base = { { { { 0.0, 0.0 }, { 1.0, 0.0 }, { 1.0, 1.0 }, { 0.0, 1.0 } } }, { 0.0, 0.0, 0.0 }, { 1.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 } } ; + const Point apex = { 0.0, 0.0, 1.0 } ; + + const Pyramid pyramid = { base, apex } ; + + EXPECT_NO_THROW(Composite(pyramid).clone() ;) ; + + } + +} + +TEST (Library_Mathematics_Geometry_3D_Objects_Composite, CopyConstructor) +{ + + using library::math::obj::Vector3d ; + using library::math::geom::d3::Object ; + using library::math::geom::d3::objects::Point ; + using library::math::geom::d3::objects::Polygon ; + using library::math::geom::d3::objects::Pyramid ; + using library::math::geom::d3::objects::Composite ; + + { + + const Polygon base = { { { { 0.0, 0.0 }, { 1.0, 0.0 }, { 1.0, 1.0 }, { 0.0, 1.0 } } }, { 0.0, 0.0, 0.0 }, { 1.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 } } ; + const Point apex = { 0.0, 0.0, 1.0 } ; + + const Pyramid pyramid = { base, apex } ; + + const Composite composite = Composite { pyramid } ; + + EXPECT_NO_THROW(Composite otherComposite(composite) ;) ; + + } + +} + +TEST (Library_Mathematics_Geometry_3D_Objects_Composite, EqualToOperator) +{ + + using library::core::types::Unique ; + using library::core::types::Real ; + using library::core::ctnr::Array ; + + using library::math::obj::Vector3d ; + using library::math::geom::d3::Object ; + using library::math::geom::d3::objects::Point ; + using library::math::geom::d3::objects::Polygon ; + using library::math::geom::d3::objects::Cuboid ; + using library::math::geom::d3::objects::Pyramid ; + using library::math::geom::d3::objects::Composite ; + + { + + const Polygon base = { { { { 0.0, 0.0 }, { 1.0, 0.0 }, { 1.0, 1.0 }, { 0.0, 1.0 } } }, { 0.0, 0.0, 0.0 }, { 1.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 } } ; + const Point apex = { 0.0, 0.0, 1.0 } ; + + const Pyramid pyramid = { base, apex } ; + + const Composite composite = Composite { pyramid } ; + + EXPECT_TRUE(composite == composite) ; + + } + + { + + const Polygon base = { { { { 0.0, 0.0 }, { 1.0, 0.0 }, { 1.0, 1.0 }, { 0.0, 1.0 } } }, { 0.0, 0.0, 0.0 }, { 1.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 } } ; + const Point apex = { 0.0, 0.0, 1.0 } ; + + Unique pyramidUPtr = std::make_unique(base, apex) ; + + const Point center = { 0.0, 0.0, 0.0 } ; + const std::array axes = { Vector3d { 1.0, 0.0, 0.0 }, Vector3d { 0.0, 1.0, 0.0 }, Vector3d { 0.0, 0.0, 1.0 } } ; + const std::array extent = { 1.0, 2.0, 3.0 } ; + + Unique cuboidUPtr = std::make_unique(center, axes, extent) ; + + Array> objects = Array>::Empty() ; + + objects.emplace_back(std::move(pyramidUPtr)) ; + objects.emplace_back(std::move(cuboidUPtr)) ; + + const Composite composite = Composite { std::move(objects) } ; + + EXPECT_TRUE(composite == composite) ; + + } + + { + + const Polygon base = { { { { 0.0, 0.0 }, { 1.0, 0.0 }, { 1.0, 1.0 }, { 0.0, 1.0 } } }, { 0.0, 0.0, 0.0 }, { 1.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 } } ; + const Point apex = { 0.0, 0.0, 1.0 } ; + + const Pyramid pyramid = { base, apex } ; + + const Composite firstComposite = Composite { pyramid } ; + + const Point center = { 0.0, 0.0, 0.0 } ; + const std::array axes = { Vector3d { 1.0, 0.0, 0.0 }, Vector3d { 0.0, 1.0, 0.0 }, Vector3d { 0.0, 0.0, 1.0 } } ; + const std::array extent = { 1.0, 2.0, 3.0 } ; + + const Cuboid cuboid = { center, axes, extent } ; + + const Composite secondComposite = Composite { cuboid } ; + + EXPECT_FALSE(firstComposite == secondComposite) ; + + } + + { + + const Polygon base = { { { { 0.0, 0.0 }, { 1.0, 0.0 }, { 1.0, 1.0 }, { 0.0, 1.0 } } }, { 0.0, 0.0, 0.0 }, { 1.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 } } ; + const Point apex = { 0.0, 0.0, 1.0 } ; + + const Unique pyramidUPtr = std::make_unique(base, apex) ; + + const Point center = { 0.0, 0.0, 0.0 } ; + const std::array axes = { Vector3d { 1.0, 0.0, 0.0 }, Vector3d { 0.0, 1.0, 0.0 }, Vector3d { 0.0, 0.0, 1.0 } } ; + const std::array extent = { 1.0, 2.0, 3.0 } ; + + const Unique cuboidUPtr = std::make_unique(center, axes, extent) ; + + Array> firstObjects = Array>::Empty() ; + + firstObjects.emplace_back(std::move(pyramidUPtr->clone())) ; + firstObjects.emplace_back(std::move(cuboidUPtr->clone())) ; + + const Composite firstComposite = Composite { std::move(firstObjects) } ; + + Array> secondObjects = Array>::Empty() ; + + secondObjects.emplace_back(std::move(cuboidUPtr->clone())) ; + secondObjects.emplace_back(std::move(pyramidUPtr->clone())) ; + + const Composite secondComposite = Composite { std::move(secondObjects) } ; + + EXPECT_FALSE(firstComposite == secondComposite) ; + + } + + { + + const Polygon base = { { { { 0.0, 0.0 }, { 1.0, 0.0 }, { 1.0, 1.0 }, { 0.0, 1.0 } } }, { 0.0, 0.0, 0.0 }, { 1.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 } } ; + const Point apex = { 0.0, 0.0, 1.0 } ; + + const Pyramid pyramid = { base, apex } ; + + const Composite composite = Composite { pyramid } ; + + EXPECT_FALSE(Composite::Undefined() == Composite::Undefined()) ; + EXPECT_FALSE(Composite::Undefined() == composite) ; + EXPECT_FALSE(composite == Composite::Undefined()) ; + + } + +} + +TEST (Library_Mathematics_Geometry_3D_Objects_Composite, NotEqualToOperator) +{ + + using library::core::types::Unique ; + using library::core::types::Real ; + using library::core::ctnr::Array ; + + using library::math::obj::Vector3d ; + using library::math::geom::d3::Object ; + using library::math::geom::d3::objects::Point ; + using library::math::geom::d3::objects::Polygon ; + using library::math::geom::d3::objects::Cuboid ; + using library::math::geom::d3::objects::Pyramid ; + using library::math::geom::d3::objects::Composite ; + + { + + const Polygon base = { { { { 0.0, 0.0 }, { 1.0, 0.0 }, { 1.0, 1.0 }, { 0.0, 1.0 } } }, { 0.0, 0.0, 0.0 }, { 1.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 } } ; + const Point apex = { 0.0, 0.0, 1.0 } ; + + const Pyramid pyramid = { base, apex } ; + + const Composite composite = Composite { pyramid } ; + + EXPECT_FALSE(composite != composite) ; + + } + + { + + const Polygon base = { { { { 0.0, 0.0 }, { 1.0, 0.0 }, { 1.0, 1.0 }, { 0.0, 1.0 } } }, { 0.0, 0.0, 0.0 }, { 1.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 } } ; + const Point apex = { 0.0, 0.0, 1.0 } ; + + Unique pyramidUPtr = std::make_unique(base, apex) ; + + const Point center = { 0.0, 0.0, 0.0 } ; + const std::array axes = { Vector3d { 1.0, 0.0, 0.0 }, Vector3d { 0.0, 1.0, 0.0 }, Vector3d { 0.0, 0.0, 1.0 } } ; + const std::array extent = { 1.0, 2.0, 3.0 } ; + + Unique cuboidUPtr = std::make_unique(center, axes, extent) ; + + Array> objects = Array>::Empty() ; + + objects.emplace_back(std::move(pyramidUPtr)) ; + objects.emplace_back(std::move(cuboidUPtr)) ; + + const Composite composite = Composite { std::move(objects) } ; + + EXPECT_FALSE(composite != composite) ; + + } + + { + + const Polygon base = { { { { 0.0, 0.0 }, { 1.0, 0.0 }, { 1.0, 1.0 }, { 0.0, 1.0 } } }, { 0.0, 0.0, 0.0 }, { 1.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 } } ; + const Point apex = { 0.0, 0.0, 1.0 } ; + + const Pyramid pyramid = { base, apex } ; + + const Composite firstComposite = Composite { pyramid } ; + + const Point center = { 0.0, 0.0, 0.0 } ; + const std::array axes = { Vector3d { 1.0, 0.0, 0.0 }, Vector3d { 0.0, 1.0, 0.0 }, Vector3d { 0.0, 0.0, 1.0 } } ; + const std::array extent = { 1.0, 2.0, 3.0 } ; + + const Cuboid cuboid = { center, axes, extent } ; + + const Composite secondComposite = Composite { cuboid } ; + + EXPECT_TRUE(firstComposite != secondComposite) ; + + } + + { + + const Polygon base = { { { { 0.0, 0.0 }, { 1.0, 0.0 }, { 1.0, 1.0 }, { 0.0, 1.0 } } }, { 0.0, 0.0, 0.0 }, { 1.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 } } ; + const Point apex = { 0.0, 0.0, 1.0 } ; + + const Unique pyramidUPtr = std::make_unique(base, apex) ; + + const Point center = { 0.0, 0.0, 0.0 } ; + const std::array axes = { Vector3d { 1.0, 0.0, 0.0 }, Vector3d { 0.0, 1.0, 0.0 }, Vector3d { 0.0, 0.0, 1.0 } } ; + const std::array extent = { 1.0, 2.0, 3.0 } ; + + const Unique cuboidUPtr = std::make_unique(center, axes, extent) ; + + Array> firstObjects = Array>::Empty() ; + + firstObjects.emplace_back(std::move(pyramidUPtr->clone())) ; + firstObjects.emplace_back(std::move(cuboidUPtr->clone())) ; + + const Composite firstComposite = Composite { std::move(firstObjects) } ; + + Array> secondObjects = Array>::Empty() ; + + secondObjects.emplace_back(std::move(cuboidUPtr->clone())) ; + secondObjects.emplace_back(std::move(pyramidUPtr->clone())) ; + + const Composite secondComposite = Composite { std::move(secondObjects) } ; + + EXPECT_TRUE(firstComposite != secondComposite) ; + + } + + { + + const Polygon base = { { { { 0.0, 0.0 }, { 1.0, 0.0 }, { 1.0, 1.0 }, { 0.0, 1.0 } } }, { 0.0, 0.0, 0.0 }, { 1.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 } } ; + const Point apex = { 0.0, 0.0, 1.0 } ; + + const Pyramid pyramid = { base, apex } ; + + const Composite composite = Composite { pyramid } ; + + EXPECT_TRUE(Composite::Undefined() != Composite::Undefined()) ; + EXPECT_TRUE(Composite::Undefined() != composite) ; + EXPECT_TRUE(composite != Composite::Undefined()) ; + + } + +} + +TEST (Library_Mathematics_Geometry_3D_Objects_Composite, AdditionOperator) +{ + + using library::core::types::Unique ; + using library::core::types::Real ; + using library::core::ctnr::Array ; + + using library::math::obj::Vector3d ; + using library::math::geom::d3::Object ; + using library::math::geom::d3::objects::Point ; + using library::math::geom::d3::objects::Polygon ; + using library::math::geom::d3::objects::Cuboid ; + using library::math::geom::d3::objects::Pyramid ; + using library::math::geom::d3::objects::Composite ; + + { + + const Polygon base = { { { { 0.0, 0.0 }, { 1.0, 0.0 }, { 1.0, 1.0 }, { 0.0, 1.0 } } }, { 0.0, 0.0, 0.0 }, { 1.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 } } ; + const Point apex = { 0.0, 0.0, 1.0 } ; + + const Pyramid pyramid = { base, apex } ; + + const Composite composite = Composite { pyramid } ; + + EXPECT_NO_THROW(composite + composite) ; + + } + + { + + EXPECT_ANY_THROW(Composite::Undefined() + Composite::Undefined()) ; + + } + +} + +TEST (Library_Mathematics_Geometry_3D_Objects_Composite, AdditionAssignmentOperator) +{ + + using library::core::types::Unique ; + using library::core::types::Real ; + using library::core::ctnr::Array ; + + using library::math::obj::Vector3d ; + using library::math::geom::d3::Object ; + using library::math::geom::d3::objects::Point ; + using library::math::geom::d3::objects::Polygon ; + using library::math::geom::d3::objects::Cuboid ; + using library::math::geom::d3::objects::Pyramid ; + using library::math::geom::d3::objects::Composite ; + + { + + const Polygon base = { { { { 0.0, 0.0 }, { 1.0, 0.0 }, { 1.0, 1.0 }, { 0.0, 1.0 } } }, { 0.0, 0.0, 0.0 }, { 1.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 } } ; + const Point apex = { 0.0, 0.0, 1.0 } ; + + const Pyramid pyramid = { base, apex } ; + + Composite composite = Composite { pyramid } ; + + EXPECT_NO_THROW(composite += composite) ; + + } + + { + + Composite firstComposite = Composite::Undefined() ; + + const Polygon base = { { { { 0.0, 0.0 }, { 1.0, 0.0 }, { 1.0, 1.0 }, { 0.0, 1.0 } } }, { 0.0, 0.0, 0.0 }, { 1.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 } } ; + const Point apex = { 0.0, 0.0, 1.0 } ; + + const Pyramid pyramid = { base, apex } ; + + const Composite composite = Composite { pyramid } ; + + EXPECT_NO_THROW(firstComposite += composite) ; + + } + + { + + Composite composite = Composite::Undefined() ; + + EXPECT_ANY_THROW(composite += Composite::Undefined()) ; + + } + +} + +TEST (Library_Mathematics_Geometry_3D_Objects_Composite, StreamOperator) +{ + + using library::core::types::Unique ; + using library::core::types::Real ; + using library::core::ctnr::Array ; + + using library::math::obj::Vector3d ; + using library::math::geom::d3::Object ; + using library::math::geom::d3::objects::Point ; + using library::math::geom::d3::objects::Polygon ; + using library::math::geom::d3::objects::Cuboid ; + using library::math::geom::d3::objects::Pyramid ; + using library::math::geom::d3::objects::Composite ; + + { + + const Polygon base = { { { { 0.0, 0.0 }, { 1.0, 0.0 }, { 1.0, 1.0 }, { 0.0, 1.0 } } }, { 0.0, 0.0, 0.0 }, { 1.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 } } ; + const Point apex = { 0.0, 0.0, 1.0 } ; + + const Pyramid pyramid = { base, apex } ; + + const Composite composite = Composite { pyramid } ; + + testing::internal::CaptureStdout() ; + + EXPECT_NO_THROW(std::cout << composite << std::endl) ; + + EXPECT_FALSE(testing::internal::GetCapturedStdout().empty()) ; + + } + +} + +TEST (Library_Mathematics_Geometry_3D_Objects_Composite, IsDefined) +{ + + using library::core::types::Unique ; + using library::core::types::Real ; + using library::core::ctnr::Array ; + + using library::math::obj::Vector3d ; + using library::math::geom::d3::Object ; + using library::math::geom::d3::objects::Point ; + using library::math::geom::d3::objects::Polygon ; + using library::math::geom::d3::objects::Cuboid ; + using library::math::geom::d3::objects::Pyramid ; + using library::math::geom::d3::objects::Composite ; + + { + + const Polygon base = { { { { 0.0, 0.0 }, { 1.0, 0.0 }, { 1.0, 1.0 }, { 0.0, 1.0 } } }, { 0.0, 0.0, 0.0 }, { 1.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 } } ; + const Point apex = { 0.0, 0.0, 1.0 } ; + + const Pyramid pyramid = { base, apex } ; + + const Composite composite = Composite { pyramid } ; + + EXPECT_TRUE(composite.isDefined()) ; + + } + + { + + EXPECT_FALSE(Composite::Undefined().isDefined()) ; + + } + +} + +TEST (Library_Mathematics_Geometry_3D_Objects_Composite, Intersects) +{ + + using library::core::types::Unique ; + using library::core::types::Real ; + using library::core::ctnr::Array ; + + using library::math::obj::Vector3d ; + using library::math::geom::d3::Object ; + using library::math::geom::d3::objects::Point ; + using library::math::geom::d3::objects::Polygon ; + using library::math::geom::d3::objects::Cuboid ; + using library::math::geom::d3::objects::Pyramid ; + using library::math::geom::d3::objects::Composite ; + + // [TBI] + + // { + + // const Polygon base = { { { { 0.0, 0.0 }, { 1.0, 0.0 }, { 1.0, 1.0 }, { 0.0, 1.0 } } }, { 0.0, 0.0, 0.0 }, { 1.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 } } ; + // const Point apex = { 0.0, 0.0, 1.0 } ; + + // const Pyramid pyramid = { base, apex } ; + + // const Composite composite = Composite { pyramid } ; + + // EXPECT_TRUE(composite.intersects(composite)) ; + + // } + + { + + const Polygon base = { { { { 0.0, 0.0 }, { 1.0, 0.0 }, { 1.0, 1.0 }, { 0.0, 1.0 } } }, { 0.0, 0.0, 0.0 }, { 1.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 } } ; + const Point apex = { 0.0, 0.0, 1.0 } ; + + const Pyramid pyramid = { base, apex } ; + + const Composite composite = Composite { pyramid } ; + + EXPECT_ANY_THROW(Composite::Undefined().intersects(Composite::Undefined())) ; + EXPECT_ANY_THROW(Composite::Undefined().intersects(composite)) ; + EXPECT_ANY_THROW(composite.intersects(Composite::Undefined())) ; + + } + +} + +TEST (Library_Mathematics_Geometry_3D_Objects_Composite, Contains) +{ + + using library::core::types::Unique ; + using library::core::types::Real ; + using library::core::ctnr::Array ; + + using library::math::obj::Vector3d ; + using library::math::geom::d3::Object ; + using library::math::geom::d3::objects::Point ; + using library::math::geom::d3::objects::Polygon ; + using library::math::geom::d3::objects::Cuboid ; + using library::math::geom::d3::objects::Pyramid ; + using library::math::geom::d3::objects::Composite ; + + // [TBI] + + // { + + // const Polygon base = { { { { 0.0, 0.0 }, { 1.0, 0.0 }, { 1.0, 1.0 }, { 0.0, 1.0 } } }, { 0.0, 0.0, 0.0 }, { 1.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 } } ; + // const Point apex = { 0.0, 0.0, 1.0 } ; + + // const Pyramid pyramid = { base, apex } ; + + // const Composite composite = Composite { pyramid } ; + + // EXPECT_TRUE(composite.contains(composite)) ; + + // } + + { + + const Polygon base = { { { { 0.0, 0.0 }, { 1.0, 0.0 }, { 1.0, 1.0 }, { 0.0, 1.0 } } }, { 0.0, 0.0, 0.0 }, { 1.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 } } ; + const Point apex = { 0.0, 0.0, 1.0 } ; + + const Pyramid pyramid = { base, apex } ; + + const Composite composite = Composite { pyramid } ; + + EXPECT_ANY_THROW(Composite::Undefined().contains(Composite::Undefined())) ; + EXPECT_ANY_THROW(Composite::Undefined().contains(composite)) ; + EXPECT_ANY_THROW(composite.contains(Composite::Undefined())) ; + + } + +} + +TEST (Library_Mathematics_Geometry_3D_Objects_Composite, Is) +{ + + using library::core::types::Unique ; + using library::core::types::Real ; + using library::core::ctnr::Array ; + + using library::math::obj::Vector3d ; + using library::math::geom::d3::Object ; + using library::math::geom::d3::objects::Point ; + using library::math::geom::d3::objects::Polygon ; + using library::math::geom::d3::objects::Cuboid ; + using library::math::geom::d3::objects::Pyramid ; + using library::math::geom::d3::objects::Composite ; + + { + + const Polygon base = { { { { 0.0, 0.0 }, { 1.0, 0.0 }, { 1.0, 1.0 }, { 0.0, 1.0 } } }, { 0.0, 0.0, 0.0 }, { 1.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 } } ; + const Point apex = { 0.0, 0.0, 1.0 } ; + + const Pyramid pyramid = { base, apex } ; + + const Composite composite = Composite { pyramid } ; + + EXPECT_TRUE(composite.is()) ; + + EXPECT_FALSE(composite.is()) ; + + } + + { + + EXPECT_ANY_THROW(Composite::Undefined().is()) ; + + } + +} + +TEST (Library_Mathematics_Geometry_3D_Objects_Composite, As) +{ + + using library::core::types::Unique ; + using library::core::types::Real ; + using library::core::ctnr::Array ; + + using library::math::obj::Vector3d ; + using library::math::geom::d3::Object ; + using library::math::geom::d3::objects::Point ; + using library::math::geom::d3::objects::Polygon ; + using library::math::geom::d3::objects::Cuboid ; + using library::math::geom::d3::objects::Pyramid ; + using library::math::geom::d3::objects::Composite ; + + { + + const Polygon base = { { { { 0.0, 0.0 }, { 1.0, 0.0 }, { 1.0, 1.0 }, { 0.0, 1.0 } } }, { 0.0, 0.0, 0.0 }, { 1.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 } } ; + const Point apex = { 0.0, 0.0, 1.0 } ; + + const Pyramid pyramid = { base, apex } ; + + const Composite composite = Composite { pyramid } ; + + EXPECT_EQ(pyramid, composite.as()) ; + + EXPECT_ANY_THROW(composite.as()) ; + + } + + { + + EXPECT_ANY_THROW(Composite::Undefined().as()) ; + + } + +} + +TEST (Library_Mathematics_Geometry_3D_Objects_Composite, AccessObjectAt) +{ + + using library::core::types::Unique ; + using library::core::types::Real ; + using library::core::ctnr::Array ; + + using library::math::obj::Vector3d ; + using library::math::geom::d3::Object ; + using library::math::geom::d3::objects::Point ; + using library::math::geom::d3::objects::Polygon ; + using library::math::geom::d3::objects::Cuboid ; + using library::math::geom::d3::objects::Pyramid ; + using library::math::geom::d3::objects::Composite ; + + { + + const Polygon base = { { { { 0.0, 0.0 }, { 1.0, 0.0 }, { 1.0, 1.0 }, { 0.0, 1.0 } } }, { 0.0, 0.0, 0.0 }, { 1.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 } } ; + const Point apex = { 0.0, 0.0, 1.0 } ; + + const Pyramid pyramid = { base, apex } ; + + const Composite composite = Composite { pyramid } ; + + EXPECT_TRUE(composite.accessObjectAt(0).is()) ; + + EXPECT_ANY_THROW(composite.accessObjectAt(1)) ; + + } + + { + + const Polygon base = { { { { 0.0, 0.0 }, { 1.0, 0.0 }, { 1.0, 1.0 }, { 0.0, 1.0 } } }, { 0.0, 0.0, 0.0 }, { 1.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 } } ; + const Point apex = { 0.0, 0.0, 1.0 } ; + + Unique pyramidUPtr = std::make_unique(base, apex) ; + + const Point center = { 0.0, 0.0, 0.0 } ; + const std::array axes = { Vector3d { 1.0, 0.0, 0.0 }, Vector3d { 0.0, 1.0, 0.0 }, Vector3d { 0.0, 0.0, 1.0 } } ; + const std::array extent = { 1.0, 2.0, 3.0 } ; + + Unique cuboidUPtr = std::make_unique(center, axes, extent) ; + + Array> objects = Array>::Empty() ; + + objects.emplace_back(std::move(pyramidUPtr)) ; + objects.emplace_back(std::move(cuboidUPtr)) ; + + const Composite composite = Composite { std::move(objects) } ; + + EXPECT_TRUE(composite.accessObjectAt(0).is()) ; + EXPECT_TRUE(composite.accessObjectAt(1).is()) ; + + EXPECT_ANY_THROW(composite.accessObjectAt(2)) ; + + } + + { + + EXPECT_ANY_THROW(Composite::Undefined().accessObjectAt(0)) ; + + } + +} + +TEST (Library_Mathematics_Geometry_3D_Objects_Composite, AccessObjects) +{ + + using library::core::types::Unique ; + using library::core::types::Real ; + using library::core::ctnr::Array ; + + using library::math::obj::Vector3d ; + using library::math::geom::d3::Object ; + using library::math::geom::d3::objects::Point ; + using library::math::geom::d3::objects::Polygon ; + using library::math::geom::d3::objects::Cuboid ; + using library::math::geom::d3::objects::Pyramid ; + using library::math::geom::d3::objects::Composite ; + + { + + const Polygon base = { { { { 0.0, 0.0 }, { 1.0, 0.0 }, { 1.0, 1.0 }, { 0.0, 1.0 } } }, { 0.0, 0.0, 0.0 }, { 1.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 } } ; + const Point apex = { 0.0, 0.0, 1.0 } ; + + const Pyramid pyramid = { base, apex } ; + + const Composite composite = Composite { pyramid } ; + + EXPECT_EQ(1, composite.accessObjects().getSize()) ; + + } + + { + + const Polygon base = { { { { 0.0, 0.0 }, { 1.0, 0.0 }, { 1.0, 1.0 }, { 0.0, 1.0 } } }, { 0.0, 0.0, 0.0 }, { 1.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 } } ; + const Point apex = { 0.0, 0.0, 1.0 } ; + + Unique pyramidUPtr = std::make_unique(base, apex) ; + + const Point center = { 0.0, 0.0, 0.0 } ; + const std::array axes = { Vector3d { 1.0, 0.0, 0.0 }, Vector3d { 0.0, 1.0, 0.0 }, Vector3d { 0.0, 0.0, 1.0 } } ; + const std::array extent = { 1.0, 2.0, 3.0 } ; + + Unique cuboidUPtr = std::make_unique(center, axes, extent) ; + + Array> objects = Array>::Empty() ; + + objects.emplace_back(std::move(pyramidUPtr)) ; + objects.emplace_back(std::move(cuboidUPtr)) ; + + const Composite composite = Composite { std::move(objects) } ; + + EXPECT_EQ(2, composite.accessObjects().getSize()) ; + + } + + { + + EXPECT_ANY_THROW(Composite::Undefined().accessObjects()) ; + + } + +} + +TEST (Library_Mathematics_Geometry_3D_Objects_Composite, GetObjectCount) +{ + + using library::core::types::Unique ; + using library::core::types::Real ; + using library::core::ctnr::Array ; + + using library::math::obj::Vector3d ; + using library::math::geom::d3::Object ; + using library::math::geom::d3::objects::Point ; + using library::math::geom::d3::objects::Polygon ; + using library::math::geom::d3::objects::Cuboid ; + using library::math::geom::d3::objects::Pyramid ; + using library::math::geom::d3::objects::Composite ; + + { + + const Polygon base = { { { { 0.0, 0.0 }, { 1.0, 0.0 }, { 1.0, 1.0 }, { 0.0, 1.0 } } }, { 0.0, 0.0, 0.0 }, { 1.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 } } ; + const Point apex = { 0.0, 0.0, 1.0 } ; + + const Pyramid pyramid = { base, apex } ; + + const Composite composite = Composite { pyramid } ; + + EXPECT_EQ(1, composite.getObjectCount()) ; + + } + + { + + const Polygon base = { { { { 0.0, 0.0 }, { 1.0, 0.0 }, { 1.0, 1.0 }, { 0.0, 1.0 } } }, { 0.0, 0.0, 0.0 }, { 1.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 } } ; + const Point apex = { 0.0, 0.0, 1.0 } ; + + Unique pyramidUPtr = std::make_unique(base, apex) ; + + const Point center = { 0.0, 0.0, 0.0 } ; + const std::array axes = { Vector3d { 1.0, 0.0, 0.0 }, Vector3d { 0.0, 1.0, 0.0 }, Vector3d { 0.0, 0.0, 1.0 } } ; + const std::array extent = { 1.0, 2.0, 3.0 } ; + + Unique cuboidUPtr = std::make_unique(center, axes, extent) ; + + Array> objects = Array>::Empty() ; + + objects.emplace_back(std::move(pyramidUPtr)) ; + objects.emplace_back(std::move(cuboidUPtr)) ; + + const Composite composite = Composite { std::move(objects) } ; + + EXPECT_EQ(2, composite.getObjectCount()) ; + + } + + { + + EXPECT_ANY_THROW(Composite::Undefined().getObjectCount()) ; + + } + +} + +TEST (Library_Mathematics_Geometry_3D_Objects_Composite, ConstIterator) +{ + + using library::core::types::Unique ; + using library::core::types::Real ; + using library::core::ctnr::Array ; + + using library::math::obj::Vector3d ; + using library::math::geom::d3::Object ; + using library::math::geom::d3::objects::Point ; + using library::math::geom::d3::objects::Polygon ; + using library::math::geom::d3::objects::Cuboid ; + using library::math::geom::d3::objects::Pyramid ; + using library::math::geom::d3::objects::Composite ; + + { + + const Polygon base = { { { { 0.0, 0.0 }, { 1.0, 0.0 }, { 1.0, 1.0 }, { 0.0, 1.0 } } }, { 0.0, 0.0, 0.0 }, { 1.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 } } ; + const Point apex = { 0.0, 0.0, 1.0 } ; + + const Pyramid pyramid = { base, apex } ; + + const Composite composite = Composite { pyramid } ; + + EXPECT_NO_THROW + ( + + for (const auto& objectUPtr : composite) + { + EXPECT_TRUE(objectUPtr->isDefined()) ; + } + + ) ; + + } + + { + + const Polygon base = { { { { 0.0, 0.0 }, { 1.0, 0.0 }, { 1.0, 1.0 }, { 0.0, 1.0 } } }, { 0.0, 0.0, 0.0 }, { 1.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 } } ; + const Point apex = { 0.0, 0.0, 1.0 } ; + + Unique pyramidUPtr = std::make_unique(base, apex) ; + + const Point center = { 0.0, 0.0, 0.0 } ; + const std::array axes = { Vector3d { 1.0, 0.0, 0.0 }, Vector3d { 0.0, 1.0, 0.0 }, Vector3d { 0.0, 0.0, 1.0 } } ; + const std::array extent = { 1.0, 2.0, 3.0 } ; + + Unique cuboidUPtr = std::make_unique(center, axes, extent) ; + + Array> objects = Array>::Empty() ; + + objects.emplace_back(std::move(pyramidUPtr)) ; + objects.emplace_back(std::move(cuboidUPtr)) ; + + const Composite composite = Composite { std::move(objects) } ; + + EXPECT_NO_THROW + ( + + for (const auto& objectUPtr : composite) + { + EXPECT_TRUE(objectUPtr->isDefined()) ; + } + + ) ; + + } + + { + + EXPECT_ANY_THROW + ( + + for (const auto& objectUPtr : Composite::Undefined()) + { + (void) objectUPtr ; + } + + ) ; + + } + +} + +TEST (Library_Mathematics_Geometry_3D_Objects_Composite, ApplyTransformation) +{ + + using library::core::types::Unique ; + using library::core::types::Real ; + using library::core::ctnr::Array ; + + using library::math::obj::Vector3d ; + using library::math::geom::d3::Object ; + using library::math::geom::d3::objects::Point ; + using library::math::geom::d3::objects::Polygon ; + using library::math::geom::d3::objects::Cuboid ; + using library::math::geom::d3::objects::Pyramid ; + using library::math::geom::d3::objects::Composite ; + using library::math::geom::d3::Transformation ; + + { + + const Polygon base = { { { { 0.0, 0.0 }, { 1.0, 0.0 }, { 1.0, 1.0 }, { 0.0, 1.0 } } }, { 0.0, 0.0, 0.0 }, { 1.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 } } ; + const Point apex = { 0.0, 0.0, 1.0 } ; + + const Pyramid pyramid = { base, apex } ; + + Composite composite = Composite { pyramid } ; + + EXPECT_NO_THROW(composite.applyTransformation(Transformation::Identity())) ; + + } + + { + + const Polygon base = { { { { 0.0, 0.0 }, { 1.0, 0.0 }, { 1.0, 1.0 }, { 0.0, 1.0 } } }, { 0.0, 0.0, 0.0 }, { 1.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 } } ; + const Point apex = { 0.0, 0.0, 1.0 } ; + + const Pyramid pyramid = { base, apex } ; + + Composite composite = Composite { pyramid } ; + + EXPECT_ANY_THROW(composite.applyTransformation(Transformation::Undefined())) ; + EXPECT_ANY_THROW(Composite::Undefined().applyTransformation(Transformation::Undefined())) ; + EXPECT_ANY_THROW(Composite::Undefined().applyTransformation(Transformation::Identity())) ; + + + } + +} + +TEST (Library_Mathematics_Geometry_3D_Objects_Composite, Undefined) +{ + + using library::math::geom::d3::objects::Composite ; + + { + + EXPECT_NO_THROW(Composite::Undefined()) ; + EXPECT_FALSE(Composite::Undefined().isDefined()) ; + + } + +} + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// \ No newline at end of file diff --git a/test/Library/Mathematics/Geometry/3D/Objects/Ellipsoid.test.cpp b/test/Library/Mathematics/Geometry/3D/Objects/Ellipsoid.test.cpp index a3963943..725b2178 100644 --- a/test/Library/Mathematics/Geometry/3D/Objects/Ellipsoid.test.cpp +++ b/test/Library/Mathematics/Geometry/3D/Objects/Ellipsoid.test.cpp @@ -1046,9 +1046,9 @@ TEST (Library_Mathematics_Geometry_3D_Objects_Ellipsoid, IntersectionWith_Line) EXPECT_TRUE(intersection.isDefined()) ; - ASSERT_TRUE(intersection.is()) ; + ASSERT_TRUE(intersection.accessComposite().is()) ; - const PointSet pointSet = intersection.as() ; + const PointSet pointSet = intersection.accessComposite().as() ; EXPECT_EQ(2, pointSet.getSize()) ; @@ -1065,9 +1065,9 @@ TEST (Library_Mathematics_Geometry_3D_Objects_Ellipsoid, IntersectionWith_Line) EXPECT_TRUE(intersection.isDefined()) ; - ASSERT_TRUE(intersection.is()) ; + ASSERT_TRUE(intersection.accessComposite().is()) ; - const PointSet pointSet = intersection.as() ; + const PointSet pointSet = intersection.accessComposite().as() ; EXPECT_EQ(2, pointSet.getSize()) ; @@ -1084,9 +1084,9 @@ TEST (Library_Mathematics_Geometry_3D_Objects_Ellipsoid, IntersectionWith_Line) EXPECT_TRUE(intersection.isDefined()) ; - ASSERT_TRUE(intersection.is()) ; + ASSERT_TRUE(intersection.accessComposite().is()) ; - const PointSet pointSet = intersection.as() ; + const PointSet pointSet = intersection.accessComposite().as() ; EXPECT_EQ(2, pointSet.getSize()) ; @@ -1103,9 +1103,9 @@ TEST (Library_Mathematics_Geometry_3D_Objects_Ellipsoid, IntersectionWith_Line) EXPECT_TRUE(intersection.isDefined()) ; - ASSERT_TRUE(intersection.is()) ; + ASSERT_TRUE(intersection.accessComposite().is()) ; - const Point point = intersection.as() ; + const Point point = intersection.accessComposite().as() ; EXPECT_TRUE(point.isNear(Point(0.0, 0.0, +3.0), Real::Epsilon())) ; @@ -1120,9 +1120,9 @@ TEST (Library_Mathematics_Geometry_3D_Objects_Ellipsoid, IntersectionWith_Line) EXPECT_TRUE(intersection.isDefined()) ; - ASSERT_TRUE(intersection.is()) ; + ASSERT_TRUE(intersection.accessComposite().is()) ; - const Point point = intersection.as() ; + const Point point = intersection.accessComposite().as() ; EXPECT_TRUE(point.isNear(Point(0.0, 0.0, -3.0), Real::Epsilon())) ; @@ -1169,9 +1169,9 @@ TEST (Library_Mathematics_Geometry_3D_Objects_Ellipsoid, IntersectionWith_Ray) EXPECT_TRUE(intersection.isDefined()) ; - ASSERT_TRUE(intersection.is()) ; + ASSERT_TRUE(intersection.accessComposite().is()) ; - const Point point = intersection.as() ; + const Point point = intersection.accessComposite().as() ; EXPECT_TRUE(point.isNear(Point(1.0, 0.0, 0.0), Real::Epsilon())) ; @@ -1186,9 +1186,9 @@ TEST (Library_Mathematics_Geometry_3D_Objects_Ellipsoid, IntersectionWith_Ray) EXPECT_TRUE(intersection.isDefined()) ; - ASSERT_TRUE(intersection.is()) ; + ASSERT_TRUE(intersection.accessComposite().is()) ; - const PointSet pointSet = intersection.as() ; + const PointSet pointSet = intersection.accessComposite().as() ; EXPECT_EQ(2, pointSet.getSize()) ; @@ -1205,9 +1205,9 @@ TEST (Library_Mathematics_Geometry_3D_Objects_Ellipsoid, IntersectionWith_Ray) EXPECT_TRUE(intersection.isDefined()) ; - ASSERT_TRUE(intersection.is()) ; + ASSERT_TRUE(intersection.accessComposite().is()) ; - const PointSet pointSet = intersection.as() ; + const PointSet pointSet = intersection.accessComposite().as() ; EXPECT_EQ(2, pointSet.getSize()) ; @@ -1224,9 +1224,9 @@ TEST (Library_Mathematics_Geometry_3D_Objects_Ellipsoid, IntersectionWith_Ray) EXPECT_TRUE(intersection.isDefined()) ; - ASSERT_TRUE(intersection.is()) ; + ASSERT_TRUE(intersection.accessComposite().is()) ; - const PointSet pointSet = intersection.as() ; + const PointSet pointSet = intersection.accessComposite().as() ; EXPECT_EQ(2, pointSet.getSize()) ; @@ -1243,9 +1243,9 @@ TEST (Library_Mathematics_Geometry_3D_Objects_Ellipsoid, IntersectionWith_Ray) EXPECT_TRUE(intersection.isDefined()) ; - ASSERT_TRUE(intersection.is()) ; + ASSERT_TRUE(intersection.accessComposite().is()) ; - const PointSet pointSet = intersection.as() ; + const PointSet pointSet = intersection.accessComposite().as() ; EXPECT_EQ(2, pointSet.getSize()) ; @@ -1273,9 +1273,9 @@ TEST (Library_Mathematics_Geometry_3D_Objects_Ellipsoid, IntersectionWith_Ray) EXPECT_TRUE(intersection.isDefined()) ; - ASSERT_TRUE(intersection.is()) ; + ASSERT_TRUE(intersection.accessComposite().is()) ; - const Point point = intersection.as() ; + const Point point = intersection.accessComposite().as() ; EXPECT_TRUE(point.isNear(Point(0.0, 0.0, +3.0), Real::Epsilon())) ; @@ -1290,9 +1290,9 @@ TEST (Library_Mathematics_Geometry_3D_Objects_Ellipsoid, IntersectionWith_Ray) EXPECT_TRUE(intersection.isDefined()) ; - ASSERT_TRUE(intersection.is()) ; + ASSERT_TRUE(intersection.accessComposite().is()) ; - const Point point = intersection.as() ; + const Point point = intersection.accessComposite().as() ; EXPECT_TRUE(point.isNear(Point(0.0, 0.0, -3.0), Real::Epsilon())) ; @@ -1320,9 +1320,9 @@ TEST (Library_Mathematics_Geometry_3D_Objects_Ellipsoid, IntersectionWith_Ray) EXPECT_TRUE(intersection.isDefined()) ; - ASSERT_TRUE(intersection.is()) ; + ASSERT_TRUE(intersection.accessComposite().is()) ; - const Point point = intersection.as() ; + const Point point = intersection.accessComposite().as() ; EXPECT_TRUE(point.isNear(Point(1.0, 0.0, 0.0), Real::Epsilon())) ; @@ -1337,9 +1337,9 @@ TEST (Library_Mathematics_Geometry_3D_Objects_Ellipsoid, IntersectionWith_Ray) EXPECT_TRUE(intersection.isDefined()) ; - ASSERT_TRUE(intersection.is()) ; + ASSERT_TRUE(intersection.accessComposite().is()) ; - const Point point = intersection.as() ; + const Point point = intersection.accessComposite().as() ; EXPECT_TRUE(point.isNear(Point(0.0, 0.0, -3.0), Real::Epsilon())) ; @@ -1365,9 +1365,9 @@ TEST (Library_Mathematics_Geometry_3D_Objects_Ellipsoid, IntersectionWith_Ray) EXPECT_TRUE(intersection.isDefined()) ; - ASSERT_TRUE(intersection.is()) ; + ASSERT_TRUE(intersection.accessComposite().is()) ; - const Point point = intersection.as() ; + const Point point = intersection.accessComposite().as() ; EXPECT_TRUE(point.isNear(Point(0.0, 0.0, +3.0), Real::Epsilon())) ; @@ -1382,9 +1382,9 @@ TEST (Library_Mathematics_Geometry_3D_Objects_Ellipsoid, IntersectionWith_Ray) EXPECT_TRUE(intersection.isDefined()) ; - ASSERT_TRUE(intersection.is()) ; + ASSERT_TRUE(intersection.accessComposite().is()) ; - const Point point = intersection.as() ; + const Point point = intersection.accessComposite().as() ; EXPECT_TRUE(point.isNear(Point(0.0, 0.0, -3.0), Real::Epsilon())) ; @@ -1429,9 +1429,9 @@ TEST (Library_Mathematics_Geometry_3D_Objects_Ellipsoid, IntersectionWith_Segmen EXPECT_TRUE(intersection.isDefined()) ; - ASSERT_TRUE(intersection.is()) ; + ASSERT_TRUE(intersection.accessComposite().is()) ; - const Point point = intersection.as() ; + const Point point = intersection.accessComposite().as() ; EXPECT_TRUE(point.isNear(Point(1.0, 0.0, 0.0), Real::Epsilon())) ; @@ -1446,9 +1446,9 @@ TEST (Library_Mathematics_Geometry_3D_Objects_Ellipsoid, IntersectionWith_Segmen EXPECT_TRUE(intersection.isDefined()) ; - ASSERT_TRUE(intersection.is()) ; + ASSERT_TRUE(intersection.accessComposite().is()) ; - const Point point = intersection.as() ; + const Point point = intersection.accessComposite().as() ; EXPECT_TRUE(point.isNear(Point(1.0, 0.0, 0.0), Real::Epsilon())) ; @@ -1463,9 +1463,9 @@ TEST (Library_Mathematics_Geometry_3D_Objects_Ellipsoid, IntersectionWith_Segmen EXPECT_TRUE(intersection.isDefined()) ; - ASSERT_TRUE(intersection.is()) ; + ASSERT_TRUE(intersection.accessComposite().is()) ; - const Point point = intersection.as() ; + const Point point = intersection.accessComposite().as() ; EXPECT_TRUE(point.isNear(Point(-1.0, 0.0, 0.0), Real::Epsilon())) ; @@ -1480,9 +1480,9 @@ TEST (Library_Mathematics_Geometry_3D_Objects_Ellipsoid, IntersectionWith_Segmen EXPECT_TRUE(intersection.isDefined()) ; - ASSERT_TRUE(intersection.is()) ; + ASSERT_TRUE(intersection.accessComposite().is()) ; - const Point point = intersection.as() ; + const Point point = intersection.accessComposite().as() ; EXPECT_TRUE(point.isNear(Point(-1.0, 0.0, 0.0), Real::Epsilon())) ; @@ -1497,9 +1497,9 @@ TEST (Library_Mathematics_Geometry_3D_Objects_Ellipsoid, IntersectionWith_Segmen EXPECT_TRUE(intersection.isDefined()) ; - ASSERT_TRUE(intersection.is()) ; + ASSERT_TRUE(intersection.accessComposite().is()) ; - const PointSet pointSet = intersection.as() ; + const PointSet pointSet = intersection.accessComposite().as() ; EXPECT_EQ(2, pointSet.getSize()) ; @@ -1516,9 +1516,9 @@ TEST (Library_Mathematics_Geometry_3D_Objects_Ellipsoid, IntersectionWith_Segmen EXPECT_TRUE(intersection.isDefined()) ; - ASSERT_TRUE(intersection.is()) ; + ASSERT_TRUE(intersection.accessComposite().is()) ; - const PointSet pointSet = intersection.as() ; + const PointSet pointSet = intersection.accessComposite().as() ; EXPECT_EQ(2, pointSet.getSize()) ; @@ -1535,9 +1535,9 @@ TEST (Library_Mathematics_Geometry_3D_Objects_Ellipsoid, IntersectionWith_Segmen EXPECT_TRUE(intersection.isDefined()) ; - ASSERT_TRUE(intersection.is()) ; + ASSERT_TRUE(intersection.accessComposite().is()) ; - const Point point = intersection.as() ; + const Point point = intersection.accessComposite().as() ; EXPECT_TRUE(point.isNear(Point(0.0, 0.0, +3.0), Real::Epsilon())) ; @@ -1552,9 +1552,9 @@ TEST (Library_Mathematics_Geometry_3D_Objects_Ellipsoid, IntersectionWith_Segmen EXPECT_TRUE(intersection.isDefined()) ; - ASSERT_TRUE(intersection.is()) ; + ASSERT_TRUE(intersection.accessComposite().is()) ; - const Point point = intersection.as() ; + const Point point = intersection.accessComposite().as() ; EXPECT_TRUE(point.isNear(Point(0.0, 0.0, +3.0), Real::Epsilon())) ; diff --git a/test/Library/Mathematics/Geometry/3D/Objects/Pyramid.test.cpp b/test/Library/Mathematics/Geometry/3D/Objects/Pyramid.test.cpp index 5bde32f8..dd813655 100644 --- a/test/Library/Mathematics/Geometry/3D/Objects/Pyramid.test.cpp +++ b/test/Library/Mathematics/Geometry/3D/Objects/Pyramid.test.cpp @@ -281,9 +281,9 @@ TEST (Library_Mathematics_Geometry_3D_Objects_Pyramid, IntersectionWith_Ellipsoi EXPECT_TRUE(intersection.isDefined()) ; EXPECT_FALSE(intersection.isEmpty()) ; - EXPECT_TRUE(intersection.is()) ; + EXPECT_TRUE(intersection.accessComposite().is()) ; - const LineString intersectionLineString = intersection.as() ; + const LineString intersectionLineString = intersection.accessComposite().as() ; EXPECT_EQ(8, intersectionLineString.getPointCount()) ; diff --git a/tools/.env b/tools/.env index c1760be6..74b067c4 100644 --- a/tools/.env +++ b/tools/.env @@ -38,7 +38,7 @@ fi repository_name="openspacecollective" # image_version="$(echo ${version} | head -c 5)" -image_version="0.1.9" +image_version="0.1.10" image_name="${repository_name}/${project_name}:${image_version}" diff --git a/tools/development/docker/Dockerfile b/tools/development/docker/Dockerfile index 6cd8227f..ab32ce7b 100644 --- a/tools/development/docker/Dockerfile +++ b/tools/development/docker/Dockerfile @@ -61,12 +61,12 @@ RUN mkdir /tmp/geometric-tools-engine \ && rm -rf /tmp/geometric-tools-engine \ && popd > /dev/null -## Library :: Core [0.1.12] +## Library :: Core [0.1.13] RUN mkdir -p /tmp/library-core \ && pushd /tmp/library-core > /dev/null \ - && wget --quiet https://github.com/open-space-collective/library-core/releases/download/0.1.12/library-core-0.1.12-1.x86_64-runtime.rpm \ - && wget --quiet https://github.com/open-space-collective/library-core/releases/download/0.1.12/library-core-0.1.12-1.x86_64-devel.rpm \ + && wget --quiet https://github.com/open-space-collective/library-core/releases/download/0.1.13/library-core-0.1.13-1.x86_64-runtime.rpm \ + && wget --quiet https://github.com/open-space-collective/library-core/releases/download/0.1.13/library-core-0.1.13-1.x86_64-devel.rpm \ && dnf install -y ./*.rpm \ && rm -rf /tmp/library-core \ && popd > /dev/null