summaryrefslogtreecommitdiffstats
path: root/src/libnr/nr-rotate.h
blob: 051372ce6cf0451a6f8d1354c08a22a4bf1cbe94 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#ifndef SEEN_NR_ROTATE_H
#define SEEN_NR_ROTATE_H

/** \file
 * Rotation about the origin.
 */

#include <libnr/nr-point.h>
#include <libnr/nr-point-fns.h>
#include <libnr/nr-point-ops.h>

namespace NR {

/** Notionally an NR::Matrix corresponding to rotation about the origin.
    Behaves like NR::Matrix for multiplication.
**/
class rotate {
public:
    Point vec;

private:
    rotate();

public:
    explicit rotate(Coord theta);
    explicit rotate(Point const &p) : vec(p) {}
    explicit rotate(Coord const x, Coord const y) : vec(x, y) {}

    bool operator==(rotate const &o) const {
        return vec == o.vec;
    }

    bool operator!=(rotate const &o) const {
        return vec != o.vec;
    }

    inline rotate &operator*=(rotate const &b);
    /* Defined in nr-rotate-ops.h. */

    rotate inverse() const {
        /** \todo
         * In the usual case that vec is a unit vector (within rounding error),
         * dividing by len_sq is either a noop or numerically harmful. 
         * Make a unit_rotate class (or the like) that knows its length is 1.
         */
        double const len_sq = dot(vec, vec);
        return rotate( Point(vec[X], -vec[Y])
                       / len_sq );
    }
};

} /* namespace NR */


#endif /* !SEEN_NR_ROTATE_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:encoding=utf-8:textwidth=99 :