MCPcopy Create free account
hub / github.com/eliotbo/bevy_plot / plot_segments

Function plot_segments

src/segments/segments.rs:86–224  ·  view source on GitHub ↗
(
    commands: &mut Commands,
    meshes: &mut ResMut<Assets<Mesh>>,
    segment_materials: &mut ResMut<Assets<SegmentUniform>>,
    plot: &mut Plot,
    plot_handle: &Handle<Plot>,
)

Source from the content-addressed store, hash-verified

84}
85
86fn plot_segments(
87 commands: &mut Commands,
88 meshes: &mut ResMut<Assets<Mesh>>,
89 segment_materials: &mut ResMut<Assets<SegmentUniform>>,
90 plot: &mut Plot,
91 plot_handle: &Handle<Plot>,
92) {
93 let data = plot.data.clone();
94 plot.compute_zeros();
95
96 for segment_plot in data.segment_groups.iter() {
97 let ys = segment_plot.data.clone();
98
99 // TODO: is this still needed?
100 // derivatives and normals
101 let (_dfs, _ns) = make_df(&ys);
102
103 let num_pts = ys.len();
104
105 let ys_world = ys.iter().map(|y| plot.to_local(*y)).collect::<Vec<Vec2>>();
106
107 let mut mesh0 = Vec::new();
108 let mut mesh_attr_uvs = Vec::new();
109 let mut inds = Vec::new();
110 let mut ends = Vec::new();
111 let mut mesh_attr_controls: Vec<[f32; 4]> = Vec::new();
112
113 let line_width = 5.0;
114 for k in 0..num_pts - 1 {
115 let y0 = ys_world[k];
116 let y1 = ys_world[k + 1];
117
118 let dy = (y1 - y0).normalize();
119 let n = Vec2::new(-dy.y, dy.x);
120
121 // // short segments
122 // let mut p0 = y0 + n * line_width;
123 // let mut p1 = y0 - n * line_width;
124 // let mut p2 = y1 + n * line_width;
125 // let mut p3 = y1 - n * line_width;
126
127 // if segment_plot.mech {
128 // p0 = y0 + n * line_width - dy * line_width * 1.0;
129 // p1 = y0 - n * line_width - dy * line_width * 1.0;
130 // p2 = y1 + n * line_width + dy * line_width * 1.0;
131 // p3 = y1 - n * line_width + dy * line_width * 1.0;
132 // }
133
134 // overlapping segments
135 let p0 = y0 + n * line_width - dy * line_width * 1.0;
136 let p1 = y0 - n * line_width - dy * line_width * 1.0;
137 let p2 = y1 + n * line_width + dy * line_width * 1.0;
138 let p3 = y1 - n * line_width + dy * line_width * 1.0;
139
140 mesh0.push(p0);
141 mesh0.push(p1);
142 mesh0.push(p2);
143 mesh0.push(p3);

Callers 1

segments_setupFunction · 0.70

Calls 6

col_to_vec4Function · 0.85
compute_zerosMethod · 0.80
to_localMethod · 0.80
addMethod · 0.80
insertMethod · 0.80
make_dfFunction · 0.70

Tested by

no test coverage detected