From 8235784117d8d1443ab96bb418cf446fdf531944 Mon Sep 17 00:00:00 2001 From: Adrian Ratiu Date: Fri, 29 Dec 2023 22:11:17 +0200 Subject: [PATCH] element/basic_shapes: add two Rectangle getters/setters It is useful to be able to update rectangle styles after the rectangles were created, so we add a helper for it. It is also useful to be able to get the point coordinates. --- plotters/src/element/basic_shapes.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/plotters/src/element/basic_shapes.rs b/plotters/src/element/basic_shapes.rs index 3c2564ec..c43af473 100644 --- a/plotters/src/element/basic_shapes.rs +++ b/plotters/src/element/basic_shapes.rs @@ -418,6 +418,20 @@ impl Rectangle { self.margin = (t, b, l, r); self } + + /// Get the points of the rectangle + /// - returns the element points + pub fn get_points(&self) -> (&Coord, &Coord) { + (&self.points[0], &self.points[1]) + } + + /// Set the style of the rectangle + /// - `style`: The shape style + /// - returns a mut reference to the rectangle + pub fn set_style>(&mut self, style: S) -> &mut Self { + self.style = style.into(); + self + } } impl<'a, Coord> PointCollection<'a, Coord> for &'a Rectangle {