diff --git a/src/2geom/rect.h b/src/2geom/rect.h
index 86f9ec1406892eaccb92a9348bde3d58c5a304f6..c89946606fe86886924c9f54ae778882430dec1e 100644 (file)
--- a/src/2geom/rect.h
+++ b/src/2geom/rect.h
return x && y ? boost::optional<Rect>(Rect(*x, *y)) : boost::optional<Rect>();
}
+inline
+double distanceSq( Point const& p, Rect const& rect )
+{
+ double dx = 0, dy = 0;
+ if ( p[X] < rect.left() )
+ {
+ dx = p[X] - rect.left();
+ }
+ else if ( p[X] > rect.right() )
+ {
+ dx = rect.right() - p[X];
+ }
+ if ( p[Y] < rect.top() )
+ {
+ dy = rect.top() - p[Y];
+ }
+ else if ( p[Y] > rect.bottom() )
+ {
+ dy = p[Y] - rect.bottom();
+ }
+ return dx*dx + dy*dy;
}
+inline
+double distance( Point const& p, Rect const& rect )
+{
+ return std::sqrt(distanceSq(p, rect));
+}
+
+
+} // end namespace Geom
+
#endif //_2GEOM_RECT
#endif //_2GEOM_D2
/*