summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorseancarroll <seanc28@gmail.com>2021-01-02 16:40:05 -0600
committerseancarroll <seanc28@gmail.com>2021-01-02 16:40:05 -0600
commitecf32922605a565c0a915c1c4a4fc06d55dfcb7f (patch)
treeb3f80716e773124499c147c90b7302214349f155
parent8d4ac73304df371250902dfe5f601a775f2ab420 (diff)
downloaddotavious-ecf32922605a565c0a915c1c4a4fc06d55dfcb7f.zip
adds rectangle struct
-rw-r--r--src/lib.rs24
1 files changed, 20 insertions, 4 deletions
diff --git a/src/lib.rs b/src/lib.rs
index f98a15d..0b22966 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1420,6 +1420,24 @@ impl<'a> DotString<'a> for Point {
}
}
+pub struct Rectangle {
+ lower_left: Point,
+ upper_right: Point,
+}
+
+impl<'a> From<Rectangle> for AttributeText<'a> {
+ fn from(rectangle: Rectangle) -> Self {
+ AttributeText::quoted(rectangle.dot_string())
+ }
+}
+
+impl<'a> DotString<'a> for Rectangle {
+ fn dot_string(&self) -> Cow<'a, str> {
+ format!("{:.1},{:.1},{:.1},{:.1}",
+ self.lower_left.x, self.lower_left.y, self.upper_right.x, self.upper_right.y).into()
+ }
+}
+
/// These specify the 8 row or column major orders for traversing a rectangular array,
/// the first character corresponding to the major order and the second to the minor order.
/// Thus, for “BL”, the major order is from bottom to top, and the minor order is from left to right.
@@ -2065,11 +2083,9 @@ trait NodeAttributes<'a> {
// TODO: add post_spline
- // TODO: add rect type?
- // "%f,%f,%f,%f"
/// Rectangles for fields of records, in points.
- fn rects(&mut self, rects: String) -> &mut Self {
- self.add_attribute("rects", AttributeText::attr(rects))
+ fn rects(&mut self, rect: Rectangle) -> &mut Self {
+ self.add_attribute("rects", AttributeText::from(rect))
}
/// If true, force polygon to be regular, i.e., the vertices of the polygon will