fn min_distance_point_line(s: &Point, t: &LineSegment) -> Result<f64, ShapelikeError> {
    // only supported for 2D objects
    if s.get_dimension() != 2 {
        return Err(ShapelikeError::UnsupportedOperation);
    }

    let (x1, x2) = t.get_coordinate(0);
    let (y1, y2) = t.get_coordinate(1);

    let x0 = s.get_coordinate(0);
    let y0 = s.get_coordinate(1);

    // avoid /0
    if x2 >= x1 - std::f64::EPSILON && x2 <= x1 + std::f64::EPSILON {
        return Ok((x0 - x1).abs());
    }

    // avoid /0
    if y2 >= y1 - std::f64::EPSILON && y2 <= y1 + std::f64::EPSILON {
        return Ok((y0 - y1).abs());
    }

    Ok(((x2 - x1) * (y1 - y0) - (x1 - x0) * (y2 - y1)).abs()
        / ((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)).sqrt())
}
/// Returns the minimum distance between a point and a line.
Returns the minimum distance between a point and a line.
Returns the minimum distance between a point and a line .
fn min_distance_point_line(s: &Point, t: &LineSegment) -> Result<f64, ShapelikeError> {
    // only supported for 2D objects
    if s.get_dimension() != 2 {
        return Err(ShapelikeError::UnsupportedOperation);
    }
    let (x1, x2) = t.get_coordinate(0);
    let (y1, y2) = t.get_coordinate(1);
    let x0 = s.get_coordinate(0);
    let y0 = s.get_coordinate(1);
    // avoid /0
    if x2 >= x1 - std::f64::EPSILON && x2 <= x1 + std::f64::EPSILON {
        return Ok((x0 - x1).abs());
    }
    // avoid /0
    if y2 >= y1 - std::f64::EPSILON && y2 <= y1 + std::f64::EPSILON {
        return Ok((y0 - y1).abs());
    }
    Ok(((x2 - x1) * (y1 - y0) - (x1 - x0) * (y2 - y1)).abs()
        / ((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)).sqrt())
}
fn min_distance_point_line ( s : & Point , t : & LineSegment ) -> Result < f64 , ShapelikeError > { // only supported for 2D objects if s . get_dimension ( ) != 2 { return Err ( ShapelikeError :: UnsupportedOperation ) ; } let ( x1 , x2 ) = t . get_coordinate ( 0 ) ; let ( y1 , y2 ) = t . get_coordinate ( 1 ) ; let x0 = s . get_coordinate ( 0 ) ; let y0 = s . get_coordinate ( 1 ) ; // avoid /0 if x2 >= x1 - std :: f64 :: EPSILON && x2 <= x1 + std :: f64 :: EPSILON { return Ok ( ( x0 - x1 ) . abs ( ) ) ; } // avoid /0 if y2 >= y1 - std :: f64 :: EPSILON && y2 <= y1 + std :: f64 :: EPSILON { return Ok ( ( y0 - y1 ) . abs ( ) ) ; } Ok ( ( ( x2 - x1 ) * ( y1 - y0 ) - ( x1 - x0 ) * ( y2 - y1 ) ) . abs ( ) / ( ( x2 - x1 ) * ( x2 - x1 ) + ( y2 - y1 ) * ( y2 - y1 ) ) . sqrt ( ) ) }
Returns the minimum distance between a point and a line.
Returns the minimum distance between a point and a line .
s
&Point
t
&LineSegment
s
&Point
t
&LineSegment