cheshirekow  v0.1.0
inversion.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 Josh Bialkowski (jbialk@mit.edu)
3  *
4  * This file is part of mpblocks.
5  *
6  * mpblocks is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * mpblocks is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with Fontconfigmm. If not, see <http://www.gnu.org/licenses/>.
18  */
25 #ifndef MPBLOCKS_BROWN79_INVERSION_HPP_
26 #define MPBLOCKS_BROWN79_INVERSION_HPP_
27 
28 namespace mpblocks {
29 namespace brown79 {
30 
31 template <class Traits>
33 
34 template <class Traits>
35 Inversion<Traits>::Inversion(const Point& center, Scalar radius) {
36  init(center, radius);
37 }
38 
39 template <class Traits>
40 void Inversion<Traits>::init(const Point& center, Scalar radius) {
41  m_center = center;
42  m_radius = radius;
43 }
44 
45 template <class Traits>
46 typename Traits::Point Inversion<Traits>::invert(const Point& p) {
47  // subtract from center ot get a vector
48  Point v = p - m_center;
49 
50  // now invert vector
51  v = (m_radius * m_radius / v.squaredNorm()) * v;
52 
53  // and add back to the center to get the result point
54  return v + m_center;
55 }
56 
57 template <class Traits>
59  const Point& p) {
60  return invert(p);
61 }
62 
63 template <class Traits>
64 const typename Traits::Point& Inversion<Traits>::center() const {
65  return m_center;
66 }
67 
68 template <class Traits>
69 typename Traits::Scalar Inversion<Traits>::radius() const {
70  return m_radius;
71 }
72 
73 } // namespace brown79
74 } // namespace mpblocks
75 
76 
77 #endif // MPBLOCKS_BROWN79_INVERSION_HPP_
Point invert(const Point &p)
invert a point
Definition: inversion.hpp:46
int init()
calls FCGX_Init
Scalar radius() const
return the radius of this inversion map
Definition: inversion.hpp:69
void init(const Point &center, Scalar radius=1.0)
alter the inversion map to have a new center and radius
Definition: inversion.hpp:40
Point operator()(const Point &p)
invert a point
Definition: inversion.hpp:58
const Point & center() const
return the center of this inversion map
Definition: inversion.hpp:64
Inversion()
create an uninitialized inversion
Definition: inversion.hpp:32