'Point along segment that is closest to given point.'

def closest_point_to_point(self, point):

    segment_vector = self.end.sub(self.start)
    point_vector = point.sub(self.start)
    seg_mag = segment_vector.magnitude()
    projection = segment_vector.dot_product(point_vector)
    scalar = (projection / (seg_mag ** 2))
    scalar = (1.0 if (scalar > 1.0) else scalar)
    scalar = (0.0 if (scalar < 0.0) else scalar)
    return self.start.add(segment_vector.unit().scale((scalar * seg_mag)))
