mirror of
https://github.com/lexmount/moli.git
synced 2026-11-18 16:08:37 +00:00
81 lines
2.5 KiB
Rust
81 lines
2.5 KiB
Rust
use crate::{dom_quad, dom_rect, geometry as geometry_runtime};
|
|
|
|
#[derive(Clone, Copy, Debug)]
|
|
pub enum GeometryClonePayload {
|
|
Point {
|
|
mutable: bool,
|
|
values: [f64; 4],
|
|
},
|
|
Rect {
|
|
mutable: bool,
|
|
values: [f64; 4],
|
|
},
|
|
Quad {
|
|
points: [[f64; 4]; 4],
|
|
},
|
|
Matrix {
|
|
mutable: bool,
|
|
is_2d: bool,
|
|
values: [f64; 16],
|
|
},
|
|
}
|
|
|
|
pub fn geometry_clone_payload_from_object<'s>(
|
|
scope: &mut v8::PinScope<'s, '_>,
|
|
object: v8::Local<'s, v8::Object>,
|
|
) -> Option<GeometryClonePayload> {
|
|
let object = moli_webapi_declare::web_api_object_target(scope, object)?;
|
|
if let Some((mutable, values)) = geometry_runtime::dom_point_clone_data(scope, object) {
|
|
return Some(GeometryClonePayload::Point { mutable, values });
|
|
}
|
|
if let Some((mutable, values)) = dom_rect::dom_rect_clone_data(scope, object) {
|
|
return Some(GeometryClonePayload::Rect { mutable, values });
|
|
}
|
|
if let Some(points) = dom_quad::dom_quad_clone_data(scope, object) {
|
|
return Some(GeometryClonePayload::Quad { points });
|
|
}
|
|
geometry_runtime::dom_matrix_clone_data(scope, object).map(|(mutable, is_2d, values)| {
|
|
GeometryClonePayload::Matrix {
|
|
mutable,
|
|
is_2d,
|
|
values,
|
|
}
|
|
})
|
|
}
|
|
|
|
pub fn build_geometry_object_from_clone_payload<'s>(
|
|
scope: &mut v8::PinScope<'s, '_>,
|
|
payload: GeometryClonePayload,
|
|
) -> v8::Local<'s, v8::Object> {
|
|
match payload {
|
|
GeometryClonePayload::Point { mutable, values } => {
|
|
geometry_runtime::build_dom_point_clone_object(scope, mutable, values)
|
|
}
|
|
GeometryClonePayload::Rect { mutable, values } => {
|
|
dom_rect::build_dom_rect_clone_object(scope, mutable, values)
|
|
}
|
|
GeometryClonePayload::Quad { points } => {
|
|
dom_quad::build_dom_quad_clone_object(scope, points)
|
|
}
|
|
GeometryClonePayload::Matrix {
|
|
mutable,
|
|
is_2d,
|
|
values,
|
|
} => geometry_runtime::build_dom_matrix_clone_object(scope, mutable, is_2d, values),
|
|
}
|
|
}
|
|
|
|
pub fn geometry_quad_clone_points<'s>(
|
|
scope: &mut v8::PinScope<'s, '_>,
|
|
object: v8::Local<'s, v8::Object>,
|
|
) -> Option<[v8::Local<'s, v8::Object>; 4]> {
|
|
dom_quad::dom_quad_points(scope, object)
|
|
}
|
|
|
|
pub fn build_geometry_quad_from_cloned_points<'s>(
|
|
scope: &mut v8::PinScope<'s, '_>,
|
|
points: [v8::Local<'s, v8::Object>; 4],
|
|
) -> v8::Local<'s, v8::Object> {
|
|
dom_quad::build_dom_quad_from_cloned_points(scope, points)
|
|
}
|