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

Method transform_position

src/transform.rs:206–221  ·  view source on GitHub ↗

Convert a value into a normalized `[0, 1]` position along an axis. Data-coordinate transforms use `axis_range` as raw data coordinates. Axes-coordinate transforms already store normalized positions.

(
        &self,
        pos: f64,
        axis_scale: AxisScale,
        axis_range: [f64; 2],
    )

Source from the content-addressed store, hash-verified

204 /// Data-coordinate transforms use `axis_range` as raw data coordinates.
205 /// Axes-coordinate transforms already store normalized positions.
206 pub fn transform_position(
207 &self,
208 pos: f64,
209 axis_scale: AxisScale,
210 axis_range: [f64; 2],
211 ) -> Option<f64> {
212 if self.coordinate_system == CoordinateSystem::Axes {
213 return self.transform_value(pos);
214 }
215
216 let pos = self.transform_data(pos, axis_scale)?;
217 let min = self.transform_data(axis_range[0], axis_scale)?;
218 let max = self.transform_data(axis_range[1], axis_scale)?;
219 let span = max - min;
220 (span.is_finite() && span.abs() > f64::EPSILON).then_some((pos - min) / span)
221 }
222
223 pub(crate) fn uses_axes_coordinates(&self) -> bool {
224 self.coordinate_system == CoordinateSystem::Axes

Callers

nothing calls this directly

Calls 2

transform_valueMethod · 0.80
transform_dataMethod · 0.80

Tested by

no test coverage detected