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

fix sinusoidal

This commit is contained in:
bolero-MURAKAMI 2012-05-01 11:32:48 +09:00
parent bafd1004dd
commit 51a7a4c86c
4 changed files with 55 additions and 17 deletions

View file

@ -36,12 +36,14 @@ namespace sprout {
difference_type index_;
value_type frequency_;
value_type amplitude_;
value_type phase_;
value_type d_;
private:
explicit SPROUT_CONSTEXPR sinusoid_iterator(sinusoid_iterator const& other, difference_type index)
: index_(index)
, frequency_(other.frequency_)
, amplitude_(other.amplitude_)
, phase_(other.phase_)
, d_(other.d_)
{}
public:
@ -49,17 +51,20 @@ namespace sprout {
: index_()
, frequency_(1)
, amplitude_(1)
, phase_(0)
, d_(value_type(2) * sprout::math::pi<value_type>())
{}
sinusoid_iterator(sinusoid_iterator const&) = default;
explicit SPROUT_CONSTEXPR sinusoid_iterator(
difference_type index,
value_type const& frequency = 1,
value_type const& amplitude = 1
value_type const& amplitude = 1,
value_type const& phase = 0
)
: index_(index)
, frequency_(frequency)
, amplitude_(amplitude)
, phase_(phase)
, d_(value_type(2) * sprout::math::pi<value_type>() * frequency)
{}
template<typename U>
@ -67,6 +72,7 @@ namespace sprout {
: index_(it.index_)
, frequency_(it.frequency_)
, amplitude_(it.amplitude_)
, phase_(it.phase_)
, d_(it.d_)
{}
template<typename U>
@ -84,6 +90,9 @@ namespace sprout {
SPROUT_CONSTEXPR value_type const& amplitude() const {
return amplitude_;
}
SPROUT_CONSTEXPR value_type const& phase() const {
return phase_;
}
SPROUT_CONSTEXPR reference operator*() const {
using std::sin;
return amplitude_ * sin(d_ * value_type(index_));
@ -137,9 +146,10 @@ namespace sprout {
}
void swap(sinusoid_iterator& other) {
using std::swap;
swap(index_, other.index_);
swap(frequency_, other.frequency_);
swap(amplitude_, other.amplitude_);
swap(index_, other.index_);
swap(phase_, other.phase_);
swap(d_, other.d_);
}
};

View file

@ -16,11 +16,12 @@ namespace sprout {
Container const& cont,
typename sprout::container_traits<Container>::value_type const& frequency,
typename sprout::container_traits<Container>::value_type const& amplitude,
typename sprout::container_traits<Container>::value_type const& phase,
typename sprout::container_traits<Container>::difference_type offset
)
{
return sprout::sub_copy(
sprout::get_internal(sprout::fixed::sinusoid(cont, frequency, amplitude)),
sprout::get_internal(sprout::fixed::sinusoid(cont, frequency, amplitude, phase)),
offset,
offset + sprout::size(cont)
);
@ -33,7 +34,8 @@ namespace sprout {
inline SPROUT_CONSTEXPR typename sprout::fit::result_of::algorithm<Container>::type sinusoid(
Container const& cont,
typename sprout::container_traits<Container>::value_type const& frequency = 1,
typename sprout::container_traits<Container>::value_type const& amplitude = 1
typename sprout::container_traits<Container>::value_type const& amplitude = 1,
typename sprout::container_traits<Container>::value_type const& phase = 0
)
{
return sprout::fit::detail::sinusoid_impl(cont, frequency, amplitude, sprout::internal_begin_offset(cont));

View file

@ -19,6 +19,7 @@ namespace sprout {
Container const& cont,
typename sprout::container_traits<Container>::value_type const& d,
typename sprout::container_traits<Container>::value_type const& amplitude,
typename sprout::container_traits<Container>::value_type const& phase,
sprout::index_tuple<Indexes...>,
typename sprout::container_traits<Container>::difference_type offset,
typename sprout::container_traits<Container>::size_type size
@ -30,7 +31,7 @@ namespace sprout {
cont,
size,
(Indexes >= offset && Indexes < offset + size
? amplitude * sin(d * value_type(Indexes))
? amplitude * sin(d * value_type(Indexes) + phase)
: *sprout::next(sprout::internal_begin(cont), Indexes)
)...
);
@ -40,7 +41,8 @@ namespace sprout {
sinusoid(
Container const& cont,
typename sprout::container_traits<Container>::value_type const& frequency,
typename sprout::container_traits<Container>::value_type const& amplitude
typename sprout::container_traits<Container>::value_type const& amplitude,
typename sprout::container_traits<Container>::value_type const& phase
)
{
typedef typename sprout::container_traits<Container>::value_type value_type;
@ -48,6 +50,7 @@ namespace sprout {
cont,
value_type(2) * sprout::math::pi<value_type>() * frequency / value_type(sprout::size(cont)),
amplitude,
phase,
sprout::container_indexes<Container>::make(),
sprout::internal_begin_offset(cont),
sprout::size(cont)
@ -62,10 +65,11 @@ namespace sprout {
sinusoid(
Container const& cont,
typename sprout::container_traits<Container>::value_type const& frequency = 1,
typename sprout::container_traits<Container>::value_type const& amplitude = 1
typename sprout::container_traits<Container>::value_type const& amplitude = 1,
typename sprout::container_traits<Container>::value_type const& phase = 0
)
{
return sprout::fixed::detail::sinusoid(cont, frequency, amplitude);
return sprout::fixed::detail::sinusoid(cont, frequency, amplitude, phase);
}
} // namespace fixed

View file

@ -39,13 +39,23 @@ namespace sprout {
explicit SPROUT_CONSTEXPR sinusoidal_range(
range_type& range,
value_type const& frequency = 1,
value_type const& amplitude = 1
value_type const& amplitude = 1,
value_type const& phase = 0
)
: base_type(
iterator(0, frequency, amplitude),
iterator(sprout::size(range), frequency, amplitude)
iterator(0, frequency, amplitude, phase),
iterator(sprout::size(range), frequency, amplitude, phase)
)
{}
SPROUT_CONSTEXPR value_type const& frequency() const {
return base_type::begin().frequency();
}
SPROUT_CONSTEXPR value_type const& amplitude() const {
return base_type::begin().amplitude();
}
SPROUT_CONSTEXPR value_type const& phase() const {
return base_type::begin().phase();
}
};
template<typename Value>
@ -66,13 +76,23 @@ namespace sprout {
sinusoidal_range(sinusoidal_range const&) = default;
explicit SPROUT_CONSTEXPR sinusoidal_range(
value_type const& frequency = 1,
value_type const& amplitude = 1
value_type const& amplitude = 1,
value_type const& phase = 0
)
: base_type(
iterator(0, frequency, amplitude),
iterator(-1, frequency, amplitude)
iterator(0, frequency, amplitude, phase),
iterator(-1, frequency, amplitude, phase)
)
{}
SPROUT_CONSTEXPR value_type const& frequency() const {
return base_type::begin().frequency();
}
SPROUT_CONSTEXPR value_type const& amplitude() const {
return base_type::begin().amplitude();
}
SPROUT_CONSTEXPR value_type const& phase() const {
return base_type::begin().phase();
}
};
//
@ -84,10 +104,11 @@ namespace sprout {
SPROUT_CONSTEXPR sprout::adaptors::sinusoidal_range<Value>
operator()(
Value const& frequency = 1,
Value const& amplitude = 1
Value const& amplitude = 1,
Value const& phase = 0
)
{
return sprout::adaptors::sinusoidal_range<Value>(frequency, amplitude);
return sprout::adaptors::sinusoidal_range<Value>(frequency, amplitude, phase);
}
};
@ -113,7 +134,8 @@ namespace sprout {
>(
sprout::lvalue_forward<Range>(lhs),
rhs.frequency(),
rhs.amplitude()
rhs.amplitude(),
rhs.phase()
);
}
} // namespace adaptors