1
0
Fork 0
mirror of https://github.com/bolero-MURAKAMI/Sprout synced 2024-11-12 21:09:01 +00:00
Sprout/sprout/darkroom/intersects/intersection.hpp

126 lines
4.4 KiB
C++
Raw Normal View History

2013-08-08 09:54:33 +00:00
/*=============================================================================
Copyright (c) 2011-2017 Bolero MURAKAMI
2013-08-08 09:54:33 +00:00
https://github.com/bolero-MURAKAMI/Sprout
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
=============================================================================*/
2011-11-26 06:20:35 +00:00
#ifndef SPROUT_DARKROOM_INTERSECTS_INTERSECTION_HPP
#define SPROUT_DARKROOM_INTERSECTS_INTERSECTION_HPP
#include <type_traits>
2011-11-26 06:20:35 +00:00
#include <sprout/config.hpp>
#include <sprout/tuple/tuple.hpp>
#include <sprout/utility/forward.hpp>
#include <sprout/type_traits/enabler_if.hpp>
2011-11-26 06:20:35 +00:00
#include <sprout/darkroom/access/access.hpp>
#include <sprout/darkroom/coords/vector.hpp>
#include <sprout/darkroom/materials/material.hpp>
namespace sprout {
namespace darkroom {
namespace intersects {
//
// intersection
//
typedef sprout::tuples::tuple<
bool,
double,
sprout::darkroom::coords::vector3d_t,
sprout::darkroom::coords::vector3d_t,
sprout::darkroom::materials::material,
bool
> intersection;
//
// has_is_from_inside
//
template<typename T>
struct has_is_from_inside
2014-12-10 10:54:12 +00:00
: public sprout::bool_constant<(sprout::darkroom::access::size<T>::value >= 6)>
{};
2011-11-26 06:20:35 +00:00
//
// does_intersect
// distance
// point_of_intersection
// normal
// material
// is_from_inside
2011-11-26 06:20:35 +00:00
//
template<typename T>
2012-10-05 15:58:56 +00:00
inline SPROUT_CONSTEXPR auto
does_intersect(T&& t)
2014-08-14 13:55:49 +00:00
SPROUT_NOEXCEPT_IF_EXPR(sprout::darkroom::access::get<0>(SPROUT_FORWARD(T, t)))
-> decltype(sprout::darkroom::access::get<0>(SPROUT_FORWARD(T, t)))
2011-11-26 06:20:35 +00:00
{
return sprout::darkroom::access::get<0>(SPROUT_FORWARD(T, t));
2011-11-26 06:20:35 +00:00
}
template<typename T>
2012-10-05 15:58:56 +00:00
inline SPROUT_CONSTEXPR auto
distance(T&& t)
2014-08-14 13:55:49 +00:00
SPROUT_NOEXCEPT_IF_EXPR(sprout::darkroom::access::get<1>(SPROUT_FORWARD(T, t)))
-> decltype(sprout::darkroom::access::get<1>(SPROUT_FORWARD(T, t)))
2011-11-26 06:20:35 +00:00
{
return sprout::darkroom::access::get<1>(SPROUT_FORWARD(T, t));
2011-11-26 06:20:35 +00:00
}
template<typename T>
2012-10-05 15:58:56 +00:00
inline SPROUT_CONSTEXPR auto
point_of_intersection(T&& t)
2014-08-14 13:55:49 +00:00
SPROUT_NOEXCEPT_IF_EXPR(sprout::darkroom::access::get<2>(SPROUT_FORWARD(T, t)))
-> decltype(sprout::darkroom::access::get<2>(SPROUT_FORWARD(T, t)))
2011-11-26 06:20:35 +00:00
{
return sprout::darkroom::access::get<2>(SPROUT_FORWARD(T, t));
2011-11-26 06:20:35 +00:00
}
template<typename T>
2012-10-05 15:58:56 +00:00
inline SPROUT_CONSTEXPR auto
normal(T&& t)
2014-08-14 13:55:49 +00:00
SPROUT_NOEXCEPT_IF_EXPR(sprout::darkroom::access::get<3>(SPROUT_FORWARD(T, t)))
-> decltype(sprout::darkroom::access::get<3>(SPROUT_FORWARD(T, t)))
2011-11-26 06:20:35 +00:00
{
return sprout::darkroom::access::get<3>(SPROUT_FORWARD(T, t));
2011-11-26 06:20:35 +00:00
}
template<typename T>
2012-10-05 15:58:56 +00:00
inline SPROUT_CONSTEXPR auto
material(T&& t)
2014-08-14 13:55:49 +00:00
SPROUT_NOEXCEPT_IF_EXPR(sprout::darkroom::access::get<4>(SPROUT_FORWARD(T, t)))
-> decltype(sprout::darkroom::access::get<4>(SPROUT_FORWARD(T, t)))
2011-11-26 06:20:35 +00:00
{
return sprout::darkroom::access::get<4>(SPROUT_FORWARD(T, t));
2011-11-26 06:20:35 +00:00
}
template<
typename T,
typename sprout::enabler_if<sprout::darkroom::intersects::has_is_from_inside<typename std::decay<T>::type>::value>::type = sprout::enabler
>
inline SPROUT_CONSTEXPR auto
is_from_inside(T&& t)
2014-08-14 13:55:49 +00:00
SPROUT_NOEXCEPT_IF_EXPR(sprout::darkroom::access::get<5>(SPROUT_FORWARD(T, t)))
-> decltype(sprout::darkroom::access::get<5>(SPROUT_FORWARD(T, t)))
{
return sprout::darkroom::access::get<5>(SPROUT_FORWARD(T, t));
}
template<
typename T,
typename sprout::enabler_if<!sprout::darkroom::intersects::has_is_from_inside<typename std::decay<T>::type>::value>::type = sprout::enabler
>
inline SPROUT_CONSTEXPR typename sprout::darkroom::access::element<5, sprout::darkroom::intersects::intersection>::type
is_from_inside(T&&)
2014-08-14 13:55:49 +00:00
SPROUT_NOEXCEPT_IF_EXPR((typename sprout::darkroom::access::element<5, sprout::darkroom::intersects::intersection>::type()))
{
return typename sprout::darkroom::access::element<5, sprout::darkroom::intersects::intersection>::type();
}
2011-11-26 06:20:35 +00:00
//
// make_intersection
//
template<typename... Elements>
inline SPROUT_CONSTEXPR sprout::tuples::tuple<Elements...>
2013-12-04 14:38:33 +00:00
make_intersection(Elements const&... elems) {
return sprout::tuples::make_tuple(elems...);
2011-11-26 06:20:35 +00:00
}
} // namespace intersects
} // namespace darkroom
} // namespace sprout
#endif // #ifndef SPROUT_DARKROOM_INTERSECTS_INTERSECTION_HPP