Struct Circle
pub struct Circle { /* private fields */ }Expand description
A circle in 2D Euclidean space.
Circle stores a center point and a radius. Construction validates the
radius so downstream methods can stay simple.
§Examples
use use_geometry::{Circle, Point2};
let circle = Circle::try_new(Point2::new(1.0, 2.0), 3.0)?;
assert_eq!(circle.center(), Point2::new(1.0, 2.0));
assert_eq!(circle.radius(), 3.0);
assert_eq!(circle.diameter(), 6.0);Implementations§
§impl Circle
impl Circle
pub fn try_new(center: Point2, radius: f64) -> Result<Circle, GeometryError>
pub fn try_new(center: Point2, radius: f64) -> Result<Circle, GeometryError>
Creates a circle from a center point and a finite, non-negative radius.
A radius of 0.0 is valid and represents a degenerate circle centered
at center.
§Errors
Returns GeometryError::NonFiniteComponent when center contains a
non-finite coordinate.
Returns GeometryError::NonFiniteRadius when radius is NaN or
infinite.
Returns GeometryError::NegativeRadius when radius is negative.
§Examples
use use_geometry::{Circle, Point2};
let circle = Circle::try_new(Point2::new(0.0, 0.0), 2.5)?;
assert_eq!(circle.center(), Point2::new(0.0, 0.0));
assert_eq!(circle.radius(), 2.5);pub fn circumference(&self) -> f64
pub fn circumference(&self) -> f64
Returns the circle circumference.
pub fn contains_point(&self, point: Point2) -> bool
pub fn contains_point(&self, point: Point2) -> bool
Returns true when point lies inside or on the circle boundary.
pub fn contains_point_with_tolerance(
&self,
point: Point2,
tolerance: f64,
) -> Result<bool, GeometryError>
pub fn contains_point_with_tolerance( &self, point: Point2, tolerance: f64, ) -> Result<bool, GeometryError>
Returns true when point lies inside the circle expanded by tolerance.
§Errors
Returns GeometryError::NonFiniteTolerance when tolerance is NaN
or infinite.
Returns GeometryError::NegativeTolerance when tolerance is negative.