Skip to content

Commit

Permalink
[feature] Add Composite 3D geometry, update Intersection
Browse files Browse the repository at this point in the history
  • Loading branch information
lucas-bremond committed Sep 11, 2018
1 parent 48856ab commit 821b9b3
Show file tree
Hide file tree
Showing 18 changed files with 2,206 additions and 177 deletions.
72 changes: 37 additions & 35 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,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 <class Type>
bool is ( ) const
{
return (!objects_.isEmpty()) && (dynamic_cast<const Type*>(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 <class Type>
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<const Type*>(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
///
Expand Down Expand Up @@ -242,7 +244,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 821b9b3

Please sign in to comment.