nr-point-fns.cpp revision 640bacb96d4e571bf5a169eec557cb20db1962ce
#include <libnr/nr-point-fns.h>
/** Compute the L infinity, or maximum, norm of \a p. */
return ( a < b || IS_NAN(b)
? b
: a );
}
/** Returns true iff p is a zero vector, i.e.\ Point(0, 0).
*
* (NaN is considered non-zero.)
*/
bool
{
return ( p[0] == 0 &&
p[1] == 0 );
}
bool
{
/* The tolerance of 1e-4 is somewhat arbitrary. NR::Point::normalize is believed to return
points well within this tolerance. I'm not aware of any callers that want a small
tolerance; most callers would be ok with a tolerance of 0.25. */
}
}
/** Returns a version of \a a scaled to be a unit vector (within rounding error).
*
* The current version tries to handle infinite coordinates gracefully,
* but it's not clear that any callers need that.
*
* \pre a != Point(0, 0).
* \pre Neither coordinate is NaN.
* \post L2(ret) very near 1.0.
*/
{
return ret;
}
{
for ( int i = 0 ; i < 2 ; i++ ) {
}
return ret;
}
{
if (r < 0.0) return begin;
}
double
{
if (r < 0.0) return 0.0;
if (r > length) return 1.0;
return (r / length);
}
{
// p_proj = projection of p on the linesegment running from p1 to p2
// p_proj = p1 + u (p2 - p1)
// calculate u according to "Minimum Distance between a Point and a Line"
// Warning: projected points will not necessarily be in between the endpoints of the linesegments!
return p;
}
}
/*
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 :