+bool
+Line::covers (Duple const & point) const
+{
+ const Duple p = window_to_item (point);
+ static const Distance threshold = 2.0;
+
+ /* this quick check works for vertical and horizontal lines, which are
+ * common.
+ */
+
+ if (_points[0].x == _points[1].x) {
+ /* line is vertical, just check x coordinate */
+ return fabs (_points[0].x - p.x) <= threshold;
+ }
+
+ if (_points[0].y == _points[1].y) {
+ /* line is horizontal, just check y coordinate */
+ return fabs (_points[0].y - p.y) <= threshold;
+ }
+
+ Duple at;
+ double t;
+ Duple a (_points[0]);
+ Duple b (_points[1]);
+ const Rect visible (window_to_item (_canvas->visible_area()));
+
+ /*
+ Clamp the line endpoints to the visible area of the canvas. If we do
+ not do this, we have a line segment extending to COORD_MAX and our
+ math goes wrong.
+ */
+
+ a.x = min (a.x, visible.x1);
+ a.y = min (a.y, visible.y1);
+ b.x = min (b.x, visible.x1);
+ b.y = min (b.y, visible.y1);
+
+ double d = distance_to_segment_squared (p, a, b, t, at);
+
+ if (t < 0.0 || t > 1.0) {
+ return false;
+ }
+
+ if (d < threshold) {
+ return true;
+ }
+
+ return false;