transforms.cpp revision 4115d2a7efa05a72856652c38e52105903318912
d37634d73670180f99a3e0ea583621373d90ec4fJohan Engelen * @brief Affine transformation classes
d37634d73670180f99a3e0ea583621373d90ec4fJohan Engelen * Krzysztof Kosiński <tweenk.pl@gmail.com>
4115d2a7efa05a72856652c38e52105903318912Johan Engelen * Johan Engelen
4115d2a7efa05a72856652c38e52105903318912Johan Engelen * Copyright ?-2012 Authors
d37634d73670180f99a3e0ea583621373d90ec4fJohan Engelen * This library is free software; you can redistribute it and/or
d37634d73670180f99a3e0ea583621373d90ec4fJohan Engelen * modify it either under the terms of the GNU Lesser General Public
d37634d73670180f99a3e0ea583621373d90ec4fJohan Engelen * License version 2.1 as published by the Free Software Foundation
d37634d73670180f99a3e0ea583621373d90ec4fJohan Engelen * (the "LGPL") or, at your option, under the terms of the Mozilla
d37634d73670180f99a3e0ea583621373d90ec4fJohan Engelen * Public License Version 1.1 (the "MPL"). If you do not alter this
d37634d73670180f99a3e0ea583621373d90ec4fJohan Engelen * notice, a recipient may use your version of this file under either
d37634d73670180f99a3e0ea583621373d90ec4fJohan Engelen * the MPL or the LGPL.
d37634d73670180f99a3e0ea583621373d90ec4fJohan Engelen * You should have received a copy of the LGPL along with this library
d37634d73670180f99a3e0ea583621373d90ec4fJohan Engelen * in the file COPYING-LGPL-2.1; if not, write to the Free Software
d37634d73670180f99a3e0ea583621373d90ec4fJohan Engelen * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
d37634d73670180f99a3e0ea583621373d90ec4fJohan Engelen * You should have received a copy of the MPL along with this library
d37634d73670180f99a3e0ea583621373d90ec4fJohan Engelen * in the file COPYING-MPL-1.1
d37634d73670180f99a3e0ea583621373d90ec4fJohan Engelen * The contents of this file are subject to the Mozilla Public License
d37634d73670180f99a3e0ea583621373d90ec4fJohan Engelen * Version 1.1 (the "License"); you may not use this file except in
d37634d73670180f99a3e0ea583621373d90ec4fJohan Engelen * compliance with the License. You may obtain a copy of the License at
d37634d73670180f99a3e0ea583621373d90ec4fJohan Engelen * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
d37634d73670180f99a3e0ea583621373d90ec4fJohan Engelen * OF ANY KIND, either express or implied. See the LGPL or the MPL for
d37634d73670180f99a3e0ea583621373d90ec4fJohan Engelen * the specific language governing rights and limitations.
d6519bf53baba32bd74436ad9c85f1fa2c6b6ae9Krzysztof Kosiński/** @brief Zoom between rectangles.
d6519bf53baba32bd74436ad9c85f1fa2c6b6ae9Krzysztof Kosiński * Given two rectangles, compute a zoom that maps one to the other.
d6519bf53baba32bd74436ad9c85f1fa2c6b6ae9Krzysztof Kosiński * Rectangles are assumed to have the same aspect ratio. */
d6519bf53baba32bd74436ad9c85f1fa2c6b6ae9Krzysztof KosińskiZoom Zoom::map_rect(Rect const &old_r, Rect const &new_r)
d6519bf53baba32bd74436ad9c85f1fa2c6b6ae9Krzysztof Kosiński ret._scale = new_r.width() / old_r.width();
d37634d73670180f99a3e0ea583621373d90ec4fJohan Engelen// Point transformation methods.
d37634d73670180f99a3e0ea583621373d90ec4fJohan Engelen return *this;
d37634d73670180f99a3e0ea583621373d90ec4fJohan Engelen return *this;
d37634d73670180f99a3e0ea583621373d90ec4fJohan Engelen return *this;
d37634d73670180f99a3e0ea583621373d90ec4fJohan Engelen return *this;
d37634d73670180f99a3e0ea583621373d90ec4fJohan Engelen return *this;
d37634d73670180f99a3e0ea583621373d90ec4fJohan Engelen// Affine multiplication methods.
d37634d73670180f99a3e0ea583621373d90ec4fJohan Engelen/** @brief Combine this transformation with a translation. */
d37634d73670180f99a3e0ea583621373d90ec4fJohan EngelenAffine &Affine::operator*=(Translate const &t) {
d37634d73670180f99a3e0ea583621373d90ec4fJohan Engelen return *this;
d37634d73670180f99a3e0ea583621373d90ec4fJohan Engelen/** @brief Combine this transformation with scaling. */
d37634d73670180f99a3e0ea583621373d90ec4fJohan Engelen return *this;
d37634d73670180f99a3e0ea583621373d90ec4fJohan Engelen/** @brief Combine this transformation a rotation. */
d37634d73670180f99a3e0ea583621373d90ec4fJohan Engelen // TODO: we just convert the Rotate to an Affine and use the existing operator*=()
d37634d73670180f99a3e0ea583621373d90ec4fJohan Engelen // is there a better way?
d37634d73670180f99a3e0ea583621373d90ec4fJohan Engelen *this *= (Affine) r;
d37634d73670180f99a3e0ea583621373d90ec4fJohan Engelen return *this;
d37634d73670180f99a3e0ea583621373d90ec4fJohan Engelen/** @brief Combine this transformation with horizontal shearing (skew). */
d37634d73670180f99a3e0ea583621373d90ec4fJohan Engelen return *this;
d37634d73670180f99a3e0ea583621373d90ec4fJohan Engelen/** @brief Combine this transformation with vertical shearing (skew). */
d37634d73670180f99a3e0ea583621373d90ec4fJohan Engelen return *this;
d6519bf53baba32bd74436ad9c85f1fa2c6b6ae9Krzysztof KosińskiAffine &Affine::operator*=(Zoom const &z) {
d6519bf53baba32bd74436ad9c85f1fa2c6b6ae9Krzysztof Kosiński _c[4] += z._trans[X]; _c[5] += z._trans[Y];
d37634d73670180f99a3e0ea583621373d90ec4fJohan Engelen// this checks whether the requirements of TransformConcept are satisfied for all transforms.
d37634d73670180f99a3e0ea583621373d90ec4fJohan Engelen// if you add a new transform type, include it here!
d37634d73670180f99a3e0ea583621373d90ec4fJohan Engelen BOOST_CONCEPT_ASSERT((TransformConcept<Translate>));
d37634d73670180f99a3e0ea583621373d90ec4fJohan Engelen BOOST_CONCEPT_ASSERT((TransformConcept<Scale>));
d37634d73670180f99a3e0ea583621373d90ec4fJohan Engelen BOOST_CONCEPT_ASSERT((TransformConcept<Rotate>));
d37634d73670180f99a3e0ea583621373d90ec4fJohan Engelen BOOST_CONCEPT_ASSERT((TransformConcept<HShear>));
d37634d73670180f99a3e0ea583621373d90ec4fJohan Engelen BOOST_CONCEPT_ASSERT((TransformConcept<VShear>));
d6519bf53baba32bd74436ad9c85f1fa2c6b6ae9Krzysztof Kosiński BOOST_CONCEPT_ASSERT((TransformConcept<Zoom>));
d37634d73670180f99a3e0ea583621373d90ec4fJohan Engelen BOOST_CONCEPT_ASSERT((TransformConcept<Affine>)); // Affine is also a transform
d37634d73670180f99a3e0ea583621373d90ec4fJohan Engelen // check inter-transform multiplication
d37634d73670180f99a3e0ea583621373d90ec4fJohan Engelen // notice that the first column is always the same and enumerates all transform types,
d37634d73670180f99a3e0ea583621373d90ec4fJohan Engelen // while the second one changes to each transform type in turn.
d6519bf53baba32bd74436ad9c85f1fa2c6b6ae9Krzysztof Kosiński m = t * t; m = t * s; m = t * r; m = t * h; m = t * v; m = t * z;
d6519bf53baba32bd74436ad9c85f1fa2c6b6ae9Krzysztof Kosiński m = s * t; m = s * s; m = s * r; m = s * h; m = s * v; m = s * z;
d6519bf53baba32bd74436ad9c85f1fa2c6b6ae9Krzysztof Kosiński m = r * t; m = r * s; m = r * r; m = r * h; m = r * v; m = r * z;
d6519bf53baba32bd74436ad9c85f1fa2c6b6ae9Krzysztof Kosiński m = h * t; m = h * s; m = h * r; m = h * h; m = h * v; m = h * z;
d6519bf53baba32bd74436ad9c85f1fa2c6b6ae9Krzysztof Kosiński m = v * t; m = v * s; m = v * r; m = v * h; m = v * v; m = v * z;
d6519bf53baba32bd74436ad9c85f1fa2c6b6ae9Krzysztof Kosiński m = z * t; m = z * s; m = z * r; m = z * h; m = z * v; m = z * z;
4115d2a7efa05a72856652c38e52105903318912Johan EngelenAffine reflection(Point const & vector, Point const & origin) {
4115d2a7efa05a72856652c38e52105903318912Johan Engelen Affine mirror ( vec_norm[X]*vec_norm[X] - vec_norm[Y]*vec_norm[Y], 2 * vec_norm[X] * vec_norm[Y] ,
4115d2a7efa05a72856652c38e52105903318912Johan Engelen 2 * vec_norm[X] * vec_norm[Y], vec_norm[Y]*vec_norm[Y] - vec_norm[X]*vec_norm[X] ,
4115d2a7efa05a72856652c38e52105903318912Johan Engelen return Translate(-origin) * mirror * Translate(origin);
4115d2a7efa05a72856652c38e52105903318912Johan Engelen} // namespace Geom
63267518b4ce196caab66ef8cbdcfc0921206b3djohanengelen Local Variables:
63267518b4ce196caab66ef8cbdcfc0921206b3djohanengelen c-file-style:"stroustrup"
63267518b4ce196caab66ef8cbdcfc0921206b3djohanengelen c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
63267518b4ce196caab66ef8cbdcfc0921206b3djohanengelen indent-tabs-mode:nil
63267518b4ce196caab66ef8cbdcfc0921206b3djohanengelen fill-column:99
a4030d5ca449e7e384bc699cd249ee704faaeab0Chris Morgan// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :