epaint/shapes/
path_shape.rs1use crate::*;
2
3#[derive(Clone, Debug, PartialEq)]
5#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
6pub struct PathShape {
7 pub points: Vec<Pos2>,
9
10 pub closed: bool,
13
14 pub fill: Color32,
16
17 pub stroke: PathStroke,
19 }
22
23impl PathShape {
24 #[inline]
28 pub fn line(points: Vec<Pos2>, stroke: impl Into<PathStroke>) -> Self {
29 Self {
30 points,
31 closed: false,
32 fill: Default::default(),
33 stroke: stroke.into(),
34 }
35 }
36
37 #[inline]
39 pub fn closed_line(points: Vec<Pos2>, stroke: impl Into<PathStroke>) -> Self {
40 Self {
41 points,
42 closed: true,
43 fill: Default::default(),
44 stroke: stroke.into(),
45 }
46 }
47
48 #[inline]
52 pub fn convex_polygon(
53 points: Vec<Pos2>,
54 fill: impl Into<Color32>,
55 stroke: impl Into<PathStroke>,
56 ) -> Self {
57 Self {
58 points,
59 closed: true,
60 fill: fill.into(),
61 stroke: stroke.into(),
62 }
63 }
64
65 #[inline]
67 pub fn visual_bounding_rect(&self) -> Rect {
68 if self.fill == Color32::TRANSPARENT && self.stroke.is_empty() {
69 Rect::NOTHING
70 } else {
71 Rect::from_points(&self.points).expand(self.stroke.width / 2.0)
72 }
73 }
74}
75
76impl From<PathShape> for Shape {
77 #[inline(always)]
78 fn from(shape: PathShape) -> Self {
79 Self::Path(shape)
80 }
81}