~and471/inkscape/ocal-dialog-improvements

« back to all changes in this revision

Viewing changes to src/libnr/nr-point-fns.h

  • Committer: Andrew
  • Date: 2011-12-27 21:04:47 UTC
  • mfrom: (10092.1.704 inkscape)
  • Revision ID: at.higginson@gmail.com-20111227210447-7nngd0yuw0reb8kq
merged with trunk so I can build again...

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#ifndef __NR_POINT_OPS_H__
2
 
#define __NR_POINT_OPS_H__
3
 
 
4
 
#include <libnr/nr-point-ops.h>
5
 
#include <libnr/nr-dim2.h>
6
 
#include <libnr/nr-macros.h>
7
 
 
8
 
namespace NR {
9
 
 
10
 
/** Compute the L1 norm, or manhattan distance, of \a p. */
11
 
inline Coord L1(Point const &p) {
12
 
        Coord d = 0;
13
 
        for ( int i = 0 ; i < 2 ; i++ ) {
14
 
                d += fabs(p[i]);
15
 
        }
16
 
        return d;
17
 
}
18
 
 
19
 
/** Compute the L2, or euclidean, norm of \a p. */
20
 
inline Coord L2(Point const &p) {
21
 
        return hypot(p[0], p[1]);
22
 
}
23
 
 
24
 
extern double LInfty(Point const &p);
25
 
 
26
 
bool is_zero(Point const &p);
27
 
 
28
 
bool is_unit_vector(Point const &p);
29
 
 
30
 
extern double atan2(Point const p);
31
 
 
32
 
inline bool point_equalp(Point const &a, Point const &b, double const eps)
33
 
{
34
 
    return ( NR_DF_TEST_CLOSE(a[X], b[X], eps) &&
35
 
             NR_DF_TEST_CLOSE(a[Y], b[Y], eps) );
36
 
}
37
 
 
38
 
/** Returns p * NR::rotate_degrees(90), but more efficient.
39
 
 *
40
 
 * Angle direction in Inkscape code: If you use the traditional mathematics convention that y
41
 
 * increases upwards, then positive angles are anticlockwise as per the mathematics convention.  If
42
 
 * you take the common non-mathematical convention that y increases downwards, then positive angles
43
 
 * are clockwise, as is common outside of mathematics.
44
 
 *
45
 
 * There is no rot_neg90 function: use -rot90(p) instead.
46
 
 */
47
 
inline Point rot90(Point const &p)
48
 
{
49
 
    return Point(-p[Y], p[X]);
50
 
}
51
 
 
52
 
/** Given two points and a parameter t \in [0, 1], return a point
53
 
 * proportionally from a to b by t. */
54
 
inline Point Lerp(double const t, Point const a, Point const b)
55
 
{
56
 
    return ( ( 1 - t ) * a
57
 
             + t * b );
58
 
}
59
 
 
60
 
Point unit_vector(Point const &a);
61
 
 
62
 
inline Coord dot(Point const &a, Point const &b)
63
 
{
64
 
    Coord ret = 0;
65
 
    for ( int i = 0 ; i < 2 ; i++ ) {
66
 
        ret += a[i] * b[i];
67
 
    }
68
 
    return ret;
69
 
}
70
 
 
71
 
inline Coord distance (Point const &a, Point const &b)
72
 
{
73
 
    Coord ret = 0;
74
 
    for ( int i = 0 ; i < 2 ; i++ ) {
75
 
        ret += (a[i] - b[i]) * (a[i] - b[i]);
76
 
    }
77
 
    return sqrt (ret);
78
 
}
79
 
 
80
 
/** Defined as dot(a, b.cw()). */
81
 
inline Coord cross(Point const &a, Point const &b)
82
 
{
83
 
    Coord ret = 0;
84
 
    ret -= a[0] * b[1];
85
 
    ret += a[1] * b[0];
86
 
    return ret;
87
 
}
88
 
 
89
 
Point abs(Point const &b);
90
 
 
91
 
} /* namespace NR */
92
 
 
93
 
NR::Point snap_vector_midpoint (NR::Point p, NR::Point begin, NR::Point end, double snap);
94
 
 
95
 
double get_offset_between_points (NR::Point p, NR::Point begin, NR::Point end);
96
 
 
97
 
NR::Point project_on_linesegment(NR::Point const p, NR::Point const p1, NR::Point const p2); 
98
 
 
99
 
#endif /* !__NR_POINT_OPS_H__ */
100
 
 
101
 
/*
102
 
  Local Variables:
103
 
  mode:c++
104
 
  c-file-style:"stroustrup"
105
 
  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
106
 
  indent-tabs-mode:nil
107
 
  fill-column:99
108
 
  End:
109
 
*/
110
 
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :