~valavanisalex/ubuntu/precise/inkscape/fix-943984

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Bryce Harrington
  • Date: 2009-07-02 17:09:45 UTC
  • mfrom: (1.1.9 upstream)
  • Revision ID: james.westby@ubuntu.com-20090702170945-nn6d6zswovbwju1t
Tags: 0.47~pre1-0ubuntu1
* New upstream release.
  - Don't constrain maximization on small resolution devices (pre0)
    (LP: #348842)
  - Fixes segfault on startup (pre0)
    (LP: #391149)

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 *get_snap_vector (NR::Point p, NR::Point o, double snap, double initial);
 
94
 
 
95
NR::Point snap_vector_midpoint (NR::Point p, NR::Point begin, NR::Point end, double snap);
 
96
 
 
97
double get_offset_between_points (NR::Point p, NR::Point begin, NR::Point end);
 
98
 
 
99
NR::Point project_on_linesegment(NR::Point const p, NR::Point const p1, NR::Point const p2); 
 
100
 
 
101
#endif /* !__NR_POINT_OPS_H__ */
 
102
 
 
103
/*
 
104
  Local Variables:
 
105
  mode:c++
 
106
  c-file-style:"stroustrup"
 
107
  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
 
108
  indent-tabs-mode:nil
 
109
  fill-column:99
 
110
  End:
 
111
*/
 
112
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :