Skip to content

Commit 5bed46b

Browse files
authored
feat: add support for segmented line and scatter (#33)
1 parent 59ac389 commit 5bed46b

File tree

11 files changed

+1092
-56
lines changed

11 files changed

+1092
-56
lines changed

egui_plot/src/items/columnar_series.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
#![allow(rustdoc::missing_crate_level_docs)]
2+
use crate::transform::PlotBounds;
23
use core::fmt;
34
use core::ops::{Bound, RangeBounds};
45

5-
use crate::transform::PlotBounds;
6-
76
/// A zero-copy Series of `(x, y)`.
87
///
98
/// This is the canonical way to pass data into plotting items without packing
@@ -83,6 +82,7 @@ impl<'a> ColumnarSeries<'a> {
8382
}
8483

8584
/// Return an iterator over `(x, y)` pairs (by value).
85+
#[allow(clippy::iter_without_into_iter)]
8686
#[inline]
8787
pub fn iter(&self) -> ColumnarSeriesIter<'a> {
8888
ColumnarSeriesIter {
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
use egui::{Color32, Pos2, Shape, Stroke, Vec2};
2+
use std::f32::consts::PI;
3+
4+
#[inline]
5+
pub fn regular_ngon(n: usize, r: f32, angle_rad: f32) -> Vec<Pos2> {
6+
let n = n.max(3);
7+
(0..n)
8+
.map(|k| {
9+
let a = angle_rad + 2.0 * PI * (k as f32) / (n as f32);
10+
Pos2::new(a.cos() * r, a.sin() * r)
11+
})
12+
.collect()
13+
}
14+
15+
#[inline]
16+
pub fn star_ngon(n: usize, r_outer: f32, r_inner: f32, angle_rad: f32) -> Vec<Pos2> {
17+
let n = n.max(2);
18+
let mut pts = Vec::with_capacity(n * 2);
19+
for k in 0..n {
20+
let a_outer = angle_rad + 2.0 * PI * (k as f32) / (n as f32);
21+
let a_inner = a_outer + PI / (n as f32);
22+
pts.push(Pos2::new(a_outer.cos() * r_outer, a_outer.sin() * r_outer));
23+
pts.push(Pos2::new(a_inner.cos() * r_inner, a_inner.sin() * r_inner));
24+
}
25+
pts
26+
}
27+
28+
pub fn push_polygon_at(
29+
out: &mut Vec<Shape>,
30+
center: Pos2,
31+
local_pts: Vec<Vec2>,
32+
color: Color32,
33+
stroke: Stroke,
34+
filled: bool,
35+
) {
36+
let pts: Vec<Pos2> = local_pts.into_iter().map(|v| center + v).collect();
37+
if filled {
38+
out.push(Shape::convex_polygon(pts, color, Stroke::NONE));
39+
} else {
40+
out.push(Shape::closed_line(pts, Stroke::new(stroke.width, color)));
41+
}
42+
}
43+
// #[inline]
44+
// //todo
45+
// pub fn degree_to_radius(d: i16) -> f32 {
46+
// (d as f32) * PI / 180.0
47+
// }

0 commit comments

Comments
 (0)