transforms.h revision 00f9ca0b3aa57e09f3c3f3632c5427fc03499df5
/**
* @file
* @brief Affine transformation classes
*//*
* Authors:
* ? <?@?.?>
* Krzysztof KosiĆski <tweenk.pl@gmail.com>
* Johan Engelen
*
* Copyright ?-2012 Authors
*
* modify it either under the terms of the GNU Lesser General Public
* License version 2.1 as published by the Free Software Foundation
* (the "LGPL") or, at your option, under the terms of the Mozilla
* Public License Version 1.1 (the "MPL"). If you do not alter this
* notice, a recipient may use your version of this file under either
* the MPL or the LGPL.
*
* You should have received a copy of the LGPL along with this library
* in the file COPYING-LGPL-2.1; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* You should have received a copy of the MPL along with this library
* in the file COPYING-MPL-1.1
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
* OF ANY KIND, either express or implied. See the LGPL or the MPL for
* the specific language governing rights and limitations.
*/
#ifndef LIB2GEOM_SEEN_TRANSFORMS_H
#define LIB2GEOM_SEEN_TRANSFORMS_H
#include <cmath>
/** @brief Type requirements for transforms.
* @ingroup Concepts */
struct TransformConcept {
T t, t2;
Affine m;
Point p;
bool bool_;
void constraints() {
m = t; //implicit conversion
m *= t;
m = m * t;
m = t * m;
p *= t;
p = p * t;
t *= t;
t = t * t;
t = pow(t, 3);
bool_ = (t == t);
bool_ = (t != t);
t = T::identity();
t = t.inverse();
}
};
/** @brief Base template for transforms.
* This class is an implementation detail and should not be used directly. */
: boost::equality_comparable< T
, boost::multipliable< T
> >
{
}
};
/** @brief Integer exponentiation for transforms.
* Negative exponents will yield the corresponding power of the inverse. This function
* can also be applied to matrices.
* @param t Affine or transform to exponantiate
* @param n Exponent
* @return \f$A^n\f$ if @a n is positive, \f$(A^{-1})^n\f$ if negative, identity if zero.
* @ingroup Transforms */
T pow(T const &t, int n) {
if (n == 0) return T::identity();
T x(n < 0 ? t.inverse() : t);
if (n < 0) n = -n;
while ( n ) { // binary exponentiation - fast
if ( n & 1 ) { result *= x; --n; }
x *= x; n /= 2;
}
return result;
}
/** @brief Translation by a vector.
* @ingroup Transforms */
{
/// Create a translation that doesn't do anything.
/// Construct a translation from its vector.
/// Construct a translation from its coordinates.
/// Get the inverse translation.
/// Get a translation that doesn't do anything.
};
}
/** @brief Scaling from the origin.
* During scaling, the point (0,0) will not move. To obtain a scale with a different
* invariant point, combine with translation to the origin and back.
* @ingroup Transforms */
{
/// Create a scaling that doesn't do anything.
/// Create a scaling from two scaling factors given as coordinates of a point.
/// Create a scaling from two scaling factors.
/// Create an uniform scaling from a single scaling factor.
//TODO: should we keep these mutators? add them to the other transforms?
};
}
/** @brief Rotation around the origin.
* Combine with translations to the origin and back to get a rotation around a different point.
* @ingroup Transforms */
{
/// Construct a zero-degree rotation.
/** @brief Construct a rotation from its angle in radians.
* Positive arguments correspond to counter-clockwise rotations (if Y grows upwards). */
/// Construct a rotation from its characteristic vector.
/// Construct a rotation from the coordinates of its characteristic vector.
/** @brief Get the characteristic vector of the rotation.
* @return A vector that would be obtained by applying this transform to the X versor. */
Rotate r;
return r;
}
/// @brief Get a zero-degree rotation.
/** @brief Construct a rotation from its angle in degrees.
* Positive arguments correspond to clockwise rotations if Y grows downwards. */
}
};
}
/** @brief Common base for shearing transforms.
* This class is an implementation detail and should not be used directly.
* @ingroup Transforms */
: public TransformOperations< S >
{
Coord f;
bool operator==(S const &s) const { return f == s.f; }
};
/** @brief Horizontal shearing.
* Points on the X axis will not move. Combine with translations to get a shear
* with a different invariant line.
* @ingroup Transforms */
{
};
}
/** @brief Vertical shearing.
* Points on the Y axis will not move. Combine with translations to get a shear
* with a different invariant line.
* @ingroup Transforms */
{
};
}
/** @brief Combination of a translation and uniform scale.
* The translation part is applied first, then the result is scaled from the new origin.
* This way when the class is used to accumulate a zoom transform, trans always points
* to the new origin in original coordinates.
* @ingroup Transforms */
{
/// Construct a zoom from a scaling factor.
/// Construct a zoom from a translation.
/// Construct a zoom from a scaling factor and a translation.
return ret;
}
return *this;
}
};
}
/** @brief Specialization of exponentiation for Scale.
* @relates Scale */
template<>
return ret;
}
/** @brief Specialization of exponentiation for Translate.
* @relates Translate */
template<>
return ret;
}
/** @brief Reflects objects about line.
* The line, defined by a vector along the line and a point on it, acts as a mirror.
* @ingroup Transforms
* @see Line::reflection()
*/
//TODO: decomposition of Affine into some finite combination of the above classes
} // end namespace Geom
#endif // LIB2GEOM_SEEN_TRANSFORMS_H
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :