Skip to main content

distance_2d

Function distance_2d 

Source
pub fn distance_2d(left: Point2, right: Point2) -> f64
Expand description

Returns the Euclidean distance between two 2D points.

ยงExamples

use use_geometry::{Point2, distance_2d};

let left = Point2::new(0.0, 0.0);
let right = Point2::new(3.0, 4.0);

assert_eq!(distance_2d(left, right), 5.0);
Examples found in repository?
examples/facade_validated_geometry.rs (line 14)
7fn main() -> Result<(), use_math::GeometryError> {
8    let a = Point2::try_new(0.0, 0.0)?;
9    let b = Point2::try_new(4.0, 0.0)?;
10    let c = Point2::try_new(0.0, 3.0)?;
11
12    let triangle = Triangle::try_new(a, b, c)?;
13
14    assert!(approx_eq(distance_2d(a, b), 4.0));
15    assert!(approx_eq(triangle.perimeter(), 12.0));
16    assert_eq!(try_orientation_2d(a, b, c)?, Orientation2::CounterClockwise);
17
18    Ok(())
19}