1
0
Fork 0
mirror of https://github.com/bolero-MURAKAMI/Sprout synced 2025-08-03 12:49:50 +00:00

fix darkroom: fix template operator() member-function call -> calcurate() free-function

This commit is contained in:
bolero-MURAKAMI 2013-09-24 15:08:36 +09:00
parent 3cb882ce91
commit dfcb6bcf31
25 changed files with 494 additions and 129 deletions

View file

@ -0,0 +1,49 @@
/*=============================================================================
Copyright (c) 2011-2013 Bolero MURAKAMI
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)
=============================================================================*/
#ifndef SPROUT_DARKROOM_MATERIALS_CALCULATE_HPP
#define SPROUT_DARKROOM_MATERIALS_CALCULATE_HPP
#include <sprout/config.hpp>
#include <sprout/type_traits/identity.hpp>
namespace sprout {
namespace darkroom {
namespace materials {
//
// calculate_result
//
template<typename Image, typename Unit>
struct calculate_result
: public sprout::identity<typename Image::result_type>
{};
template<typename Image, typename Unit>
struct calculate_result<Image const, Unit>
: public sprout::darkroom::materials::calculate_result<Image, Unit>
{};
template<typename Image, typename Unit>
struct calculate_result<Image volatile, Unit>
: public sprout::darkroom::materials::calculate_result<Image, Unit>
{};
template<typename Image, typename Unit>
struct calculate_result<Image const volatile, Unit>
: public sprout::darkroom::materials::calculate_result<Image, Unit>
{};
//
// calculate
//
template<typename Image, typename Unit>
inline SPROUT_CONSTEXPR typename sprout::darkroom::materials::calculate_result<Image, Unit>::type
calculate(Image const& image, Unit const& u, Unit const& v) {
return image(u, v);
}
} // namespace materials
} // namespace darkroom
} // namespace sprout
#endif // #ifndef SPROUT_DARKROOM_MATERIALS_CALCULATE_HPP

View file

@ -13,6 +13,7 @@
#include <sprout/utility/forward.hpp>
#include <sprout/darkroom/access/access.hpp>
#include <sprout/darkroom/colors/rgb.hpp>
#include <sprout/darkroom/materials/calculate.hpp>
namespace sprout {
namespace darkroom {
@ -39,40 +40,19 @@ namespace sprout {
}
//
// calc_color
// calc_reflection
//
template<typename Image, typename Unit>
inline SPROUT_CONSTEXPR auto
calc_color(Image&& t, Unit const& u, Unit const& v)
SPROUT_NOEXCEPT
-> decltype(sprout::forward<Image>(t).template operator()(u, v))
{
return sprout::forward<Image>(t).template operator()(u, v);
}
template<typename Image, typename Unit>
inline SPROUT_CONSTEXPR auto
calc_reflection(Image&& t, Unit const& u, Unit const& v)
SPROUT_NOEXCEPT
-> decltype(sprout::forward<Image>(t).template operator()(u, v))
{
return sprout::forward<Image>(t).template operator()(u, v);
}
//
// calc_material
// calculate_material
//
template<typename Material, typename Unit>
inline SPROUT_CONSTEXPR auto
calc_material(Material const& mat, Unit const& u, Unit const& v)
calculate_material(Material const& mat, Unit const& u, Unit const& v)
-> decltype(sprout::tuples::make_tuple(
sprout::darkroom::materials::calc_color(sprout::darkroom::materials::color(mat), u, v),
sprout::darkroom::materials::calc_reflection(sprout::darkroom::materials::reflection(mat), u, v)
sprout::darkroom::materials::calculate(sprout::darkroom::materials::color(mat), u, v),
sprout::darkroom::materials::calculate(sprout::darkroom::materials::reflection(mat), u, v)
))
{
return sprout::tuples::make_tuple(
sprout::darkroom::materials::calc_color(sprout::darkroom::materials::color(mat), u, v),
sprout::darkroom::materials::calc_reflection(sprout::darkroom::materials::reflection(mat), u, v)
sprout::darkroom::materials::calculate(sprout::darkroom::materials::color(mat), u, v),
sprout::darkroom::materials::calculate(sprout::darkroom::materials::reflection(mat), u, v)
);
}

View file

@ -31,7 +31,7 @@ namespace sprout {
private:
template<typename Unit>
SPROUT_CONSTEXPR result_type
calc_1(Unit const& u, Unit const& v) const {
calculate_1(Unit const& u, Unit const& v) const {
return (u >= 0 && v >= 0) || (u < 0 && v < 0) ? elem1_ : elem2_;
}
public:
@ -43,7 +43,7 @@ namespace sprout {
template<typename Unit>
SPROUT_CONSTEXPR result_type
operator()(Unit const& u, Unit const& v) const {
return calc_1(
return calculate_1(
(u < 0
? scale_ + sprout::fmod(u, scale_)
: sprout::fmod(u, scale_)

View file

@ -92,12 +92,12 @@ namespace sprout {
}
template<typename Unit>
SPROUT_CONSTEXPR result_type
calc_nearest(Unit const& x, Unit const& y) const {
calculate_nearest(Unit const& x, Unit const& y) const {
return get_color(x, y);
}
template<typename Unit>
SPROUT_CONSTEXPR result_type
calc_bilinear_1(
calculate_bilinear_1(
Unit const& x, Unit const& x0,
Unit const& y, Unit const& y0
) const
@ -110,8 +110,8 @@ namespace sprout {
}
template<typename Unit>
SPROUT_CONSTEXPR result_type
calc_bilinear(Unit const& x, Unit const& y) const {
return calc_bilinear_1(
calculate_bilinear(Unit const& x, Unit const& y) const {
return calculate_bilinear_1(
x, sprout::floor(x),
y, sprout::floor(y)
);
@ -119,8 +119,8 @@ namespace sprout {
template<typename Unit>
SPROUT_CONSTEXPR result_type
calc(Unit const& x, Unit const& y) const {
return is_nearest() ? calc_nearest(x, y)
: calc_bilinear(x, y)
return is_nearest() ? calculate_nearest(x, y)
: calculate_bilinear(x, y)
;
}
public: