Code

update to latest 2geom. this adds gsl dependency, doesn't seem to make inskape execut...
[inkscape.git] / src / 2geom / rect.h
index 86f9ec1406892eaccb92a9348bde3d58c5a304f6..c89946606fe86886924c9f54ae778882430dec1e 100644 (file)
@@ -153,8 +153,38 @@ inline boost::optional<Rect> intersect(Rect const & a, Rect const & b) {
     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
 /*