| 1 | use crate::prelude::*; |
| 2 | use crate::{scalar, Point, Scalar}; |
| 3 | use skia_bindings as sb; |
| 4 | use skia_bindings::SkCubicMap; |
| 5 | |
| 6 | #[derive (Copy, Clone, Debug)] |
| 7 | #[repr (transparent)] |
| 8 | pub struct CubicMap(SkCubicMap); |
| 9 | |
| 10 | native_transmutable!(SkCubicMap, CubicMap, cubic_map_layout); |
| 11 | |
| 12 | impl CubicMap { |
| 13 | pub fn new(p1: impl Into<Point>, p2: impl Into<Point>) -> Self { |
| 14 | Self::from_native_c(nt: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, tolerance:None) && scalar::nearly_equal(p2.x, p2.y, tolerance: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(nt:unsafe { sb::C_SkCubicMap_computeFromT(self.native(), t) }) |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | #[test ] |
| 35 | fn construct_cubic_map() { |
| 36 | let _ = CubicMap::new((10, 10), (100, 100)); |
| 37 | } |
| 38 | |
| 39 | #[test ] |
| 40 | fn test_compute_from_t() { |
| 41 | let cm = CubicMap::new((10, 10), (100, 100)); |
| 42 | let _p = cm.compute_from_t(0.5); |
| 43 | } |
| 44 | |