summaryrefslogtreecommitdiff
path: root/library/src
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2023-03-28 16:57:18 +0200
committerLaurenz <laurmaedje@gmail.com>2023-03-28 17:00:02 +0200
commitd1ff94a3b59b5642c549b1141853e0ffbe842185 (patch)
treebeebac32faa4d40eafd385d371744bf511b01c20 /library/src
parent44165d09a9e6c09d4c5a9dbeab1af7f23e3d887a (diff)
A bit more polygon docs
Diffstat (limited to 'library/src')
-rw-r--r--library/src/visualize/mod.rs4
-rw-r--r--library/src/visualize/polygon.rs30
2 files changed, 23 insertions, 11 deletions
diff --git a/library/src/visualize/mod.rs b/library/src/visualize/mod.rs
index 198c707d..06eec23d 100644
--- a/library/src/visualize/mod.rs
+++ b/library/src/visualize/mod.rs
@@ -2,10 +2,10 @@
mod image;
mod line;
-mod shape;
mod polygon;
+mod shape;
pub use self::image::*;
pub use self::line::*;
+pub use self::polygon::*;
pub use self::shape::*;
-pub use self::polygon::*; \ No newline at end of file
diff --git a/library/src/visualize/polygon.rs b/library/src/visualize/polygon.rs
index 40058834..07725b72 100644
--- a/library/src/visualize/polygon.rs
+++ b/library/src/visualize/polygon.rs
@@ -1,10 +1,19 @@
use crate::prelude::*;
-/// A closed-path polygon.
+/// A closed polygon.
+///
+/// The polygon is defined by its corner points and is closed automatically.
///
/// ## Example
/// ```example
-/// #polygon(fill: blue, (0pt, 0pt), (10pt, 0pt), (10pt, 10pt))
+/// #polygon(
+/// fill: red,
+/// stroke: 2pt + black,
+/// (0pt, 0pt),
+/// (50%, 0pt),
+/// (50%, 4cm),
+/// (20%, 4cm),
+/// )
/// ```
///
/// Display: Polygon
@@ -13,6 +22,9 @@ use crate::prelude::*;
pub struct PolygonElem {
/// How to fill the polygon. See the
/// [rectangle's documentation]($func/rect.fill) for more details.
+ ///
+ /// Currently all polygons are filled according to the
+ /// [non-zero winding rule](https://en.wikipedia.org/wiki/Nonzero-rule).
pub fill: Option<Paint>,
/// How to stroke the polygon. See the [lines's
@@ -21,7 +33,8 @@ pub struct PolygonElem {
#[fold]
pub stroke: Option<PartialStroke>,
- /// The vertices of the polygon. The polygon automatically closes itself.
+ /// The vertices of the polygon. Each point is specified as an array of two
+ /// [relative lengths]($type/relative-length).
#[variadic]
pub vertices: Vec<Axes<Rel<Length>>>,
}
@@ -45,20 +58,19 @@ impl Layout for PolygonElem {
.collect();
let size = points.iter().fold(Point::zero(), |max, c| c.max(max)).to_size();
-
let target = regions.expand.select(regions.size, size);
let mut frame = Frame::new(target);
- // only create a path if there is more than zero points.
+ // Only create a path if there are more than zero points.
if points.len() > 0 {
- let stroke = self.stroke(styles).map(|e| e.unwrap_or_default());
let fill = self.fill(styles);
+ let stroke = self.stroke(styles).map(PartialStroke::unwrap_or_default);
- // construct a closed path given all points.
+ // Construct a closed path given all points.
let mut path = Path::new();
path.move_to(points[0]);
- for point in &points[1..] {
- path.line_to(*point);
+ for &point in &points[1..] {
+ path.line_to(point);
}
path.close_path();