skia_safe/core/
cubic_map.rs

1use crate::prelude::*;
2use crate::{scalar, Point, Scalar};
3use skia_bindings as sb;
4use skia_bindings::SkCubicMap;
5
6#[derive(Copy, Clone, Debug)]
7#[repr(transparent)]
8pub struct CubicMap(SkCubicMap);
9
10native_transmutable!(SkCubicMap, CubicMap, cubic_map_layout);
11
12impl CubicMap {
13    pub fn new(p1: impl Into<Point>, p2: impl Into<Point>) -> Self {
14        Self::from_native_c(unsafe {
15            SkCubicMap::new(p1.into().into_native(), p2.into().into_native())
16        })
17    }
18
19    pub fn is_linear(p1: impl Into<Point>, p2: impl Into<Point>) -> bool {
20        let p1 = p1.into();
21        let p2 = p2.into();
22        scalar::nearly_equal(p1.x, p1.y, None) && scalar::nearly_equal(p2.x, p2.y, None)
23    }
24
25    pub fn compute_y_from_x(&self, x: f32) -> f32 {
26        unsafe { self.native().computeYFromX(x) }
27    }
28
29    pub fn compute_from_t(&self, t: f32) -> Point {
30        Point::from_native_c(unsafe { sb::C_SkCubicMap_computeFromT(self.native(), t) })
31    }
32}
33
34#[test]
35fn construct_cubic_map() {
36    let _ = CubicMap::new((10, 10), (100, 100));
37}
38
39#[test]
40fn test_compute_from_t() {
41    let cm = CubicMap::new((10, 10), (100, 100));
42    let _p = cm.compute_from_t(0.5);
43}