Skip to content

Commit

Permalink
element/basic_shapes: add two Rectangle getters/setters
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
10ne1 committed Jun 23, 2024
1 parent 16714cf commit 316ad09
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions plotters/src/element/basic_shapes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,20 @@ impl<Coord> Rectangle<Coord> {
self.margin = (t, b, l, r);
self
}

/// Get the points of the rectangle
/// - returns the element points
pub fn get_points(&self) -> (&Coord, &Coord) {
return (&self.points[0], &self.points[1]);

Check warning

Code scanning / clippy

unneeded return statement Warning

unneeded return statement
}

/// Set the style of the rectangle
/// - `style`: The shape style
/// - returns a mut reference to the rectangle
pub fn set_style<S: Into<ShapeStyle>>(&mut self, style: S) -> &mut Self {
self.style = style.into();
self
}
}

impl<'a, Coord> PointCollection<'a, Coord> for &'a Rectangle<Coord> {
Expand Down

0 comments on commit 316ad09

Please sign in to comment.