MCPcopy Create free account
hub / github.com/donkeyteethUX/iced_plot / update

Method update

src/grid.rs:96–184  ·  view source on GitHub ↗
(&mut self, device: &Device, state: &PlotState)

Source from the content-addressed store, hash-verified

94 }
95
96 pub(crate) fn update(&mut self, device: &Device, state: &PlotState) {
97 let camera = &state.camera;
98
99 if camera.position == self.last_center
100 && camera.half_extents == self.last_extents
101 && state.grid_style == self.last_style
102 {
103 return;
104 }
105
106 self.last_center = camera.position;
107 self.last_extents = camera.half_extents;
108 self.last_style = state.grid_style;
109
110 // Calculate bounds in render space (world - offset) for line endpoints
111 let render_center = camera.effective_position();
112 let min_x = render_center.x - camera.half_extents.x;
113 let max_x = render_center.x + camera.half_extents.x;
114 let min_y = render_center.y - camera.half_extents.y;
115 let max_y = render_center.y + camera.half_extents.y;
116
117 let mut verts = Vec::new();
118 let mut count = 0u32;
119
120 // Build vertical lines from precomputed x ticks
121 let width = state.bounds.width.max(1.0);
122 let height = state.bounds.height.max(1.0);
123 for positioned_tick in &state.x_ticks {
124 let ndc_x = (positioned_tick.screen_pos / width) as f64 * 2.0 - 1.0;
125 let render_x = render_center.x + ndc_x * camera.half_extents.x;
126 let color = match positioned_tick.tick.line_type {
127 TickWeight::Major => state.grid_style.major,
128 TickWeight::Minor => state.grid_style.minor,
129 TickWeight::SubMinor => state.grid_style.sub_minor,
130 };
131 verts.extend_from_slice(&[
132 render_x as f32,
133 min_y as f32,
134 color.r,
135 color.g,
136 color.b,
137 color.a,
138 ]);
139 verts.extend_from_slice(&[
140 render_x as f32,
141 max_y as f32,
142 color.r,
143 color.g,
144 color.b,
145 color.a,
146 ]);
147 count += 2;
148 }
149
150 // Build horizontal lines from precomputed y ticks
151 for positioned_tick in &state.y_ticks {
152 let ndc_y = 1.0 - (positioned_tick.screen_pos / height) as f64 * 2.0;
153 let render_y = render_center.y + ndc_y * camera.half_extents.y;

Callers 2

prepare_frameMethod · 0.45

Calls 2

effective_positionMethod · 0.80
newFunction · 0.50

Tested by

no test coverage detected