def get_sq_seg_dist(point, point_1, point_2)
      x  = point_1.x
      y  = point_1.y
      dx = point_2.x - x
      dy = point_2.y - y

      if dx != 0 || dy != 0
        t = ((point.x - x) * dx + (point.y - y) * dy) / (dx * dx + dy * dy)

        if t > 1
          x = point_2.x
          y = point_2.y

        elsif t > 0
          x += dx * t
          y += dy * t
        end
      end

      dx = point.x - x
      dy = point.y - y

      dx * dx + dy * dy
    end
def get_sq_seg_dist(point, point_1, point_2)
      x  = point_1.x
      y  = point_1.y
      dx = point_2.x - x
      dy = point_2.y - y

      if dx != 0 || dy != 0
        t = ((point.x - x) * dx + (point.y - y) * dy) / (dx * dx + dy * dy)

        if t > 1
          x = point_2.x
          y = point_2.y

        elsif t > 0
          x += dx * t
          y += dy * t
        end
      end

      dx = point.x - x
      dy = point.y - y

      dx * dx + dy * dy
    end
Square distance from a point to a segment