Skip to content

Commit

Permalink
Merge pull request #13 from open-space-collective/dev@lucas
Browse files Browse the repository at this point in the history
Dev@lucas
  • Loading branch information
lucas-bremond authored Sep 11, 2018
2 parents e743e60 + 0fd968b commit bee31c3
Show file tree
Hide file tree
Showing 39 changed files with 5,117 additions and 430 deletions.
78 changes: 59 additions & 19 deletions include/Library/Mathematics/Geometry/3D/Intersection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,26 @@

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#include <Library/Mathematics/Geometry/3D/Objects/Composite.hpp>
#include <Library/Mathematics/Geometry/3D/Objects/Pyramid.hpp>
#include <Library/Mathematics/Geometry/3D/Objects/Ellipsoid.hpp>
#include <Library/Mathematics/Geometry/3D/Objects/Cuboid.hpp>
#include <Library/Mathematics/Geometry/3D/Objects/Sphere.hpp>
#include <Library/Mathematics/Geometry/3D/Objects/Plane.hpp>
#include <Library/Mathematics/Geometry/3D/Objects/Polygon.hpp>
#include <Library/Mathematics/Geometry/3D/Objects/LineString.hpp>
#include <Library/Mathematics/Geometry/3D/Objects/Segment.hpp>
#include <Library/Mathematics/Geometry/3D/Objects/Ray.hpp>
#include <Library/Mathematics/Geometry/3D/Objects/LineString.hpp>
#include <Library/Mathematics/Geometry/3D/Objects/Line.hpp>
#include <Library/Mathematics/Geometry/3D/Objects/PointSet.hpp>
#include <Library/Mathematics/Geometry/3D/Objects/Point.hpp>
#include <Library/Mathematics/Geometry/3D/Object.hpp>

#include <Library/Core/Containers/Array.hpp>
#include <Library/Core/Types/Size.hpp>
#include <Library/Core/Types/Index.hpp>
#include <Library/Core/Types/Unique.hpp>
#include <Library/Core/Error.hpp>

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Expand All @@ -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 ;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Expand All @@ -61,12 +71,15 @@ class Intersection
Point,
PointSet,
Line,
LineString,
Ray,
Segment,
LineString,
Polygon,
Plane,
Cuboid,
Sphere,
Ellipsoid,
Pyramid,
Complex

} ;
Expand All @@ -75,7 +88,7 @@ class Intersection
///
/// @param [in] anObjectArray An array of objects

Intersection ( const Array<Unique<Object>>& anObjectArray ) ;
Intersection ( Array<Unique<Object>>&& anObjectArray ) ;

/// @brief Copy constructor
///
Expand Down Expand Up @@ -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
Expand All @@ -142,45 +164,63 @@ class Intersection

bool isEmpty ( ) const ;

/// @brief Check if intersection is complex
///
/// A complex intersection contains more than one object.
///
/// @return True if intersection is complex

bool isComplex ( ) const ;

/// @brief Returns true if intersection can be converted to underlying object
///
/// Only valid if the intersection only contains one object.
///
/// @return True if intersection can be converted to underlying object

template <class Type>
bool is ( ) const
{
return (!objects_.isEmpty()) && (dynamic_cast<const Type*>(objects_.accessFirst().get()) != nullptr) ;
}

/// @brief Get intersection type
///
/// @return Intersection type
if (!this->isDefined())
{
throw library::core::error::runtime::Undefined("Intersection") ;
}

return composite_.is<Type>() ;

Intersection::Type getType ( ) const ;
}

/// @brief Access intersection as its underlying object
///
/// Only valid if the intersection only contains one object.
///
/// @return Reference to underlying object

template <class Type>
const Type& as ( ) const
{

if (objects_.isEmpty())
if (!this->isDefined())
{
throw library::core::error::RuntimeError("Cannot convert intersection: it is empty.") ;
throw library::core::error::runtime::Undefined("Intersection") ;
}

const Type* objectPtr = dynamic_cast<const Type*>(objects_.accessFirst().get()) ;
return composite_.as<Type>() ;

if (objectPtr == nullptr)
{
throw library::core::error::RuntimeError("Cannot convert intersection: wrong type.") ;
}
}

return *objectPtr ;
/// @brief Access composite object
///
/// @return Reference to composite object

}
const Composite& accessComposite ( ) const ;

/// @brief Get intersection type
///
/// @return Intersection type

Intersection::Type getType ( ) const ;

/// @brief Constructs an undefined intersection
///
Expand Down Expand Up @@ -242,7 +282,7 @@ class Intersection

Intersection::Type type_ ;

Array<Unique<Object>> objects_ ;
Composite composite_ ;

Intersection ( ) ;

Expand Down
33 changes: 32 additions & 1 deletion include/Library/Mathematics/Geometry/3D/Object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#include <Library/Mathematics/Geometry/3D/Transformations/Rotations/Quaternion.hpp>
#include <Library/Mathematics/Objects/Vector.hpp>

#include <Library/Core/Error.hpp>

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

namespace library
Expand Down Expand Up @@ -45,7 +47,7 @@ class Object

public:

/// @brief Default constructor
/// @brief Default constructor (default)

Object ( ) = default ;

Expand Down Expand Up @@ -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 <class Type>
bool is ( ) const
{
return dynamic_cast<const Type*>(this) != nullptr ;
}

/// @brief Check if object intersects another object
///
/// @code
Expand All @@ -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 <class Type>
const Type& as ( ) const
{

const Type* objectPtr = dynamic_cast<const Type*>(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
Expand Down
Loading

0 comments on commit bee31c3

Please sign in to comment.