1
#ifndef __NR_POINT_OPS_H__
2
#define __NR_POINT_OPS_H__
4
#include <libnr/nr-point-ops.h>
5
#include <libnr/nr-dim2.h>
6
#include <libnr/nr-macros.h>
10
/** Compute the L1 norm, or manhattan distance, of \a p. */
11
inline Coord L1(Point const &p) {
13
for ( int i = 0 ; i < 2 ; i++ ) {
19
/** Compute the L2, or euclidean, norm of \a p. */
20
inline Coord L2(Point const &p) {
21
return hypot(p[0], p[1]);
24
extern double LInfty(Point const &p);
26
bool is_zero(Point const &p);
28
bool is_unit_vector(Point const &p);
30
extern double atan2(Point const p);
32
inline bool point_equalp(Point const &a, Point const &b, double const eps)
34
return ( NR_DF_TEST_CLOSE(a[X], b[X], eps) &&
35
NR_DF_TEST_CLOSE(a[Y], b[Y], eps) );
38
/** Returns p * NR::rotate_degrees(90), but more efficient.
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.
45
* There is no rot_neg90 function: use -rot90(p) instead.
47
inline Point rot90(Point const &p)
49
return Point(-p[Y], p[X]);
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)
56
return ( ( 1 - t ) * a
60
Point unit_vector(Point const &a);
62
inline Coord dot(Point const &a, Point const &b)
65
for ( int i = 0 ; i < 2 ; i++ ) {
71
inline Coord distance (Point const &a, Point const &b)
74
for ( int i = 0 ; i < 2 ; i++ ) {
75
ret += (a[i] - b[i]) * (a[i] - b[i]);
80
/** Defined as dot(a, b.cw()). */
81
inline Coord cross(Point const &a, Point const &b)
89
Point abs(Point const &b);
93
NR::Point snap_vector_midpoint (NR::Point p, NR::Point begin, NR::Point end, double snap);
95
double get_offset_between_points (NR::Point p, NR::Point begin, NR::Point end);
97
NR::Point project_on_linesegment(NR::Point const p, NR::Point const p1, NR::Point const p2);
99
#endif /* !__NR_POINT_OPS_H__ */
104
c-file-style:"stroustrup"
105
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
110
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :