summaryrefslogtreecommitdiffstats
path: root/src/libnr/nr-point-fns.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/libnr/nr-point-fns.cpp')
-rw-r--r--src/libnr/nr-point-fns.cpp91
1 files changed, 15 insertions, 76 deletions
diff --git a/src/libnr/nr-point-fns.cpp b/src/libnr/nr-point-fns.cpp
index cd6d6927b..a2e74c112 100644
--- a/src/libnr/nr-point-fns.cpp
+++ b/src/libnr/nr-point-fns.cpp
@@ -1,72 +1,11 @@
-#include <libnr/nr-point-fns.h>
-#include <2geom/isnan.h>
+#include "libnr/nr-point-fns.h"
-using NR::Point;
-
-/** Compute the L infinity, or maximum, norm of \a p. */
-NR::Coord NR::LInfty(Point const &p) {
- NR::Coord const a(fabs(p[0]));
- NR::Coord const b(fabs(p[1]));
- 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
-NR::is_zero(Point const &p)
-{
- return ( p[0] == 0 &&
- p[1] == 0 );
-}
-
-bool
-NR::is_unit_vector(Point const &p)
-{
- return fabs(1.0 - L2(p)) <= 1e-4;
- /* 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. */
-}
-
-NR::Coord NR::atan2(Point const p) {
- return std::atan2(p[NR::Y], p[NR::X]);
-}
-
-/** 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.
- */
-Point NR::unit_vector(Point const &a)
-{
- Point ret(a);
- ret.normalize();
- return ret;
-}
-
-NR::Point abs(NR::Point const &b)
-{
- NR::Point ret;
- for ( int i = 0 ; i < 2 ; i++ ) {
- ret[i] = fabs(b[i]);
- }
- return ret;
-}
-
-NR::Point
-snap_vector_midpoint (NR::Point p, NR::Point begin, NR::Point end, double snap)
+Geom::Point
+snap_vector_midpoint (Geom::Point const &p, Geom::Point const &begin, Geom::Point const &end, double snap)
{
- double length = NR::L2(end - begin);
- NR::Point be = (end - begin) / length;
- double r = NR::dot(p - begin, be);
+ double length = Geom::distance(begin, end);
+ Geom::Point be = (end - begin) / length;
+ double r = Geom::dot(p - begin, be);
if (r < 0.0) return begin;
if (r > length) return end;
@@ -78,11 +17,11 @@ snap_vector_midpoint (NR::Point p, NR::Point begin, NR::Point end, double snap)
}
double
-get_offset_between_points (NR::Point p, NR::Point begin, NR::Point end)
+get_offset_between_points (Geom::Point const &p, Geom::Point const &begin, Geom::Point const &end)
{
- double length = NR::L2(end - begin);
- NR::Point be = (end - begin) / length;
- double r = NR::dot(p - begin, be);
+ double length = Geom::distance(begin, end);
+ Geom::Point be = (end - begin) / length;
+ double r = Geom::dot(p - begin, be);
if (r < 0.0) return 0.0;
if (r > length) return 1.0;
@@ -90,8 +29,8 @@ get_offset_between_points (NR::Point p, NR::Point begin, NR::Point end)
return (r / length);
}
-NR::Point
-project_on_linesegment(NR::Point const p, NR::Point const p1, NR::Point const p2)
+Geom::Point
+project_on_linesegment(Geom::Point const &p, Geom::Point const &p1, Geom::Point const &p2)
{
// p_proj = projection of p on the linesegment running from p1 to p2
// p_proj = p1 + u (p2 - p1)
@@ -104,9 +43,9 @@ project_on_linesegment(NR::Point const p, NR::Point const p1, NR::Point const p2
return p;
}
- NR::Point const d1(p-p1); // delta 1
- NR::Point const d2(p2-p1); // delta 2
- double const u = (d1[NR::X] * d2[NR::X] + d1[NR::Y] * d2[NR::Y]) / (NR::L2(d2) * NR::L2(d2));
+ Geom::Point d1(p-p1); // delta 1
+ Geom::Point d2(p2-p1); // delta 2
+ double u = Geom::dot(d1, d2) / Geom::L2sq(d2);
return (p1 + u*(p2-p1));
}