+ double dx = point2->x - point1->x;
+ double dy = point2->y - point1->y;
+ double seg_len = sqrt(dx*dx+dy*dy);
+ double distance_from_seg =
+ seg_len*((x-point1->x)*dy-(y-point1->y)*dx)/(dy*dy+dx*dx);
+ double distance_from_prev =
+ seg_len*((y-point1->y)*dy+(x-point1->x)*dx)/(dy*dy+dx*dx);
+
+ if ((fabs(distance_from_seg) < extra &&
+ distance_from_prev >= 0 && distance_from_prev <= seg_len)
+ || inLabelRegion)