nr-point-fns.h revision 6b15695578f07a3f72c4c9475c1a261a3021472a
#ifndef __NR_POINT_OPS_H__
#define __NR_POINT_OPS_H__
#include <libnr/nr-point-ops.h>
#include <libnr/nr-macros.h>
/** Compute the L1 norm, or manhattan distance, of \a p. */
Coord d = 0;
for ( int i = 0 ; i < 2 ; i++ ) {
d += fabs(p[i]);
}
return d;
}
/** Compute the L2, or euclidean, norm of \a p. */
return hypot(p[0], p[1]);
}
bool is_unit_vector(Point const &p);
{
return ( NR_DF_TEST_CLOSE(a[X], b[X], eps) &&
NR_DF_TEST_CLOSE(a[Y], b[Y], eps) );
}
/** Returns p * NR::rotate_degrees(90), but more efficient.
*
* Angle direction in Inkscape code: If you use the traditional mathematics convention that y
* increases upwards, then positive angles are anticlockwise as per the mathematics convention. If
* you take the common non-mathematical convention that y increases downwards, then positive angles
* are clockwise, as is common outside of mathematics.
*
* There is no rot_neg90 function: use -rot90(p) instead.
*/
{
return Point(-p[Y], p[X]);
}
/** Given two points and a parameter t \in [0, 1], return a point
* proportionally from a to b by t. */
{
return ( ( 1 - t ) * a
+ t * b );
}
{
for ( int i = 0 ; i < 2 ; i++ ) {
ret += a[i] * b[i];
}
return ret;
}
{
for ( int i = 0 ; i < 2 ; i++ ) {
ret += (a[i] - b[i]) * (a[i] - b[i]);
}
}
/** Defined as dot(a, b.cw()). */
{
ret -= a[0] * b[1];
ret += a[1] * b[0];
return ret;
}
} /* namespace NR */
#endif /* !__NR_POINT_OPS_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 :