~centralelyon2010/inkscape/imagelinks2

« back to all changes in this revision

Viewing changes to src/2geom/rect.h

  • Committer: johanengelen
  • Date: 2008-05-10 20:20:11 UTC
  • Revision ID: johanengelen@users.sourceforge.net-20080510202011-s2oudu0rb9e2gl32
update to latest 2geom. this adds gsl dependency, doesn't seem to make inskape executable bigger

Show diffs side-by-side

added added

removed removed

Lines of Context:
153
153
    return x && y ? boost::optional<Rect>(Rect(*x, *y)) : boost::optional<Rect>();
154
154
}
155
155
 
156
 
}
 
156
inline
 
157
double distanceSq( Point const& p, Rect const& rect )
 
158
{
 
159
        double dx = 0, dy = 0;
 
160
        if ( p[X] < rect.left() )
 
161
        {
 
162
                dx = p[X] - rect.left();
 
163
        }
 
164
        else if ( p[X] > rect.right() )
 
165
        {
 
166
                dx = rect.right() - p[X];
 
167
        }
 
168
        if ( p[Y] < rect.top() )
 
169
        {
 
170
                dy = rect.top() - p[Y];
 
171
        }
 
172
        else if (  p[Y] > rect.bottom() )
 
173
        {
 
174
                dy = p[Y] - rect.bottom();
 
175
        }
 
176
        return dx*dx + dy*dy;
 
177
}
 
178
 
 
179
inline 
 
180
double distance( Point const& p, Rect const& rect )
 
181
{
 
182
        return std::sqrt(distanceSq(p, rect));
 
183
}
 
184
 
 
185
 
 
186
} // end namespace Geom
157
187
 
158
188
#endif //_2GEOM_RECT
159
189
#endif //_2GEOM_D2