1use js_sys::{Array, Function, Map, Reflect};
2use wasm_bindgen::prelude::*;
3
4use crate::colors::{Color, GradientImageOrColor, GradientStop, Image, LinearGradient, RadialGradient};
5
6use super::{geometry::{add_tip::{add_both_sides_tips, add_final_tip, add_initial_tip}, arc::{annular_sector, arc, circle, ellipse, elliptical_arc}, dashed_object::dashed_object, line::line, poly::{equilateral_triangle, polygon, rectangle, regular_polygon, right_triangle, square, triangle}}, plotting::{axes::{area_under_curve, axes, contour_plot_in_axes, coords_to_point, parametric_plot_in_axes, plot_in_axes, point_to_coords, riemann_rectangles_for_plot, secant_line_for_plot}, functions::{contour_plot, function, parametric_function}, number_line::{get_numbers_tex, number_line, number_to_point, point_to_number}}, svg_to_vector::svg_to_vector_pin, vector_object::VectorObject};
7
8
9#[wasm_bindgen]
10#[derive(Clone, Debug)]
11pub struct WasmGradientImageOrColor {
12 #[wasm_bindgen(skip)]
13 pub gradient_image_or_color: GradientImageOrColor
14}
15
16
17impl JsCast for WasmGradientImageOrColor {
18 fn instanceof(val: &JsValue) -> bool {
19 Reflect::get(&val, &JsValue::from_str("isColor")).is_ok() &&
21 Reflect::get(&val, &JsValue::from_str("isLinearGradient")).is_ok() &&
22 Reflect::get(&val, &JsValue::from_str("isRadialGradient")).is_ok() &&
23 Reflect::get(&val, &JsValue::from_str("isImage")).is_ok() &&
24 Reflect::get(&val, &JsValue::from_str("getColor")).is_ok() &&
25 Reflect::get(&val, &JsValue::from_str("getLinearGradient")).is_ok() &&
26 Reflect::get(&val, &JsValue::from_str("getRadialGradient")).is_ok() &&
27 Reflect::get(&val, &JsValue::from_str("getImage")).is_ok()
28 }
29 fn unchecked_from_js(val: JsValue) -> Self {
30 let is_color_func = Reflect::get(&val, &JsValue::from_str("isColor")).unwrap();
31 let is_linear_gradient_func = Reflect::get(&val, &JsValue::from_str("isLinearGradient")).unwrap();
32 let is_radial_gradient_func = Reflect::get(&val, &JsValue::from_str("isRadialGradient")).unwrap();
33 if Function::from(is_color_func).call0(&val).unwrap().as_bool().unwrap() {
34 let get_color_func = Reflect::get(&val, &JsValue::from_str("getColor")).unwrap();
35 let color = Function::from(get_color_func).call0(&val).unwrap();
36 let get_r_func = Reflect::get(&color, &JsValue::from_str("getR")).unwrap();
37 let get_g_func = Reflect::get(&color, &JsValue::from_str("getG")).unwrap();
38 let get_b_func = Reflect::get(&color, &JsValue::from_str("getB")).unwrap();
39 let get_a_func = Reflect::get(&color, &JsValue::from_str("getA")).unwrap();
40 let r = Function::from(get_r_func).call0(&color).unwrap().as_f64().unwrap();
41 let g = Function::from(get_g_func).call0(&color).unwrap().as_f64().unwrap();
42 let b = Function::from(get_b_func).call0(&color).unwrap().as_f64().unwrap();
43 let a = Function::from(get_a_func).call0(&color).unwrap().as_f64().unwrap();
44 return WasmGradientImageOrColor {
45 gradient_image_or_color: GradientImageOrColor::Color(Color { red: r, green: g, blue: b, alpha: a })
46 };
47 } else if Function::from(is_linear_gradient_func).call0(&val).unwrap().as_bool().unwrap() {
48 let get_linear_gradient_func = Reflect::get(&val, &JsValue::from_str("getLinearGradient")).unwrap();
49 let linear_gradient = Function::from(get_linear_gradient_func).call0(&val).unwrap();
50 let get_x1_func = Reflect::get(&linear_gradient, &JsValue::from_str("getX1")).unwrap();
51 let get_y1_func = Reflect::get(&linear_gradient, &JsValue::from_str("getY1")).unwrap();
52 let get_x2_func = Reflect::get(&linear_gradient, &JsValue::from_str("getX2")).unwrap();
53 let get_y2_func = Reflect::get(&linear_gradient, &JsValue::from_str("getY2")).unwrap();
54 let get_stops_func = Reflect::get(&linear_gradient, &JsValue::from_str("getStops")).unwrap();
55 let get_alpha_func = Reflect::get(&linear_gradient, &JsValue::from_str("getAlpha")).unwrap();
56 let x1 = Function::from(get_x1_func).call0(&linear_gradient).unwrap().as_f64().unwrap();
57 let y1 = Function::from(get_y1_func).call0(&linear_gradient).unwrap().as_f64().unwrap();
58 let x2 = Function::from(get_x2_func).call0(&linear_gradient).unwrap().as_f64().unwrap();
59 let y2 = Function::from(get_y2_func).call0(&linear_gradient).unwrap().as_f64().unwrap();
60 let stops = Function::from(get_stops_func).call0(&linear_gradient).unwrap();
61 let stops = Array::from(&stops);
62 let stops = stops.iter().map(|stop| {
63 let stop = stop.dyn_into::<WasmGradientStop>().unwrap();
64 stop.stop
65 }).collect();
66 let alpha = Function::from(get_alpha_func).call0(&linear_gradient).unwrap().as_f64().unwrap();
67 return WasmGradientImageOrColor {
68 gradient_image_or_color: GradientImageOrColor::LinearGradient(LinearGradient { x1, y1, x2, y2, stops, alpha })
69 };
70 } else if Function::from(is_radial_gradient_func).call0(&val).unwrap().as_bool().unwrap() {
71 let get_radial_gradient_func = Reflect::get(&val, &JsValue::from_str("getRadialGradient")).unwrap();
72 let radial_gradient = Function::from(get_radial_gradient_func).call0(&val).unwrap();
73 let get_cx_func = Reflect::get(&radial_gradient, &JsValue::from_str("getCx")).unwrap();
74 let get_cy_func = Reflect::get(&radial_gradient, &JsValue::from_str("getCy")).unwrap();
75 let get_r_func = Reflect::get(&radial_gradient, &JsValue::from_str("getR")).unwrap();
76 let get_fx_func = Reflect::get(&radial_gradient, &JsValue::from_str("getFx")).unwrap();
77 let get_fy_func = Reflect::get(&radial_gradient, &JsValue::from_str("getFy")).unwrap();
78 let get_stops_func = Reflect::get(&radial_gradient, &JsValue::from_str("getStops")).unwrap();
79 let get_alpha_func = Reflect::get(&radial_gradient, &JsValue::from_str("getAlpha")).unwrap();
80 let cx = Function::from(get_cx_func).call0(&radial_gradient).unwrap().as_f64().unwrap();
81 let cy = Function::from(get_cy_func).call0(&radial_gradient).unwrap().as_f64().unwrap();
82 let r = Function::from(get_r_func).call0(&radial_gradient).unwrap().as_f64().unwrap();
83 let fx = Function::from(get_fx_func).call0(&radial_gradient).unwrap().as_f64().unwrap();
84 let fy = Function::from(get_fy_func).call0(&radial_gradient).unwrap().as_f64().unwrap();
85 let stops = Function::from(get_stops_func).call0(&radial_gradient).unwrap();
86 let stops = Array::from(&stops);
87 let stops = stops.iter().map(|stop| {
88 let stop = stop.dyn_into::<WasmGradientStop>().unwrap();
89 stop.stop
90 }).collect();
91 let alpha = Function::from(get_alpha_func).call0(&radial_gradient).unwrap().as_f64().unwrap();
92 return WasmGradientImageOrColor {
93 gradient_image_or_color: GradientImageOrColor::RadialGradient(RadialGradient { cx, cy, r, fx, fy, stops, alpha })
94 };
95 }
96 let get_image_func = Reflect::get(&val, &JsValue::from_str("getImage")).unwrap();
97 let image = Function::from(get_image_func).call0(&val).unwrap();
98 let get_image_base64_func = Reflect::get(&image, &JsValue::from_str("getImageBase64")).unwrap();
99 let image_base64 = Function::from(get_image_base64_func).call0(&image).unwrap().as_string().unwrap();
100 let get_mime_type_func = Reflect::get(&image, &JsValue::from_str("getMimeType")).unwrap();
101 let mime_type = Function::from(get_mime_type_func).call0(&image).unwrap().as_string().unwrap();
102 let get_top_func = Reflect::get(&image, &JsValue::from_str("getTop")).unwrap();
103 let get_left_func = Reflect::get(&image, &JsValue::from_str("getLeft")).unwrap();
104 let get_bottom_func = Reflect::get(&image, &JsValue::from_str("getBottom")).unwrap();
105 let get_right_func = Reflect::get(&image, &JsValue::from_str("getRight")).unwrap();
106 let get_alpha_func = Reflect::get(&image, &JsValue::from_str("getAlpha")).unwrap();
107 let top = Function::from(get_top_func).call0(&image).unwrap().as_f64().unwrap();
108 let left = Function::from(get_left_func).call0(&image).unwrap().as_f64().unwrap();
109 let bottom = Function::from(get_bottom_func).call0(&image).unwrap().as_f64().unwrap();
110 let right = Function::from(get_right_func).call0(&image).unwrap().as_f64().unwrap();
111 let alpha = Function::from(get_alpha_func).call0(&image).unwrap().as_f64().unwrap();
112 WasmGradientImageOrColor {
113 gradient_image_or_color: GradientImageOrColor::Image(Image { image_base64, mime_type, top_left_corner: (left, top), bottom_right_corner: (right, bottom), alpha })
114 }
115 }
116 fn unchecked_from_js_ref(val: &JsValue) -> &Self {
117 &val.unchecked_ref::<WasmGradientImageOrColor>()
118 }
119}
120
121
122impl AsRef<JsValue> for WasmGradientImageOrColor {
123 fn as_ref(&self) -> &JsValue {
124 self.unchecked_ref()
125 }
126}
127
128
129#[wasm_bindgen]
130impl WasmGradientImageOrColor {
131 #[wasm_bindgen(js_name = fromColor)]
132 pub fn from_color(color: WasmColor) -> WasmGradientImageOrColor {
133 WasmGradientImageOrColor {
134 gradient_image_or_color: GradientImageOrColor::Color(color.color)
135 }
136 }
137 #[wasm_bindgen(js_name = fromLinearGradient)]
138 pub fn from_linear_gradient(linear_gradient: WasmLinearGradient) -> WasmGradientImageOrColor {
139 WasmGradientImageOrColor {
140 gradient_image_or_color: GradientImageOrColor::LinearGradient(linear_gradient.linear_gradient)
141 }
142 }
143 #[wasm_bindgen(js_name = fromRadialGradient)]
144 pub fn from_radial_gradient(radial_gradient: WasmRadialGradient) -> WasmGradientImageOrColor {
145 WasmGradientImageOrColor {
146 gradient_image_or_color: GradientImageOrColor::RadialGradient(radial_gradient.radial_gradient)
147 }
148 }
149 #[wasm_bindgen(js_name = fromImage)]
150 pub fn from_image(image: WasmImage) -> WasmGradientImageOrColor {
151 WasmGradientImageOrColor {
152 gradient_image_or_color: GradientImageOrColor::Image(image.image)
153 }
154 }
155 #[wasm_bindgen(js_name = isColor)]
156 pub fn is_color(&self) -> bool {
157 match &self.gradient_image_or_color {
158 GradientImageOrColor::Color(_) => true,
159 _ => false
160 }
161 }
162 #[wasm_bindgen(js_name = isLinearGradient)]
163 pub fn is_linear_gradient(&self) -> bool {
164 match &self.gradient_image_or_color {
165 GradientImageOrColor::LinearGradient(_) => true,
166 _ => false
167 }
168 }
169 #[wasm_bindgen(js_name = isRadialGradient)]
170 pub fn is_radial_gradient(&self) -> bool {
171 match &self.gradient_image_or_color {
172 GradientImageOrColor::RadialGradient(_) => true,
173 _ => false
174 }
175 }
176 #[wasm_bindgen(js_name = isImage)]
177 pub fn is_image(&self) -> bool {
178 match &self.gradient_image_or_color {
179 GradientImageOrColor::Image(_) => true,
180 _ => false
181 }
182 }
183 #[wasm_bindgen(js_name = getColor)]
184 pub fn get_color(&self) -> Option<WasmColor> {
185 match &self.gradient_image_or_color {
186 GradientImageOrColor::Color(color) => Some(WasmColor { color: color.clone() }),
187 _ => None
188 }
189 }
190 #[wasm_bindgen(js_name = getLinearGradient)]
191 pub fn get_linear_gradient(&self) -> Option<WasmLinearGradient> {
192 match &self.gradient_image_or_color {
193 GradientImageOrColor::LinearGradient(linear_gradient) => Some(WasmLinearGradient { linear_gradient: linear_gradient.clone() }),
194 _ => None
195 }
196 }
197 #[wasm_bindgen(js_name = getRadialGradient)]
198 pub fn get_radial_gradient(&self) -> Option<WasmRadialGradient> {
199 match &self.gradient_image_or_color {
200 GradientImageOrColor::RadialGradient(radial_gradient) => Some(WasmRadialGradient { radial_gradient: radial_gradient.clone() }),
201 _ => None
202 }
203 }
204 #[wasm_bindgen(js_name = getImage)]
205 pub fn get_image(&self) -> Option<WasmImage> {
206 match &self.gradient_image_or_color {
207 GradientImageOrColor::Image(image) => Some(WasmImage { image: image.clone() }),
208 _ => None
209 }
210 }
211 #[wasm_bindgen(js_name = clone)]
212 pub fn clone_js(&self) -> WasmGradientImageOrColor {
213 self.clone()
214 }
215}
216
217
218#[wasm_bindgen]
219#[derive(Clone, Debug)]
220pub struct WasmColor {
221 #[wasm_bindgen(skip)]
222 pub color: Color,
223}
224
225
226impl JsCast for WasmColor {
227 fn instanceof(val: &JsValue) -> bool {
228 Reflect::get(&val, &JsValue::from_str("getR")).is_ok() &&
230 Reflect::get(&val, &JsValue::from_str("getG")).is_ok() &&
231 Reflect::get(&val, &JsValue::from_str("getB")).is_ok() &&
232 Reflect::get(&val, &JsValue::from_str("getA")).is_ok()
233 }
234 fn unchecked_from_js(val: JsValue) -> Self {
235 let get_r_func = Reflect::get(&val, &JsValue::from_str("getR")).unwrap();
236 let get_g_func = Reflect::get(&val, &JsValue::from_str("getG")).unwrap();
237 let get_b_func = Reflect::get(&val, &JsValue::from_str("getB")).unwrap();
238 let get_a_func = Reflect::get(&val, &JsValue::from_str("getA")).unwrap();
239 let r = Function::from(get_r_func).call0(&val).unwrap().as_f64().unwrap();
240 let g = Function::from(get_g_func).call0(&val).unwrap().as_f64().unwrap();
241 let b = Function::from(get_b_func).call0(&val).unwrap().as_f64().unwrap();
242 let a = Function::from(get_a_func).call0(&val).unwrap().as_f64().unwrap();
243 WasmColor {
244 color: Color { red: r, green: g, blue: b, alpha: a }
245 }
246 }
247 fn unchecked_from_js_ref(val: &JsValue) -> &Self {
248 &val.unchecked_ref::<WasmColor>()
249 }
250}
251
252
253impl AsRef<JsValue> for WasmColor {
254 fn as_ref(&self) -> &JsValue {
255 self.unchecked_ref()
256 }
257}
258
259
260#[wasm_bindgen]
261impl WasmColor {
262 #[wasm_bindgen(constructor)]
263 pub fn new(r: f64, g: f64, b: f64, a: f64) -> WasmColor {
264 WasmColor {
265 color: Color { red: r, green: g, blue: b, alpha: a }
266 }
267 }
268 #[wasm_bindgen(js_name = getR)]
269 pub fn get_r(&self) -> f64 {
270 self.color.red
271 }
272 #[wasm_bindgen(js_name = getG)]
273 pub fn get_g(&self) -> f64 {
274 self.color.green
275 }
276 #[wasm_bindgen(js_name = getB)]
277 pub fn get_b(&self) -> f64 {
278 self.color.blue
279 }
280 #[wasm_bindgen(js_name = getA)]
281 pub fn get_a(&self) -> f64 {
282 self.color.alpha
283 }
284}
285
286
287#[wasm_bindgen]
288#[derive(Clone, Debug)]
289pub struct WasmGradientStop {
290 stop: GradientStop
291}
292
293
294impl JsCast for WasmGradientStop {
295 fn instanceof(val: &JsValue) -> bool {
296 Reflect::get(&val, &JsValue::from_str("getOffset")).is_ok() &&
298 Reflect::get(&val, &JsValue::from_str("getColor")).is_ok()
299 }
300 fn unchecked_from_js(val: JsValue) -> Self {
301 let get_offset_func = Reflect::get(&val, &JsValue::from_str("getOffset")).unwrap();
302 let get_color_func = Reflect::get(&val, &JsValue::from_str("getColor")).unwrap();
303 let offset = Function::from(get_offset_func).call0(&val).unwrap().as_f64().unwrap();
304 let color = Function::from(get_color_func).call0(&val).unwrap();
305 let get_r_func = Reflect::get(&color, &JsValue::from_str("getR")).unwrap();
306 let get_g_func = Reflect::get(&color, &JsValue::from_str("getG")).unwrap();
307 let get_b_func = Reflect::get(&color, &JsValue::from_str("getB")).unwrap();
308 let get_a_func = Reflect::get(&color, &JsValue::from_str("getA")).unwrap();
309 let r = Function::from(get_r_func).call0(&color).unwrap().as_f64().unwrap();
310 let g = Function::from(get_g_func).call0(&color).unwrap().as_f64().unwrap();
311 let b = Function::from(get_b_func).call0(&color).unwrap().as_f64().unwrap();
312 let a = Function::from(get_a_func).call0(&color).unwrap().as_f64().unwrap();
313 WasmGradientStop {
314 stop: GradientStop { offset, color: Color { red: r, green: g, blue: b, alpha: a } }
315 }
316 }
317 fn unchecked_from_js_ref(val: &JsValue) -> &Self {
318 &val.unchecked_ref::<WasmGradientStop>()
319 }
320}
321
322
323impl AsRef<JsValue> for WasmGradientStop {
324 fn as_ref(&self) -> &JsValue {
325 self.unchecked_ref()
326 }
327}
328
329
330#[wasm_bindgen]
331impl WasmGradientStop {
332 #[wasm_bindgen(constructor)]
333 pub fn new(offset: f64, color: WasmColor) -> WasmGradientStop {
334 WasmGradientStop {
335 stop: GradientStop { offset, color: color.color }
336 }
337 }
338 #[wasm_bindgen(js_name = getOffset)]
339 pub fn get_offset(&self) -> f64 {
340 self.stop.offset
341 }
342 #[wasm_bindgen(js_name = getColor)]
343 pub fn get_color(&self) -> WasmColor {
344 WasmColor { color: self.stop.color.clone() }
345 }
346}
347
348
349#[wasm_bindgen]
350#[derive(Clone, Debug)]
351pub struct WasmLinearGradient {
352 linear_gradient: LinearGradient
353}
354
355
356#[wasm_bindgen]
357impl WasmLinearGradient {
358 #[wasm_bindgen(constructor)]
359 pub fn new(
360 x1: f64,
361 y1: f64,
362 x2: f64,
363 y2: f64,
364 stops: Vec<WasmGradientStop>,
365 alpha: f64
366 ) -> WasmLinearGradient {
367 WasmLinearGradient {
368 linear_gradient: LinearGradient {
369 x1,
370 x2,
371 y1,
372 y2,
373 stops: stops.iter().map(|stop| stop.stop.clone()).collect(),
374 alpha: alpha
375 }
376 }
377 }
378 #[wasm_bindgen(js_name = getX1)]
379 pub fn get_x1(&self) -> f64 {
380 self.linear_gradient.x1
381 }
382 #[wasm_bindgen(js_name = getY1)]
383 pub fn get_y1(&self) -> f64 {
384 self.linear_gradient.y1
385 }
386 #[wasm_bindgen(js_name = getX2)]
387 pub fn get_x2(&self) -> f64 {
388 self.linear_gradient.x2
389 }
390 #[wasm_bindgen(js_name = getY2)]
391 pub fn get_y2(&self) -> f64 {
392 self.linear_gradient.y2
393 }
394 #[wasm_bindgen(js_name = getStops)]
395 pub fn get_stops(&self) -> Vec<WasmGradientStop> {
396 let stops = self.linear_gradient.stops.iter().map(|stop| WasmGradientStop { stop: stop.clone() }).collect();
397 stops
398 }
399 #[wasm_bindgen(js_name = getAlpha)]
400 pub fn get_alpha(&self) -> f64 {
401 self.linear_gradient.alpha
402 }
403}
404
405
406#[wasm_bindgen]
407#[derive(Clone, Debug)]
408pub struct WasmRadialGradient {
409 radial_gradient: RadialGradient
410}
411
412
413#[wasm_bindgen]
414impl WasmRadialGradient {
415 #[wasm_bindgen(constructor)]
416 pub fn new(
417 cx: f64,
418 cy: f64,
419 r: f64,
420 fx: f64,
421 fy: f64,
422 stops: Vec<WasmGradientStop>,
423 alpha: f64
424 ) -> WasmRadialGradient {
425 WasmRadialGradient {
426 radial_gradient: RadialGradient {
427 cx,
428 cy,
429 r,
430 fx,
431 fy,
432 stops: stops.iter().map(|stop| stop.stop.clone()).collect(),
433 alpha: alpha
434 }
435 }
436 }
437 #[wasm_bindgen(js_name = getCx)]
438 pub fn get_cx(&self) -> f64 {
439 self.radial_gradient.cx
440 }
441 #[wasm_bindgen(js_name = getCy)]
442 pub fn get_cy(&self) -> f64 {
443 self.radial_gradient.cy
444 }
445 #[wasm_bindgen(js_name = getR)]
446 pub fn get_r(&self) -> f64 {
447 self.radial_gradient.r
448 }
449 #[wasm_bindgen(js_name = getFx)]
450 pub fn get_fx(&self) -> f64 {
451 self.radial_gradient.fx
452 }
453 #[wasm_bindgen(js_name = getFy)]
454 pub fn get_fy(&self) -> f64 {
455 self.radial_gradient.fy
456 }
457 #[wasm_bindgen(js_name = getStops)]
458 pub fn get_stops(&self) -> Vec<WasmGradientStop> {
459 let stops = self.radial_gradient.stops.iter().map(|stop| WasmGradientStop { stop: stop.clone() }).collect();
460 stops
461 }
462 #[wasm_bindgen(js_name = getAlpha)]
463 pub fn get_alpha(&self) -> f64 {
464 self.radial_gradient.alpha
465 }
466}
467
468
469#[wasm_bindgen]
470#[derive(Clone, Debug)]
471pub struct WasmImage {
472 image: Image
473}
474
475
476#[wasm_bindgen]
477impl WasmImage {
478 #[wasm_bindgen(constructor)]
479 pub fn new(
480 image_base64: String,
481 mime_type: String,
482 top: f64,
483 left: f64,
484 bottom: f64,
485 right: f64,
486 alpha: f64
487 ) -> WasmImage {
488 let top_left_corner = (left, top);
489 let bottom_right_corner = (right, bottom);
490 WasmImage {
491 image: Image {
492 image_base64,
493 mime_type,
494 top_left_corner,
495 bottom_right_corner,
496 alpha
497 }
498 }
499 }
500 #[wasm_bindgen(js_name = getImageBase64)]
501 pub fn get_image_base64(&self) -> String {
502 self.image.image_base64.clone()
503 }
504 #[wasm_bindgen(js_name = getMimeType)]
505 pub fn get_mime_type(&self) -> String {
506 self.image.mime_type.clone()
507 }
508 #[wasm_bindgen(js_name = getTop)]
509 pub fn get_top(&self) -> f64 {
510 self.image.top_left_corner.1
511 }
512 #[wasm_bindgen(js_name = getLeft)]
513 pub fn get_left(&self) -> f64 {
514 self.image.top_left_corner.0
515 }
516 #[wasm_bindgen(js_name = getBottom)]
517 pub fn get_bottom(&self) -> f64 {
518 self.image.bottom_right_corner.1
519 }
520 #[wasm_bindgen(js_name = getRight)]
521 pub fn get_right(&self) -> f64 {
522 self.image.bottom_right_corner.0
523 }
524 #[wasm_bindgen(js_name = getAlpha)]
525 pub fn get_alpha(&self) -> f64 {
526 self.image.alpha
527 }
528}
529
530
531#[wasm_bindgen]
532#[derive(Clone, Debug)]
533pub struct WasmVectorObject {
534 #[wasm_bindgen(skip)]
535 pub native_vec_features: VectorObject
536}
537
538
539#[wasm_bindgen]
540impl WasmVectorObject {
541 #[wasm_bindgen(constructor)]
542 pub fn new() -> WasmVectorObject {
543 WasmVectorObject {
544 native_vec_features: VectorObject::new()
545 }
546 }
547 #[wasm_bindgen(js_name = getIndex)]
548 pub fn get_index(&self) -> usize {
549 self.native_vec_features.get_index()
550 }
551 #[wasm_bindgen(js_name = incrementIndex)]
552 pub fn increment_index(&self, increment: usize, recursive: bool) -> Self {
553 WasmVectorObject {
554 native_vec_features: self.native_vec_features.increment_index(increment, recursive)
555 }
556 }
557 #[wasm_bindgen(js_name = getPoints)]
558 pub fn get_points(&self) -> Array {
559 let points = self.native_vec_features.get_points();
560 let points = points.iter().map(|point| Array::of2(&point.0.into(), &point.1.into())).collect();
561 points
562 }
563 #[wasm_bindgen(js_name = add)]
564 pub fn add(&self, new_subobject: WasmVectorObject) -> Self {
565 WasmVectorObject {
566 native_vec_features: self.native_vec_features.add(&new_subobject.native_vec_features)
567 }
568 }
569 #[wasm_bindgen(js_name = remove)]
570 pub fn remove(&self, index: usize) -> Self {
571 WasmVectorObject {
572 native_vec_features: self.native_vec_features.remove(index)
573 }
574 }
575 #[wasm_bindgen(js_name = getSubobject)]
576 pub fn get_subobject(&self, index: usize) -> WasmVectorObject {
577 WasmVectorObject {
578 native_vec_features: self.native_vec_features.get_subobject(index)
579 }
580 }
581 #[wasm_bindgen(js_name = sliceSubobjects)]
582 pub fn slice_subobjects(&self, start: usize, end: usize) -> Vec<WasmVectorObject> {
583 let subobjects = self.native_vec_features.slice_subobjects(start, end);
584 let subobjects = subobjects.iter().map(|object| WasmVectorObject { native_vec_features: object.clone() }).collect();
585 subobjects
586 }
587 #[wasm_bindgen(js_name = setSubobject)]
588 pub fn set_subobject(&self, index: usize, new_subobject: WasmVectorObject) -> Self {
589 WasmVectorObject {
590 native_vec_features: self.native_vec_features.set_subobject(index, new_subobject.native_vec_features)
591 }
592 }
593 #[wasm_bindgen(js_name = setSliceSubobjects)]
594 pub fn set_slice_subobjects(&self, start: usize, end: usize, new_subobjects: Vec<WasmVectorObject>) -> Self {
595 let new_subobjects = new_subobjects.iter().map(|object| object.native_vec_features.clone()).collect();
596 WasmVectorObject {
597 native_vec_features: self.native_vec_features.set_slice_subobjects(start, end, new_subobjects)
598 }
599 }
600 #[wasm_bindgen(js_name = getFill)]
601 pub fn get_fill(&self) -> WasmGradientImageOrColor {
602 WasmGradientImageOrColor { gradient_image_or_color: self.native_vec_features.get_fill() }
603 }
604 #[wasm_bindgen(js_name = getStroke)]
605 pub fn get_stroke(&self) -> WasmGradientImageOrColor {
606 WasmGradientImageOrColor { gradient_image_or_color: self.native_vec_features.get_stroke() }
607 }
608 #[wasm_bindgen(js_name = getSubobjectsRecursively)]
609 pub fn get_subobjects_recursively(&self, with_points: Option<bool>) -> Vec<WasmVectorObject> {
610 let subobjects = self.native_vec_features.get_subobjects_recursively(with_points);
611 let subobjects = subobjects.iter().map(|object| WasmVectorObject { native_vec_features: object.clone() }).collect();
612 subobjects
613 }
614 #[wasm_bindgen(js_name = getSubcurve)]
615 pub fn get_subcurve(&self, start: f64, end: f64) -> Self {
616 WasmVectorObject {
617 native_vec_features: self.native_vec_features.get_subcurve(start, end)
618 }
619 }
620 #[wasm_bindgen(js_name = getStrokeWidth)]
621 pub fn get_stroke_width(&self) -> f64 {
622 self.native_vec_features.get_stroke_width()
623 }
624 #[wasm_bindgen(js_name = getLineCap)]
625 pub fn get_line_cap(&self) -> String {
626 self.native_vec_features.get_line_cap().to_string()
627 }
628 #[wasm_bindgen(js_name = getLineJoin)]
629 pub fn get_line_join(&self) -> String {
630 self.native_vec_features.get_line_join().to_string()
631 }
632 #[wasm_bindgen(js_name = getPartialCopy)]
633 pub fn get_partial_copy(&self, start: f64, end: f64, recursive: bool) -> Self {
634 WasmVectorObject {
635 native_vec_features: self.native_vec_features.get_partial_copy(start, end, recursive)
636 }
637 }
638 #[wasm_bindgen(js_name = getAnchorsAndHandles)]
639 pub fn get_anchors_and_handles(&self) -> Array {
640 let anchors_and_handles = self.native_vec_features.get_anchors_and_handles();
641 let result = Array::of4(
642 &anchors_and_handles.0.iter().map(|point| Array::of2(&point.0.into(), &point.1.into())).collect::<Array>(),
643 &anchors_and_handles.1.iter().map(|point| Array::of2(&point.0.into(), &point.1.into())).collect::<Array>(),
644 &anchors_and_handles.2.iter().map(|point| Array::of2(&point.0.into(), &point.1.into())).collect::<Array>(),
645 &anchors_and_handles.3.iter().map(|point| Array::of2(&point.0.into(), &point.1.into())).collect::<Array>()
646 );
647 result
648 }
649 #[wasm_bindgen(js_name = scaleHandleToAnchorDistances)]
650 pub fn scale_handle_to_anchor_distances(&self, scale: f64, recursive: bool) -> Self {
651 WasmVectorObject {
652 native_vec_features: self.native_vec_features.scale_handle_to_anchor_distances(scale, recursive)
653 }
654 }
655 #[wasm_bindgen(js_name = setAnchorsAndHandles)]
656 pub fn set_anchors_and_handles(&self, anchors_and_handles: Array) -> Self {
657 let a1 = anchors_and_handles.get(0).dyn_into::<Array>().unwrap();
658 let h1 = anchors_and_handles.get(1).dyn_into::<Array>().unwrap();
659 let h2 = anchors_and_handles.get(2).dyn_into::<Array>().unwrap();
660 let a2 = anchors_and_handles.get(3).dyn_into::<Array>().unwrap();
661 let anchors_and_handles = (
662 a1.iter().map(|point| {
663 let point = point.dyn_into::<Array>().unwrap();
664 (point.get(0).as_f64().unwrap(), point.get(1).as_f64().unwrap())
665 }).collect(),
666 h1.iter().map(|point| {
667 let point = point.dyn_into::<Array>().unwrap();
668 (point.get(0).as_f64().unwrap(), point.get(1).as_f64().unwrap())
669 }).collect(),
670 h2.iter().map(|point| {
671 let point = point.dyn_into::<Array>().unwrap();
672 (point.get(0).as_f64().unwrap(), point.get(1).as_f64().unwrap())
673 }).collect(),
674 a2.iter().map(|point| {
675 let point = point.dyn_into::<Array>().unwrap();
676 (point.get(0).as_f64().unwrap(), point.get(1).as_f64().unwrap())
677 }).collect()
678 );
679 WasmVectorObject {
680 native_vec_features: self.native_vec_features.set_anchors_and_handles(anchors_and_handles)
681 }
682 }
683 #[wasm_bindgen(js_name = getNthCurvePoints)]
684 pub fn get_nth_curve_points(&self, n: usize) -> Array {
685 let points = self.native_vec_features.get_nth_curve_points(n);
686 let points = points.iter().map(|point| Array::of2(&point.0.into(), &point.1.into())).collect();
687 points
688 }
689 #[wasm_bindgen(js_name = getNthCurveLengthPieces)]
690 pub fn get_nth_curve_length_pieces(&self, n: usize, sample_points: Option<usize>) -> Vec<f64> {
691 self.native_vec_features.get_nth_curve_length_pieces(n, sample_points)
692 }
693 #[wasm_bindgen(js_name = getNumCurves)]
694 pub fn get_num_curves(&self) -> usize {
695 self.native_vec_features.get_num_curves()
696 }
697 #[wasm_bindgen(js_name = isClosed)]
698 pub fn is_closed(&self) -> bool {
699 self.native_vec_features.is_closed()
700 }
701 #[wasm_bindgen(js_name = getSubpaths)]
702 pub fn get_subpaths(&self) -> Array {
703 let subpaths = self.native_vec_features.get_subpaths();
704 let subpaths = subpaths.iter().map(|subpath| {
705 let points = subpath.iter().map(|point| Array::of2(&point.0.into(), &point.1.into())).collect::<Array>();
706 points
707 }).collect();
708 subpaths
709 }
710 #[wasm_bindgen(js_name = applyFunction)]
711 pub async fn apply_function(
712 &self,
713 function: js_sys::Function,
714 recursive: bool,
715 about_point: Option<Array>,
716 about_edge: Option<Array>
717 ) -> Self {
718 let about_point = about_point.map(|point| (point.get(0).as_f64().unwrap(), point.get(1).as_f64().unwrap()));
719 let about_edge = about_edge.map(|edge| (edge.get(0).as_f64().unwrap(), edge.get(1).as_f64().unwrap()));
720 WasmVectorObject {
721 native_vec_features: self.native_vec_features.apply_function(
722 function,
723 recursive,
724 about_point,
725 about_edge
726 ).await
727 }
728 }
729 #[wasm_bindgen(js_name = getPieces)]
730 pub fn get_pieces(&self, n_pieces: usize) -> WasmVectorObject {
731 let pieces = self.native_vec_features.get_pieces(n_pieces);
732 WasmVectorObject { native_vec_features: pieces }
733 }
734 #[wasm_bindgen(js_name = getCubicBezierTuples)]
735 pub fn get_cubic_bezier_tuples(&self) -> Array {
736 let cubic_bezier_tuples = self.native_vec_features.get_cubic_bezier_tuples();
737 let cubic_bezier_tuples = cubic_bezier_tuples.iter().map(|tuple| {
738 let point1 = Array::of2(&tuple.0.0.into(), &tuple.0.1.into());
739 let point2 = Array::of2(&tuple.1.0.into(), &tuple.1.1.into());
740 let point3 = Array::of2(&tuple.2.0.into(), &tuple.2.1.into());
741 let point4 = Array::of2(&tuple.3.0.into(), &tuple.3.1.into());
742 Array::of4(&point1, &point2, &point3, &point4)
743 }).collect();
744 cubic_bezier_tuples
745 }
746 #[wasm_bindgen(js_name = getSubobjects)]
747 pub fn get_subobjects(&self) -> Vec<WasmVectorObject> {
748 let subobjects = self.native_vec_features.get_subobjects();
749 let subobjects = subobjects.iter().map(|object| WasmVectorObject { native_vec_features: object.clone() }).collect();
750 subobjects
751 }
752 #[wasm_bindgen(js_name = scale)]
753 pub fn scale(&self, factor: f64, recursive: bool) -> Self {
754 WasmVectorObject {
755 native_vec_features: self.native_vec_features.scale(factor, recursive)
756 }
757 }
758 #[wasm_bindgen(js_name = stretch)]
759 pub fn stretch(&self, x_factor: f64, y_factor: f64, recursive: bool) -> Self {
760 WasmVectorObject {
761 native_vec_features: self.native_vec_features.stretch((x_factor, y_factor), recursive)
762 }
763 }
764 #[wasm_bindgen(js_name = shift)]
765 pub fn shift(&self, x_shift: f64, y_shift: f64, recursive: bool) -> Self {
766 WasmVectorObject {
767 native_vec_features: self.native_vec_features.shift((x_shift, y_shift), recursive)
768 }
769 }
770 #[wasm_bindgen(js_name = mergedPoints)]
771 pub fn merged_points(&self) -> Array {
772 let merged_points = self.native_vec_features.merged_points();
773 let merged_points = merged_points.iter().map(|point| Array::of2(&point.0.into(), &point.1.into())).collect();
774 merged_points
775 }
776 #[wasm_bindgen(js_name = getBoundingBox)]
777 pub fn get_bounding_box(&self) -> Array {
778 let ((min_x, min_y), (max_x, max_y)) = self.native_vec_features.get_bounding_box();
779 let min_point = Array::of2(&min_x.into(), &min_y.into());
780 let max_point = Array::of2(&max_x.into(), &max_y.into());
781 Array::of2(&min_point, &max_point)
782 }
783 #[wasm_bindgen(js_name = getCenter)]
784 pub fn get_center(&self) -> Array {
785 let (center_x, center_y) = self.native_vec_features.get_center();
786 Array::of2(¢er_x.into(), ¢er_y.into())
787 }
788 #[wasm_bindgen(js_name = getCenterOfMass)]
789 pub fn get_center_of_mass(&self) -> Array {
790 let (center_x, center_y) = self.native_vec_features.get_center_of_mass();
791 Array::of2(¢er_x.into(), ¢er_y.into())
792 }
793 #[wasm_bindgen(js_name = getHeight)]
794 pub fn get_height(&self) -> f64 {
795 self.native_vec_features.get_height()
796 }
797 #[wasm_bindgen(js_name = getWidth)]
798 pub fn get_width(&self) -> f64 {
799 self.native_vec_features.get_width()
800 }
801 #[wasm_bindgen(js_name = setIndex)]
802 pub fn set_index(&self, index: usize) -> Self {
803 WasmVectorObject {
804 native_vec_features: self.native_vec_features.set_index(index)
805 }
806 }
807 #[wasm_bindgen(js_name = setFill)]
808 pub fn set_fill(&self, fill: WasmGradientImageOrColor, recursive: bool) -> Self {
809 WasmVectorObject {
810 native_vec_features: self.native_vec_features.set_fill(fill.gradient_image_or_color, recursive)
811 }
812 }
813 #[wasm_bindgen(js_name = setFillOpacity)]
814 pub fn set_fill_opacity(&self, opacity: f64, recursive: bool) -> Self {
815 WasmVectorObject {
816 native_vec_features: self.native_vec_features.set_fill_opacity(opacity, recursive)
817 }
818 }
819 #[wasm_bindgen(js_name = setFillRule)]
820 pub fn set_fill_rule(&self, fill_rule: String, recursive: bool) -> Self {
821 match fill_rule.as_str() {
822 "nonzero" => WasmVectorObject {
823 native_vec_features: self.native_vec_features.set_fill_rule("nonzero", recursive)
824 },
825 "evenodd" => WasmVectorObject {
826 native_vec_features: self.native_vec_features.set_fill_rule("evenodd", recursive)
827 },
828 _ => WasmVectorObject {
829 native_vec_features: self.native_vec_features.set_fill_rule("nonzero", recursive)
830 }
831 }
832 }
833 #[wasm_bindgen(js_name = moveTo)]
834 pub fn move_to(&self, x: f64, y: f64, recursive: bool) -> Self {
835 WasmVectorObject {
836 native_vec_features: self.native_vec_features.move_to((x, y), recursive)
837 }
838 }
839 #[wasm_bindgen(js_name = getFillRule)]
840 pub fn get_fill_rule(&self) -> String {
841 self.native_vec_features.get_fill_rule().to_string()
842 }
843 #[wasm_bindgen(js_name = setStroke)]
844 pub fn set_stroke(&self, stroke: WasmGradientImageOrColor, recursive: bool) -> Self {
845 WasmVectorObject {
846 native_vec_features: self.native_vec_features.set_stroke(stroke.gradient_image_or_color, recursive)
847 }
848 }
849 #[wasm_bindgen(js_name = setStrokeOpacity)]
850 pub fn set_stroke_opacity(&self, opacity: f64, recursive: bool) -> Self {
851 WasmVectorObject {
852 native_vec_features: self.native_vec_features.set_stroke_opacity(opacity, recursive)
853 }
854 }
855 #[wasm_bindgen(js_name = setStrokeWidth)]
856 pub fn set_stroke_width(&self, width: f64, recursive: bool) -> Self {
857 WasmVectorObject {
858 native_vec_features: self.native_vec_features.set_stroke_width(width, recursive)
859 }
860 }
861 #[wasm_bindgen(js_name = setLineCap)]
862 pub fn set_line_cap(&self, line_cap: String, recursive: bool) -> Self {
863 match line_cap.as_str() {
864 "butt" => WasmVectorObject {
865 native_vec_features: self.native_vec_features.set_line_cap("butt", recursive)
866 },
867 "round" => WasmVectorObject {
868 native_vec_features: self.native_vec_features.set_line_cap("round", recursive)
869 },
870 "square" => WasmVectorObject {
871 native_vec_features: self.native_vec_features.set_line_cap("square", recursive)
872 },
873 _ => WasmVectorObject {
874 native_vec_features: self.native_vec_features.set_line_cap("butt", recursive)
875 }
876 }
877 }
878 #[wasm_bindgen(js_name = setLineJoin)]
879 pub fn set_line_join(&self, line_join: String, recursive: bool) -> Self {
880 match line_join.as_str() {
881 "miter" => WasmVectorObject {
882 native_vec_features: self.native_vec_features.set_line_join("miter", recursive)
883 },
884 "round" => WasmVectorObject {
885 native_vec_features: self.native_vec_features.set_line_join("round", recursive)
886 },
887 "bevel" => WasmVectorObject {
888 native_vec_features: self.native_vec_features.set_line_join("bevel", recursive)
889 },
890 _ => WasmVectorObject {
891 native_vec_features: self.native_vec_features.set_line_join("miter", recursive)
892 }
893 }
894 }
895 #[wasm_bindgen(js_name = setPoints)]
896 pub fn set_points(&self, points: Array) -> Self {
897 let points = points.iter().map(|point| {
898 let point = point.dyn_into::<Array>().unwrap();
899 let x = point.get(0).as_f64().unwrap();
900 let y = point.get(1).as_f64().unwrap();
901 (x, y)
902 }).collect();
903 WasmVectorObject {
904 native_vec_features: self.native_vec_features.set_points(points)
905 }
906 }
907 #[wasm_bindgen(js_name = setSubobjects)]
908 pub fn set_subobjects(&self, subobjects: Vec<WasmVectorObject>) -> Self {
909 let subobjects = subobjects.iter().map(|object| object.native_vec_features.clone()).collect();
910 WasmVectorObject {
911 native_vec_features: self.native_vec_features.set_subobjects(subobjects)
912 }
913 }
914 #[wasm_bindgen(js_name = rotate)]
915 pub fn rotate(&self, angle: f64, recursive: bool) -> Self {
916 WasmVectorObject {
917 native_vec_features: self.native_vec_features.rotate(angle, recursive)
918 }
919 }
920 #[wasm_bindgen(js_name = getCriticalPoint)]
921 pub fn get_critical_point(&self, key_x: f64, key_y: f64) -> Array {
922 let (critical_x, critical_y) = self.native_vec_features.get_critical_point((key_x, key_y));
923 Array::of2(&critical_x.into(), &critical_y.into())
924 }
925 #[wasm_bindgen(js_name = getFillOpacity)]
926 pub fn get_fill_opacity(&self) -> f64 {
927 self.native_vec_features.get_fill_opacity()
928 }
929 #[wasm_bindgen(js_name = getStrokeOpacity)]
930 pub fn get_stroke_opacity(&self) -> f64 {
931 self.native_vec_features.get_stroke_opacity()
932 }
933 #[wasm_bindgen(js_name = matchStyle)]
934 pub fn match_style(&self, other: WasmVectorObject) -> Self {
935 WasmVectorObject {
936 native_vec_features: self.native_vec_features.match_style(&other.native_vec_features)
937 }
938 }
939 #[wasm_bindgen(js_name = nextToOther)]
940 pub fn next_to_other(
941 &self,
942 other: WasmVectorObject,
943 direction: Array,
944 buff: f64,
945 aligned_edge: Array,
946 recursive: bool
947 ) -> Self {
948 let direction = (direction.get(0).as_f64().unwrap(), direction.get(1).as_f64().unwrap());
949 let aligned_edge = (aligned_edge.get(0).as_f64().unwrap(), aligned_edge.get(1).as_f64().unwrap());
950 WasmVectorObject {
951 native_vec_features: self.native_vec_features.next_to_other(&other.native_vec_features, direction, buff, aligned_edge, recursive)
952 }
953 }
954 #[wasm_bindgen(js_name = arrangeSubobjects)]
955 pub fn arrange_subobjects(
956 &self,
957 direction: Array,
958 buff: f64,
959 aligned_edge: Array,
960 recursive: bool
961 ) -> Self {
962 let direction = (direction.get(0).as_f64().unwrap(), direction.get(1).as_f64().unwrap());
963 let aligned_edge = (aligned_edge.get(0).as_f64().unwrap(), aligned_edge.get(1).as_f64().unwrap());
964 WasmVectorObject {
965 native_vec_features: self.native_vec_features.arrange_subobjects(direction, buff, aligned_edge, recursive)
966 }
967 }
968 #[wasm_bindgen(js_name = nextToPoint)]
969 pub fn next_to_point(
970 &self,
971 point: Array,
972 direction: Array,
973 buff: f64,
974 aligned_edge: Array,
975 recursive: bool
976 ) -> Self {
977 let point = (point.get(0).as_f64().unwrap(), point.get(1).as_f64().unwrap());
978 let direction = (direction.get(0).as_f64().unwrap(), direction.get(1).as_f64().unwrap());
979 let aligned_edge = (aligned_edge.get(0).as_f64().unwrap(), aligned_edge.get(1).as_f64().unwrap());
980 WasmVectorObject {
981 native_vec_features: self.native_vec_features.next_to_point(point, direction, buff, aligned_edge, recursive)
982 }
983 }
984 #[wasm_bindgen(js_name = clone)]
985 pub fn clone_js(&self) -> Self {
986 self.clone()
987 }
988}
989
990
991impl JsCast for WasmVectorObject {
992 fn instanceof(val: &JsValue) -> bool {
993 Reflect::get(&val, &JsValue::from_str("getPoints")).is_ok() &&
995 Reflect::get(&val, &JsValue::from_str("getFill")).is_ok() &&
996 Reflect::get(&val, &JsValue::from_str("getStroke")).is_ok() &&
997 Reflect::get(&val, &JsValue::from_str("getStrokeWidth")).is_ok() &&
998 Reflect::get(&val, &JsValue::from_str("getLineCap")).is_ok() &&
999 Reflect::get(&val, &JsValue::from_str("getLineJoin")).is_ok() &&
1000 Reflect::get(&val, &JsValue::from_str("getSubobjects")).is_ok() &&
1001 Reflect::get(&val, &JsValue::from_str("getIndex")).is_ok() &&
1002 Reflect::get(&val, &JsValue::from_str("getFillRule")).is_ok()
1003 }
1004 fn unchecked_from_js(val: JsValue) -> Self {
1005 let get_points = Reflect::get(&val, &JsValue::from_str("getPoints")).unwrap();
1006 let get_fill = Reflect::get(&val, &JsValue::from_str("getFill")).unwrap();
1007 let get_stroke = Reflect::get(&val, &JsValue::from_str("getStroke")).unwrap();
1008 let get_stroke_width = Reflect::get(&val, &JsValue::from_str("getStrokeWidth")).unwrap();
1009 let get_line_cap = Reflect::get(&val, &JsValue::from_str("getLineCap")).unwrap();
1010 let get_line_join = Reflect::get(&val, &JsValue::from_str("getLineJoin")).unwrap();
1011 let get_subobjects = Reflect::get(&val, &JsValue::from_str("getSubobjects")).unwrap();
1012 let get_index = Reflect::get(&val, &JsValue::from_str("getIndex")).unwrap();
1013 let get_fill_rule = Reflect::get(&val, &JsValue::from_str("getFillRule")).unwrap();
1014 let points = get_points.dyn_into::<js_sys::Function>().unwrap().call0(&val).unwrap();
1015 let fill = get_fill.dyn_into::<js_sys::Function>().unwrap().call0(&val).unwrap();
1016 let stroke = get_stroke.dyn_into::<js_sys::Function>().unwrap().call0(&val).unwrap();
1017 let stroke_width = get_stroke_width.dyn_into::<js_sys::Function>().unwrap().call0(&val).unwrap();
1018 let line_cap = get_line_cap.dyn_into::<js_sys::Function>().unwrap().call0(&val).unwrap();
1019 let line_join = get_line_join.dyn_into::<js_sys::Function>().unwrap().call0(&val).unwrap();
1020 let subobjects = get_subobjects.dyn_into::<js_sys::Function>().unwrap().call0(&val).unwrap();
1021 let index = get_index.dyn_into::<js_sys::Function>().unwrap().call0(&val).unwrap();
1022 let points = points.dyn_into::<Array>().unwrap();
1023 let fill = fill.dyn_into::<WasmGradientImageOrColor>().unwrap();
1024 let stroke = stroke.dyn_into::<WasmGradientImageOrColor>().unwrap();
1025 let stroke_width = stroke_width.as_f64().unwrap();
1026 let line_cap = line_cap.as_string().unwrap();
1027 let line_join = line_join.as_string().unwrap();
1028 let subobjects = subobjects.dyn_into::<Array>().unwrap();
1029 let index = index.as_f64().unwrap() as usize;
1030 let subobjects = subobjects.iter().map(|object| object.dyn_into::<WasmVectorObject>().unwrap()).collect::<Vec<WasmVectorObject>>();
1031 let fill_rule = get_fill_rule.dyn_into::<js_sys::Function>().unwrap().call0(&val).unwrap();
1032 return WasmVectorObject::new()
1033 .set_points(points)
1034 .set_fill(fill, false)
1035 .set_stroke(stroke, false)
1036 .set_stroke_width(stroke_width, false)
1037 .set_line_cap(line_cap, false)
1038 .set_line_join(line_join, false)
1039 .set_subobjects(subobjects)
1040 .set_index(index)
1041 .set_fill_rule(fill_rule.as_string().unwrap(), false);
1042 }
1043 fn unchecked_from_js_ref(val: &JsValue) -> &Self {
1044 val.unchecked_ref::<WasmVectorObject>()
1045 }
1046}
1047
1048
1049impl AsRef<JsValue> for WasmVectorObject {
1050 fn as_ref(&self) -> &JsValue {
1051 Box::leak(Box::new(JsValue::from(self.clone())))
1052 }
1053}
1054
1055
1056#[wasm_bindgen(js_name = dashedObject)]
1057pub fn dashed_object_js(
1058 shape: &WasmVectorObject,
1059 num_dashes: Option<usize>,
1060 dashed_ratio: Option<f64>,
1061 dash_offset: Option<f64>,
1062 equal_lengths: Option<bool>
1063) -> WasmVectorObject {
1064 WasmVectorObject {
1065 native_vec_features: dashed_object(&shape.native_vec_features, num_dashes, dashed_ratio, dash_offset, equal_lengths)
1066 }
1067}
1068
1069
1070#[wasm_bindgen(js_name = addFinalTip)]
1071pub fn add_final_tip_js(
1072 shape: WasmVectorObject,
1073 tip_side_length: f64,
1074 tip_color: WasmColor
1075) -> WasmVectorObject {
1076 WasmVectorObject {
1077 native_vec_features: add_final_tip(shape.native_vec_features, tip_side_length, (
1078 tip_color.color.red,
1079 tip_color.color.green,
1080 tip_color.color.blue,
1081 tip_color.color.alpha
1082 ))
1083 }
1084}
1085
1086
1087#[wasm_bindgen(js_name = addInitialTip)]
1088pub fn add_initial_tip_js(
1089 shape: WasmVectorObject,
1090 tip_side_length: f64,
1091 tip_color: WasmColor
1092) -> WasmVectorObject {
1093 WasmVectorObject {
1094 native_vec_features: add_initial_tip(shape.native_vec_features, tip_side_length, (
1095 tip_color.color.red,
1096 tip_color.color.green,
1097 tip_color.color.blue,
1098 tip_color.color.alpha
1099 ))
1100 }
1101}
1102
1103
1104#[wasm_bindgen(js_name = addBothSidesTips)]
1105pub fn add_both_sides_tips_js(
1106 shape: WasmVectorObject,
1107 tip_side_length: f64,
1108 tip_color: WasmColor
1109) -> WasmVectorObject {
1110 WasmVectorObject {
1111 native_vec_features: add_both_sides_tips(shape.native_vec_features, tip_side_length, (
1112 tip_color.color.red,
1113 tip_color.color.green,
1114 tip_color.color.blue,
1115 tip_color.color.alpha
1116 ))
1117 }
1118}
1119
1120
1121#[wasm_bindgen(js_name = arc)]
1122pub fn arc_js(
1123 center: Array,
1124 radius: f64,
1125 start_angle: f64,
1126 end_angle: f64,
1127 num_points: Option<usize>,
1128 stroke_color: Option<WasmColor>,
1129 fill_color: Option<WasmColor>,
1130 stroke_width: Option<f64>,
1131 line_cap: Option<String>,
1132 line_join: Option<String>,
1133 index: Option<usize>
1134) -> WasmVectorObject {
1135 let center = (center.get(0).as_f64().unwrap(), center.get(1).as_f64().unwrap());
1136 let stroke_color = match stroke_color {
1137 Some(color) => Some((
1138 color.color.red,
1139 color.color.green,
1140 color.color.blue,
1141 color.color.alpha
1142 )),
1143 None => None
1144 };
1145 let fill_color = match fill_color {
1146 Some(color) => Some((
1147 color.color.red,
1148 color.color.green,
1149 color.color.blue,
1150 color.color.alpha
1151 )),
1152 None => None
1153 };
1154 let stroke_width = match stroke_width {
1155 Some(width) => Some(width),
1156 None => None
1157 };
1158 let line_cap = match line_cap {
1159 Some(cap) => match cap.as_str() {
1160 "butt" => Some("butt"),
1161 "round" => Some("round"),
1162 "square" => Some("square"),
1163 _ => Some("butt")
1164 },
1165 None => None
1166 };
1167 let line_join = match line_join {
1168 Some(join) => match join.as_str() {
1169 "miter" => Some("miter"),
1170 "round" => Some("round"),
1171 "bevel" => Some("bevel"),
1172 _ => Some("miter")
1173 },
1174 None => None
1175 };
1176 let index = match index {
1177 Some(index) => Some(index),
1178 None => None
1179 };
1180 WasmVectorObject {
1181 native_vec_features: arc(
1182 center,
1183 radius,
1184 start_angle,
1185 end_angle,
1186 num_points,
1187 stroke_color,
1188 fill_color,
1189 stroke_width,
1190 line_cap,
1191 line_join,
1192 index
1193 )
1194 }
1195}
1196
1197
1198#[wasm_bindgen(js_name = circle)]
1199pub fn circle_js(
1200 center: Array,
1201 radius: f64,
1202 num_points: Option<usize>,
1203 stroke_color: Option<WasmColor>,
1204 fill_color: Option<WasmColor>,
1205 stroke_width: Option<f64>,
1206 line_cap: Option<String>,
1207 line_join: Option<String>,
1208 index: Option<usize>
1209) -> WasmVectorObject {
1210 let center = (center.get(0).as_f64().unwrap(), center.get(1).as_f64().unwrap());
1211 let stroke_color = match stroke_color {
1212 Some(color) => Some((
1213 color.color.red,
1214 color.color.green,
1215 color.color.blue,
1216 color.color.alpha
1217 )),
1218 None => None
1219 };
1220 let fill_color = match fill_color {
1221 Some(color) => Some((
1222 color.color.red,
1223 color.color.green,
1224 color.color.blue,
1225 color.color.alpha
1226 )),
1227 None => None
1228 };
1229 let stroke_width = match stroke_width {
1230 Some(width) => Some(width),
1231 None => None
1232 };
1233 let line_cap = match line_cap {
1234 Some(cap) => match cap.as_str() {
1235 "butt" => Some("butt"),
1236 "round" => Some("round"),
1237 "square" => Some("square"),
1238 _ => Some("butt")
1239 },
1240 None => None
1241 };
1242 let line_join = match line_join {
1243 Some(join) => match join.as_str() {
1244 "miter" => Some("miter"),
1245 "round" => Some("round"),
1246 "bevel" => Some("bevel"),
1247 _ => Some("miter")
1248 },
1249 None => None
1250 };
1251 let index = match index {
1252 Some(index) => Some(index),
1253 None => None
1254 };
1255 WasmVectorObject {
1256 native_vec_features: circle(
1257 center,
1258 radius,
1259 num_points,
1260 stroke_color,
1261 fill_color,
1262 stroke_width,
1263 line_cap,
1264 line_join,
1265 index
1266 )
1267 }
1268}
1269
1270
1271#[wasm_bindgen(js_name = ellipticalArc)]
1272pub fn elliptical_arc_js(
1273 center: Array,
1274 x_radius: f64,
1275 y_radius: f64,
1276 start_angle: f64,
1277 end_angle: f64,
1278 num_points: Option<usize>,
1279 stroke_color: Option<WasmColor>,
1280 fill_color: Option<WasmColor>,
1281 stroke_width: Option<f64>,
1282 line_cap: Option<String>,
1283 line_join: Option<String>,
1284 index: Option<usize>
1285) -> WasmVectorObject {
1286 let center = (center.get(0).as_f64().unwrap(), center.get(1).as_f64().unwrap());
1287 let stroke_color = match stroke_color {
1288 Some(color) => Some((
1289 color.color.red,
1290 color.color.green,
1291 color.color.blue,
1292 color.color.alpha
1293 )),
1294 None => None
1295 };
1296 let fill_color = match fill_color {
1297 Some(color) => Some((
1298 color.color.red,
1299 color.color.green,
1300 color.color.blue,
1301 color.color.alpha
1302 )),
1303 None => None
1304 };
1305 let stroke_width = match stroke_width {
1306 Some(width) => Some(width),
1307 None => None
1308 };
1309 let line_cap = match line_cap {
1310 Some(cap) => match cap.as_str() {
1311 "butt" => Some("butt"),
1312 "round" => Some("round"),
1313 "square" => Some("square"),
1314 _ => Some("butt")
1315 },
1316 None => None
1317 };
1318 let line_join = match line_join {
1319 Some(join) => match join.as_str() {
1320 "miter" => Some("miter"),
1321 "round" => Some("round"),
1322 "bevel" => Some("bevel"),
1323 _ => Some("miter")
1324 },
1325 None => None
1326 };
1327 let index = match index {
1328 Some(index) => Some(index),
1329 None => None
1330 };
1331 WasmVectorObject {
1332 native_vec_features: elliptical_arc(
1333 center,
1334 x_radius,
1335 y_radius,
1336 start_angle,
1337 end_angle,
1338 num_points,
1339 stroke_color,
1340 fill_color,
1341 stroke_width,
1342 line_cap,
1343 line_join,
1344 index
1345 )
1346 }
1347}
1348
1349
1350#[wasm_bindgen(js_name = ellipse)]
1351pub fn ellipse_js(
1352 center: Array,
1353 x_radius: f64,
1354 y_radius: f64,
1355 num_points: Option<usize>,
1356 stroke_color: Option<WasmColor>,
1357 fill_color: Option<WasmColor>,
1358 stroke_width: Option<f64>,
1359 line_cap: Option<String>,
1360 line_join: Option<String>,
1361 index: Option<usize>
1362) -> WasmVectorObject {
1363 let center = (center.get(0).as_f64().unwrap(), center.get(1).as_f64().unwrap());
1364 let stroke_color = match stroke_color {
1365 Some(color) => Some((
1366 color.color.red,
1367 color.color.green,
1368 color.color.blue,
1369 color.color.alpha
1370 )),
1371 None => None
1372 };
1373 let fill_color = match fill_color {
1374 Some(color) => Some((
1375 color.color.red,
1376 color.color.green,
1377 color.color.blue,
1378 color.color.alpha
1379 )),
1380 None => None
1381 };
1382 let stroke_width = match stroke_width {
1383 Some(width) => Some(width),
1384 None => None
1385 };
1386 let line_cap = match line_cap {
1387 Some(cap) => match cap.as_str() {
1388 "butt" => Some("butt"),
1389 "round" => Some("round"),
1390 "square" => Some("square"),
1391 _ => Some("butt")
1392 },
1393 None => None
1394 };
1395 let line_join = match line_join {
1396 Some(join) => match join.as_str() {
1397 "miter" => Some("miter"),
1398 "round" => Some("round"),
1399 "bevel" => Some("bevel"),
1400 _ => Some("miter")
1401 },
1402 None => None
1403 };
1404 let index = match index {
1405 Some(index) => Some(index),
1406 None => None
1407 };
1408 WasmVectorObject {
1409 native_vec_features: ellipse(
1410 center,
1411 x_radius,
1412 y_radius,
1413 num_points,
1414 stroke_color,
1415 fill_color,
1416 stroke_width,
1417 line_cap,
1418 line_join,
1419 index
1420 )
1421 }
1422}
1423
1424
1425#[wasm_bindgen(js_name = annularSector)]
1426pub fn annular_sector_js(
1427 center: Array,
1428 inner_radius: f64,
1429 outer_radius: f64,
1430 start_angle: f64,
1431 end_angle: f64,
1432 num_points: Option<usize>,
1433 stroke_color: Option<WasmColor>,
1434 fill_color: Option<WasmColor>,
1435 stroke_width: Option<f64>,
1436 line_cap: Option<String>,
1437 line_join: Option<String>,
1438 index: Option<usize>
1439) -> WasmVectorObject {
1440 let center = (center.get(0).as_f64().unwrap(), center.get(1).as_f64().unwrap());
1441 let stroke_color = match stroke_color {
1442 Some(color) => Some((
1443 color.color.red,
1444 color.color.green,
1445 color.color.blue,
1446 color.color.alpha
1447 )),
1448 None => None
1449 };
1450 let fill_color = match fill_color {
1451 Some(color) => Some((
1452 color.color.red,
1453 color.color.green,
1454 color.color.blue,
1455 color.color.alpha
1456 )),
1457 None => None
1458 };
1459 let stroke_width = match stroke_width {
1460 Some(width) => Some(width),
1461 None => None
1462 };
1463 let line_cap = match line_cap {
1464 Some(cap) => match cap.as_str() {
1465 "butt" => Some("butt"),
1466 "round" => Some("round"),
1467 "square" => Some("square"),
1468 _ => Some("butt")
1469 },
1470 None => None
1471 };
1472 let line_join = match line_join {
1473 Some(join) => match join.as_str() {
1474 "miter" => Some("miter"),
1475 "round" => Some("round"),
1476 "bevel" => Some("bevel"),
1477 _ => Some("miter")
1478 },
1479 None => None
1480 };
1481 let index = match index {
1482 Some(index) => Some(index),
1483 None => None
1484 };
1485 WasmVectorObject {
1486 native_vec_features: annular_sector(
1487 center,
1488 inner_radius,
1489 outer_radius,
1490 start_angle,
1491 end_angle,
1492 num_points,
1493 stroke_color,
1494 fill_color,
1495 stroke_width,
1496 line_cap,
1497 line_join,
1498 index
1499 )
1500 }
1501}
1502
1503
1504#[wasm_bindgen(js_name = line)]
1505pub fn line_js(
1506 start_point: Array,
1507 end_point: Array,
1508 stroke_color: Option<WasmColor>,
1509 stroke_width: Option<f64>,
1510 line_cap: Option<String>,
1511 line_join: Option<String>,
1512 index: Option<usize>
1513) -> WasmVectorObject {
1514 let start_point = (start_point.get(0).as_f64().unwrap(), start_point.get(1).as_f64().unwrap());
1515 let end_point = (end_point.get(0).as_f64().unwrap(), end_point.get(1).as_f64().unwrap());
1516 let stroke_color = match stroke_color {
1517 Some(color) => Some((
1518 color.color.red,
1519 color.color.green,
1520 color.color.blue,
1521 color.color.alpha
1522 )),
1523 None => None
1524 };
1525 let stroke_width = match stroke_width {
1526 Some(width) => Some(width),
1527 None => None
1528 };
1529 let line_cap = match line_cap {
1530 Some(cap) => match cap.as_str() {
1531 "butt" => Some("butt"),
1532 "round" => Some("round"),
1533 "square" => Some("square"),
1534 _ => Some("butt")
1535 },
1536 None => None
1537 };
1538 let line_join = match line_join {
1539 Some(join) => match join.as_str() {
1540 "miter" => Some("miter"),
1541 "round" => Some("round"),
1542 "bevel" => Some("bevel"),
1543 _ => Some("miter")
1544 },
1545 None => None
1546 };
1547 let index = match index {
1548 Some(index) => Some(index),
1549 None => None
1550 };
1551 WasmVectorObject {
1552 native_vec_features: line(
1553 start_point,
1554 end_point,
1555 stroke_color,
1556 stroke_width,
1557 line_cap,
1558 line_join,
1559 index
1560 )
1561 }
1562}
1563
1564
1565#[wasm_bindgen(js_name = polygon)]
1566pub fn polygon_js(
1567 points: Array,
1568 stroke_color: Option<WasmColor>,
1569 fill_color: Option<WasmColor>,
1570 stroke_width: Option<f64>,
1571 line_cap: Option<String>,
1572 line_join: Option<String>,
1573 index: Option<usize>
1574) -> WasmVectorObject {
1575 let points = points.iter().map(|point| {
1576 let point = point.dyn_into::<Array>().unwrap();
1577 let x = point.get(0).as_f64().unwrap();
1578 let y = point.get(1).as_f64().unwrap();
1579 (x, y)
1580 }).collect();
1581 let stroke_color = match stroke_color {
1582 Some(color) => Some((
1583 color.color.red,
1584 color.color.green,
1585 color.color.blue,
1586 color.color.alpha
1587 )),
1588 None => None
1589 };
1590 let fill_color = match fill_color {
1591 Some(color) => Some((
1592 color.color.red,
1593 color.color.green,
1594 color.color.blue,
1595 color.color.alpha
1596 )),
1597 None => None
1598 };
1599 let stroke_width = match stroke_width {
1600 Some(width) => Some(width),
1601 None => None
1602 };
1603 let line_cap = match line_cap {
1604 Some(cap) => match cap.as_str() {
1605 "butt" => Some("butt"),
1606 "round" => Some("round"),
1607 "square" => Some("square"),
1608 _ => Some("butt")
1609 },
1610 None => None
1611 };
1612 let line_join = match line_join {
1613 Some(join) => match join.as_str() {
1614 "miter" => Some("miter"),
1615 "round" => Some("round"),
1616 "bevel" => Some("bevel"),
1617 _ => Some("miter")
1618 },
1619 None => None
1620 };
1621 let index = match index {
1622 Some(index) => Some(index),
1623 None => None
1624 };
1625 WasmVectorObject {
1626 native_vec_features: polygon(
1627 points,
1628 stroke_color,
1629 fill_color,
1630 stroke_width,
1631 line_cap,
1632 line_join,
1633 index
1634 )
1635 }
1636}
1637
1638
1639#[wasm_bindgen(js_name = regularPolygon)]
1640pub fn regular_polygon_js(
1641 center: Array,
1642 side_length: f64,
1643 num_sides: usize,
1644 stroke_color: Option<WasmColor>,
1645 fill_color: Option<WasmColor>,
1646 stroke_width: Option<f64>,
1647 line_cap: Option<String>,
1648 line_join: Option<String>,
1649 index: Option<usize>
1650) -> WasmVectorObject {
1651 let center = (center.get(0).as_f64().unwrap(), center.get(1).as_f64().unwrap());
1652 let stroke_color = match stroke_color {
1653 Some(color) => Some((
1654 color.color.red,
1655 color.color.green,
1656 color.color.blue,
1657 color.color.alpha
1658 )),
1659 None => None
1660 };
1661 let fill_color = match fill_color {
1662 Some(color) => Some((
1663 color.color.red,
1664 color.color.green,
1665 color.color.blue,
1666 color.color.alpha
1667 )),
1668 None => None
1669 };
1670 let stroke_width = match stroke_width {
1671 Some(width) => Some(width),
1672 None => None
1673 };
1674 let line_cap = match line_cap {
1675 Some(cap) => match cap.as_str() {
1676 "butt" => Some("butt"),
1677 "round" => Some("round"),
1678 "square" => Some("square"),
1679 _ => Some("butt")
1680 },
1681 None => None
1682 };
1683 let line_join = match line_join {
1684 Some(join) => match join.as_str() {
1685 "miter" => Some("miter"),
1686 "round" => Some("round"),
1687 "bevel" => Some("bevel"),
1688 _ => Some("miter")
1689 },
1690 None => None
1691 };
1692 let index = match index {
1693 Some(index) => Some(index),
1694 None => None
1695 };
1696 WasmVectorObject {
1697 native_vec_features: regular_polygon(
1698 center,
1699 side_length,
1700 num_sides,
1701 stroke_color,
1702 fill_color,
1703 stroke_width,
1704 line_cap,
1705 line_join,
1706 index
1707 )
1708 }
1709}
1710
1711
1712#[wasm_bindgen(js_name = square)]
1713pub fn square_js(
1714 center: Array,
1715 side_length: f64,
1716 stroke_color: Option<WasmColor>,
1717 fill_color: Option<WasmColor>,
1718 stroke_width: Option<f64>,
1719 line_cap: Option<String>,
1720 line_join: Option<String>,
1721 index: Option<usize>
1722) -> WasmVectorObject {
1723 let center = (center.get(0).as_f64().unwrap(), center.get(1).as_f64().unwrap());
1724 let stroke_color = match stroke_color {
1725 Some(color) => Some((
1726 color.color.red,
1727 color.color.green,
1728 color.color.blue,
1729 color.color.alpha
1730 )),
1731 None => None
1732 };
1733 let fill_color = match fill_color {
1734 Some(color) => Some((
1735 color.color.red,
1736 color.color.green,
1737 color.color.blue,
1738 color.color.alpha
1739 )),
1740 None => None
1741 };
1742 let stroke_width = match stroke_width {
1743 Some(width) => Some(width),
1744 None => None
1745 };
1746 let line_cap = match line_cap {
1747 Some(cap) => match cap.as_str() {
1748 "butt" => Some("butt"),
1749 "round" => Some("round"),
1750 "square" => Some("square"),
1751 _ => Some("butt")
1752 },
1753 None => None
1754 };
1755 let line_join = match line_join {
1756 Some(join) => match join.as_str() {
1757 "miter" => Some("miter"),
1758 "round" => Some("round"),
1759 "bevel" => Some("bevel"),
1760 _ => Some("miter")
1761 },
1762 None => None
1763 };
1764 let index = match index {
1765 Some(index) => Some(index),
1766 None => None
1767 };
1768 WasmVectorObject {
1769 native_vec_features: square(
1770 center,
1771 side_length,
1772 stroke_color,
1773 fill_color,
1774 stroke_width,
1775 line_cap,
1776 line_join,
1777 index
1778 )
1779 }
1780}
1781
1782
1783#[wasm_bindgen(js_name = rectangle)]
1784pub fn rectangle_js(
1785 center: Array,
1786 width: f64,
1787 height: f64,
1788 stroke_color: Option<WasmColor>,
1789 fill_color: Option<WasmColor>,
1790 stroke_width: Option<f64>,
1791 line_cap: Option<String>,
1792 line_join: Option<String>,
1793 index: Option<usize>
1794) -> WasmVectorObject {
1795 let center = (center.get(0).as_f64().unwrap(), center.get(1).as_f64().unwrap());
1796 let stroke_color = match stroke_color {
1797 Some(color) => Some((
1798 color.color.red,
1799 color.color.green,
1800 color.color.blue,
1801 color.color.alpha
1802 )),
1803 None => None
1804 };
1805 let fill_color = match fill_color {
1806 Some(color) => Some((
1807 color.color.red,
1808 color.color.green,
1809 color.color.blue,
1810 color.color.alpha
1811 )),
1812 None => None
1813 };
1814 let stroke_width = match stroke_width {
1815 Some(width) => Some(width),
1816 None => None
1817 };
1818 let line_cap = match line_cap {
1819 Some(cap) => match cap.as_str() {
1820 "butt" => Some("butt"),
1821 "round" => Some("round"),
1822 "square" => Some("square"),
1823 _ => Some("butt")
1824 },
1825 None => None
1826 };
1827 let line_join = match line_join {
1828 Some(join) => match join.as_str() {
1829 "miter" => Some("miter"),
1830 "round" => Some("round"),
1831 "bevel" => Some("bevel"),
1832 _ => Some("miter")
1833 },
1834 None => None
1835 };
1836 let index = match index {
1837 Some(index) => Some(index),
1838 None => None
1839 };
1840 WasmVectorObject {
1841 native_vec_features: rectangle(
1842 center,
1843 width,
1844 height,
1845 stroke_color,
1846 fill_color,
1847 stroke_width,
1848 line_cap,
1849 line_join,
1850 index
1851 )
1852 }
1853}
1854
1855
1856#[wasm_bindgen(js_name = equilateralTriangle)]
1857pub fn equilateral_triangle_js(
1858 center: Array,
1859 side_length: f64,
1860 stroke_color: Option<WasmColor>,
1861 fill_color: Option<WasmColor>,
1862 stroke_width: Option<f64>,
1863 line_cap: Option<String>,
1864 line_join: Option<String>,
1865 index: Option<usize>
1866) -> WasmVectorObject {
1867 let center = (center.get(0).as_f64().unwrap(), center.get(1).as_f64().unwrap());
1868 let stroke_color = match stroke_color {
1869 Some(color) => Some((
1870 color.color.red,
1871 color.color.green,
1872 color.color.blue,
1873 color.color.alpha
1874 )),
1875 None => None
1876 };
1877 let fill_color = match fill_color {
1878 Some(color) => Some((
1879 color.color.red,
1880 color.color.green,
1881 color.color.blue,
1882 color.color.alpha
1883 )),
1884 None => None
1885 };
1886 let stroke_width = match stroke_width {
1887 Some(width) => Some(width),
1888 None => None
1889 };
1890 let line_cap = match line_cap {
1891 Some(cap) => match cap.as_str() {
1892 "butt" => Some("butt"),
1893 "round" => Some("round"),
1894 "square" => Some("square"),
1895 _ => Some("butt")
1896 },
1897 None => None
1898 };
1899 let line_join = match line_join {
1900 Some(join) => match join.as_str() {
1901 "miter" => Some("miter"),
1902 "round" => Some("round"),
1903 "bevel" => Some("bevel"),
1904 _ => Some("miter")
1905 },
1906 None => None
1907 };
1908 let index = match index {
1909 Some(index) => Some(index),
1910 None => None
1911 };
1912 WasmVectorObject {
1913 native_vec_features: equilateral_triangle(
1914 center,
1915 side_length,
1916 stroke_color,
1917 fill_color,
1918 stroke_width,
1919 line_cap,
1920 line_join,
1921 index
1922 )
1923 }
1924}
1925
1926
1927#[wasm_bindgen(js_name = triangle)]
1928pub fn triangle_js(
1929 point1: Array,
1930 point2: Array,
1931 point3: Array,
1932 stroke_color: Option<WasmColor>,
1933 fill_color: Option<WasmColor>,
1934 stroke_width: Option<f64>,
1935 line_cap: Option<String>,
1936 line_join: Option<String>,
1937 index: Option<usize>
1938) -> WasmVectorObject {
1939 let point1 = (point1.get(0).as_f64().unwrap(), point1.get(1).as_f64().unwrap());
1940 let point2 = (point2.get(0).as_f64().unwrap(), point2.get(1).as_f64().unwrap());
1941 let point3 = (point3.get(0).as_f64().unwrap(), point3.get(1).as_f64().unwrap());
1942 let stroke_color = match stroke_color {
1943 Some(color) => Some((
1944 color.color.red,
1945 color.color.green,
1946 color.color.blue,
1947 color.color.alpha
1948 )),
1949 None => None
1950 };
1951 let fill_color = match fill_color {
1952 Some(color) => Some((
1953 color.color.red,
1954 color.color.green,
1955 color.color.blue,
1956 color.color.alpha
1957 )),
1958 None => None
1959 };
1960 let stroke_width = match stroke_width {
1961 Some(width) => Some(width),
1962 None => None
1963 };
1964 let line_cap = match line_cap {
1965 Some(cap) => match cap.as_str() {
1966 "butt" => Some("butt"),
1967 "round" => Some("round"),
1968 "square" => Some("square"),
1969 _ => Some("butt")
1970 },
1971 None => None
1972 };
1973 let line_join = match line_join {
1974 Some(join) => match join.as_str() {
1975 "miter" => Some("miter"),
1976 "round" => Some("round"),
1977 "bevel" => Some("bevel"),
1978 _ => Some("miter")
1979 },
1980 None => None
1981 };
1982 let index = match index {
1983 Some(index) => Some(index),
1984 None => None
1985 };
1986 WasmVectorObject {
1987 native_vec_features: triangle(
1988 point1,
1989 point2,
1990 point3,
1991 stroke_color,
1992 fill_color,
1993 stroke_width,
1994 line_cap,
1995 line_join,
1996 index
1997 )
1998 }
1999}
2000
2001
2002#[wasm_bindgen(js_name = rightTriangle)]
2003pub fn right_triangle_js(
2004 point1: Array,
2005 point2: Array,
2006 stroke_color: Option<WasmColor>,
2007 fill_color: Option<WasmColor>,
2008 stroke_width: Option<f64>,
2009 line_cap: Option<String>,
2010 line_join: Option<String>,
2011 index: Option<usize>
2012) -> WasmVectorObject {
2013 let point1 = (point1.get(0).as_f64().unwrap(), point1.get(1).as_f64().unwrap());
2014 let point2 = (point2.get(0).as_f64().unwrap(), point2.get(1).as_f64().unwrap());
2015 let stroke_color = match stroke_color {
2016 Some(color) => Some((
2017 color.color.red,
2018 color.color.green,
2019 color.color.blue,
2020 color.color.alpha
2021 )),
2022 None => None
2023 };
2024 let fill_color = match fill_color {
2025 Some(color) => Some((
2026 color.color.red,
2027 color.color.green,
2028 color.color.blue,
2029 color.color.alpha
2030 )),
2031 None => None
2032 };
2033 let stroke_width = match stroke_width {
2034 Some(width) => Some(width),
2035 None => None
2036 };
2037 let line_cap = match line_cap {
2038 Some(cap) => match cap.as_str() {
2039 "butt" => Some("butt"),
2040 "round" => Some("round"),
2041 "square" => Some("square"),
2042 _ => Some("butt")
2043 },
2044 None => None
2045 };
2046 let line_join = match line_join {
2047 Some(join) => match join.as_str() {
2048 "miter" => Some("miter"),
2049 "round" => Some("round"),
2050 "bevel" => Some("bevel"),
2051 _ => Some("miter")
2052 },
2053 None => None
2054 };
2055 let index = match index {
2056 Some(index) => Some(index),
2057 None => None
2058 };
2059 WasmVectorObject {
2060 native_vec_features: right_triangle(
2061 point1,
2062 point2,
2063 stroke_color,
2064 fill_color,
2065 stroke_width,
2066 line_cap,
2067 line_join,
2068 index
2069 )
2070 }
2071}
2072
2073
2074#[wasm_bindgen(js_name = axes)]
2075pub fn axes_js(
2076 x_min: f64,
2077 x_max: f64,
2078 x_step: f64,
2079 y_min: f64,
2080 y_max: f64,
2081 y_step: f64,
2082 center: Array,
2083 x_length: Option<f64>,
2084 y_length: Option<f64>,
2085 color: Option<WasmColor>,
2086 stroke_width: Option<f64>,
2087 line_cap: Option<String>,
2088 line_join: Option<String>,
2089 index: Option<usize>,
2090 add_x_ticks: Option<bool>,
2091 add_y_ticks: Option<bool>,
2092 x_tick_size: Option<f64>,
2093 y_tick_size: Option<f64>,
2094 add_x_tip: Option<bool>,
2095 add_y_tip: Option<bool>
2096) -> WasmVectorObject {
2097 let color = match color {
2098 Some(color) => Some((
2099 color.color.red,
2100 color.color.green,
2101 color.color.blue,
2102 color.color.alpha
2103 )),
2104 None => None
2105 };
2106 let center = (center.get(0).as_f64().unwrap(), center.get(1).as_f64().unwrap());
2107 let line_cap = match line_cap {
2108 Some(cap) => match cap.as_str() {
2109 "butt" => Some("butt"),
2110 "round" => Some("round"),
2111 "square" => Some("square"),
2112 _ => Some("butt")
2113 },
2114 None => None
2115 };
2116 let line_join = match line_join {
2117 Some(join) => match join.as_str() {
2118 "miter" => Some("miter"),
2119 "round" => Some("round"),
2120 "bevel" => Some("bevel"),
2121 _ => Some("miter")
2122 },
2123 None => None
2124 };
2125 return WasmVectorObject {
2126 native_vec_features: axes(
2127 x_min,
2128 x_max,
2129 x_step,
2130 y_min,
2131 y_max,
2132 y_step,
2133 center,
2134 x_length,
2135 y_length,
2136 color,
2137 stroke_width,
2138 line_cap,
2139 line_join,
2140 index,
2141 add_x_ticks,
2142 add_y_ticks,
2143 x_tick_size,
2144 y_tick_size,
2145 add_x_tip,
2146 add_y_tip
2147 )
2148 }
2149}
2150
2151
2152#[wasm_bindgen(js_name = coordsToPoint)]
2153pub fn coords_to_point_js(
2154 axes: &WasmVectorObject,
2155 x: f64,
2156 y: f64,
2157 x_min: f64,
2158 x_max: f64,
2159 y_min: f64,
2160 y_max: f64
2161) -> Array {
2162 let point = coords_to_point(&axes.native_vec_features, x, y, x_min, x_max, y_min, y_max);
2163 Array::of2(&point.0.into(), &point.1.into())
2164}
2165
2166
2167#[wasm_bindgen(js_name = pointToCoords)]
2168pub fn point_to_coords_js(
2169 axes: &WasmVectorObject,
2170 point: Array,
2171 x_min: f64,
2172 x_max: f64,
2173 y_min: f64,
2174 y_max: f64
2175) -> Array {
2176 let point = (point.get(0).as_f64().unwrap(), point.get(1).as_f64().unwrap());
2177 let coords = point_to_coords(&axes.native_vec_features, point, x_min, x_max, y_min, y_max);
2178 Array::of2(&coords.0.into(), &coords.1.into())
2179}
2180
2181
2182#[wasm_bindgen(js_name = parametricPlotInAxes)]
2183pub async fn parametric_plot_in_axes_js(
2184 f: &js_sys::Function,
2185 t_min: f64,
2186 t_max: f64,
2187 t_step: f64,
2188 axes: &WasmVectorObject,
2189 x_min: f64,
2190 x_max: f64,
2191 y_min: f64,
2192 y_max: f64,
2193 color: Option<WasmColor>,
2194 stroke_width: Option<f64>,
2195 line_cap: Option<String>,
2196 line_join: Option<String>,
2197 index: Option<usize>
2198) -> WasmVectorObject {
2199 let color = match color {
2200 Some(color) => Some((
2201 color.color.red,
2202 color.color.green,
2203 color.color.blue,
2204 color.color.alpha
2205 )),
2206 None => None
2207 };
2208 let line_cap = match line_cap {
2209 Some(cap) => match cap.as_str() {
2210 "butt" => Some("butt"),
2211 "round" => Some("round"),
2212 "square" => Some("square"),
2213 _ => Some("butt")
2214 },
2215 None => None
2216 };
2217 let line_join = match line_join {
2218 Some(join) => match join.as_str() {
2219 "miter" => Some("miter"),
2220 "round" => Some("round"),
2221 "bevel" => Some("bevel"),
2222 _ => Some("miter")
2223 },
2224 None => None
2225 };
2226 return WasmVectorObject {
2227 native_vec_features: parametric_plot_in_axes(
2228 Box::leak(Box::new(f.clone())),
2229 t_min,
2230 t_max,
2231 t_step,
2232 Box::leak(Box::new(axes.native_vec_features.clone())),
2233 Box::leak(Box::new(x_min)),
2234 Box::leak(Box::new(x_max)),
2235 Box::leak(Box::new(y_min)),
2236 Box::leak(Box::new(y_max)),
2237 color,
2238 stroke_width,
2239 line_cap,
2240 line_join,
2241 index
2242 ).await
2243 }
2244}
2245
2246
2247#[wasm_bindgen(js_name = plotInAxes)]
2248pub async fn plot_in_axes_js(
2249 f: js_sys::Function,
2250 x_min: f64,
2251 x_max: f64,
2252 y_min: f64,
2253 y_max: f64,
2254 x1: f64,
2255 x2: f64,
2256 x_step: f64,
2257 axes: &WasmVectorObject,
2258 color: Option<WasmColor>,
2259 stroke_width: Option<f64>,
2260 line_cap: Option<String>,
2261 line_join: Option<String>,
2262 index: Option<usize>
2263) -> WasmVectorObject {
2264 let color = match color {
2265 Some(color) => Some((
2266 color.color.red,
2267 color.color.green,
2268 color.color.blue,
2269 color.color.alpha
2270 )),
2271 None => None
2272 };
2273 let line_cap = match line_cap {
2274 Some(cap) => match cap.as_str() {
2275 "butt" => Some("butt"),
2276 "round" => Some("round"),
2277 "square" => Some("square"),
2278 _ => Some("butt")
2279 },
2280 None => None
2281 };
2282 let line_join = match line_join {
2283 Some(join) => match join.as_str() {
2284 "miter" => Some("miter"),
2285 "round" => Some("round"),
2286 "bevel" => Some("bevel"),
2287 _ => Some("miter")
2288 },
2289 None => None
2290 };
2291 return WasmVectorObject {
2292 native_vec_features: plot_in_axes(
2293 Box::leak(Box::new(f.clone())),
2294 Box::leak(Box::new(x_min)),
2295 Box::leak(Box::new(x_max)),
2296 Box::leak(Box::new(y_min)),
2297 Box::leak(Box::new(y_max)),
2298 x1,
2299 x2,
2300 x_step,
2301 Box::leak(Box::new(axes.native_vec_features.clone())),
2302 color,
2303 stroke_width,
2304 line_cap,
2305 line_join,
2306 index
2307 ).await
2308 }
2309}
2310
2311
2312#[wasm_bindgen(js_name = contourPlotInAxes)]
2313pub async fn contour_plot_in_axes_js(
2314 f: js_sys::Function,
2315 x_min: f64,
2316 x_max: f64,
2317 y_min: f64,
2318 y_max: f64,
2319 x_1: f64,
2320 x_2: f64,
2321 x_step: f64,
2322 y_1: f64,
2323 y_2: f64,
2324 y_step: f64,
2325 axes: &WasmVectorObject,
2326 intervals: &[f64],
2327 color: Option<WasmColor>,
2328 stroke_width: Option<f64>,
2329 line_cap: Option<String>,
2330 line_join: Option<String>,
2331 index: Option<usize>,
2332) -> WasmVectorObject {
2333 let color = match color {
2334 Some(color) => Some((
2335 color.color.red,
2336 color.color.green,
2337 color.color.blue,
2338 color.color.alpha
2339 )),
2340 None => None
2341 };
2342 let line_cap = match line_cap {
2343 Some(cap) => match cap.as_str() {
2344 "butt" => Some("butt"),
2345 "round" => Some("round"),
2346 "square" => Some("square"),
2347 _ => Some("butt")
2348 },
2349 None => None
2350 };
2351 let line_join = match line_join {
2352 Some(join) => match join.as_str() {
2353 "miter" => Some("miter"),
2354 "round" => Some("round"),
2355 "bevel" => Some("bevel"),
2356 _ => Some("miter")
2357 },
2358 None => None
2359 };
2360 return WasmVectorObject {
2361 native_vec_features: contour_plot_in_axes(
2362 f,
2363 x_min,
2364 x_max,
2365 y_min,
2366 y_max,
2367 x_1,
2368 x_2,
2369 x_step,
2370 y_1,
2371 y_2,
2372 y_step,
2373 Box::leak(Box::new(axes.native_vec_features.clone())),
2374 intervals,
2375 color,
2376 stroke_width,
2377 line_cap,
2378 line_join,
2379 index,
2380 ).await
2381 }
2382}
2383
2384
2385#[wasm_bindgen(js_name = areaUnderCurve)]
2386pub fn area_under_curve_js(
2387 axes: &WasmVectorObject,
2388 plot: &WasmVectorObject,
2389 x_min: f64,
2390 x_max: f64,
2391 y_min: f64,
2392 y_max: f64,
2393 x1: f64,
2394 x2: f64,
2395 color: Option<WasmColor>,
2396 index: Option<usize>
2397) -> WasmVectorObject {
2398 let color = match color {
2399 Some(color) => Some((
2400 color.color.red,
2401 color.color.green,
2402 color.color.blue,
2403 color.color.alpha
2404 )),
2405 None => None
2406 };
2407 return WasmVectorObject {
2408 native_vec_features: area_under_curve(
2409 &axes.native_vec_features,
2410 &plot.native_vec_features,
2411 x_min,
2412 x_max,
2413 y_min,
2414 y_max,
2415 x1,
2416 x2,
2417 color,
2418 index
2419 )
2420 }
2421}
2422
2423
2424#[wasm_bindgen(js_name = riemannRectanglesForPlot)]
2425pub async fn riemann_rectangles_for_plot_js(
2426 f: js_sys::Function,
2427 x_min: f64,
2428 x_max: f64,
2429 y_min: f64,
2430 y_max: f64,
2431 direction: f64,
2432 x_1: f64,
2433 x_2: f64,
2434 n_rects: usize,
2435 axes: &WasmVectorObject,
2436 stroke_color: Option<WasmColor>,
2437 fill_color: Option<WasmColor>,
2438 stroke_width: Option<f64>,
2439 line_cap: Option<String>,
2440 line_join: Option<String>,
2441 index: Option<usize>
2442) -> WasmVectorObject {
2443 let stroke_color = match stroke_color {
2444 Some(color) => Some((
2445 color.color.red,
2446 color.color.green,
2447 color.color.blue,
2448 color.color.alpha
2449 )),
2450 None => None
2451 };
2452 let fill_color = match fill_color {
2453 Some(color) => Some((
2454 color.color.red,
2455 color.color.green,
2456 color.color.blue,
2457 color.color.alpha
2458 )),
2459 None => None
2460 };
2461 let line_cap = match line_cap {
2462 Some(cap) => match cap.as_str() {
2463 "butt" => Some("butt"),
2464 "round" => Some("round"),
2465 "square" => Some("square"),
2466 _ => Some("butt")
2467 },
2468 None => None
2469 };
2470 let line_join = match line_join {
2471 Some(join) => match join.as_str() {
2472 "miter" => Some("miter"),
2473 "round" => Some("round"),
2474 "bevel" => Some("bevel"),
2475 _ => Some("miter")
2476 },
2477 None => None
2478 };
2479 return WasmVectorObject {
2480 native_vec_features: riemann_rectangles_for_plot(
2481 f.clone(),
2482 x_min,
2483 x_max,
2484 y_min,
2485 y_max,
2486 direction,
2487 x_1,
2488 x_2,
2489 n_rects,
2490 &axes.native_vec_features,
2491 stroke_color,
2492 fill_color,
2493 stroke_width,
2494 line_cap,
2495 line_join,
2496 index
2497 ).await
2498 }
2499}
2500
2501
2502#[wasm_bindgen(js_name = secantLineForPlot)]
2503pub async fn secant_line_for_plot_js(
2504 f: js_sys::Function,
2505 x_1: f64,
2506 x_2: f64,
2507 length: f64,
2508 axes: &WasmVectorObject,
2509 x_min: f64,
2510 x_max: f64,
2511 y_min: f64,
2512 y_max: f64,
2513 color: Option<WasmColor>,
2514 stroke_width: Option<f64>,
2515 line_cap: Option<String>,
2516 line_join: Option<String>,
2517 index: Option<usize>
2518) -> WasmVectorObject {
2519 let color = match color {
2520 Some(color) => Some((
2521 color.color.red,
2522 color.color.green,
2523 color.color.blue,
2524 color.color.alpha
2525 )),
2526 None => None
2527 };
2528 let line_cap = match line_cap {
2529 Some(cap) => match cap.as_str() {
2530 "butt" => Some("butt"),
2531 "round" => Some("round"),
2532 "square" => Some("square"),
2533 _ => Some("butt")
2534 },
2535 None => None
2536 };
2537 let line_join = match line_join {
2538 Some(join) => match join.as_str() {
2539 "miter" => Some("miter"),
2540 "round" => Some("round"),
2541 "bevel" => Some("bevel"),
2542 _ => Some("miter")
2543 },
2544 None => None
2545 };
2546 return WasmVectorObject {
2547 native_vec_features: secant_line_for_plot(
2548 f.clone(),
2549 x_1,
2550 x_2,
2551 length,
2552 &axes.native_vec_features,
2553 x_min,
2554 x_max,
2555 y_min,
2556 y_max,
2557 color,
2558 stroke_width,
2559 line_cap,
2560 line_join,
2561 index
2562 ).await
2563 }
2564}
2565
2566
2567#[wasm_bindgen(js_name = parametricFunction)]
2568pub async fn parametric_function_js(
2569 f: &js_sys::Function,
2570 t_min: f64,
2571 t_max: f64,
2572 t_step: f64,
2573 color: Option<WasmColor>,
2574 stroke_width: Option<f64>,
2575 line_cap: Option<String>,
2576 line_join: Option<String>,
2577 index: Option<usize>
2578) -> WasmVectorObject {
2579 let color = match color {
2580 Some(color) => Some((
2581 color.color.red,
2582 color.color.green,
2583 color.color.blue,
2584 color.color.alpha
2585 )),
2586 None => None
2587 };
2588 let line_cap = match line_cap {
2589 Some(cap) => match cap.as_str() {
2590 "butt" => Some("butt"),
2591 "round" => Some("round"),
2592 "square" => Some("square"),
2593 _ => Some("butt")
2594 },
2595 None => None
2596 };
2597 let line_join = match line_join {
2598 Some(join) => match join.as_str() {
2599 "miter" => Some("miter"),
2600 "round" => Some("round"),
2601 "bevel" => Some("bevel"),
2602 _ => Some("miter")
2603 },
2604 None => None
2605 };
2606 return WasmVectorObject {
2607 native_vec_features: parametric_function(
2608 f.clone(),
2609 t_min,
2610 t_max,
2611 t_step,
2612 color,
2613 stroke_width,
2614 line_cap,
2615 line_join,
2616 index
2617 ).await
2618 }
2619}
2620
2621
2622#[wasm_bindgen(js_name = contourPlot)]
2623pub async fn contour_plot_js(
2624 f: js_sys::Function,
2625 x_min: f64,
2626 x_max: f64,
2627 y_min: f64,
2628 y_max: f64,
2629 x_step: f64,
2630 y_step: f64,
2631 intervals: &[f64],
2632 color: Option<WasmColor>,
2633 stroke_width: Option<f64>,
2634 line_cap: Option<String>,
2635 line_join: Option<String>,
2636 index: Option<usize>,
2637) -> WasmVectorObject {
2638 let color = match color {
2639 Some(color) => Some((
2640 color.color.red,
2641 color.color.green,
2642 color.color.blue,
2643 color.color.alpha
2644 )),
2645 None => None
2646 };
2647 let line_cap = match line_cap {
2648 Some(cap) => match cap.as_str() {
2649 "butt" => Some("butt"),
2650 "round" => Some("round"),
2651 "square" => Some("square"),
2652 _ => Some("butt")
2653 },
2654 None => None
2655 };
2656 let line_join = match line_join {
2657 Some(join) => match join.as_str() {
2658 "miter" => Some("miter"),
2659 "round" => Some("round"),
2660 "bevel" => Some("bevel"),
2661 _ => Some("miter")
2662 },
2663 None => None
2664 };
2665 return WasmVectorObject {
2666 native_vec_features: contour_plot(
2667 f.clone(),
2668 x_min,
2669 x_max,
2670 y_min,
2671 y_max,
2672 x_step,
2673 y_step,
2674 intervals,
2675 color,
2676 stroke_width,
2677 line_cap,
2678 line_join,
2679 index,
2680 ).await
2681 }
2682}
2683
2684
2685#[wasm_bindgen(js_name = realFunction)]
2686pub async fn real_function_js(
2687 f: js_sys::Function,
2688 x_min: f64,
2689 x_max: f64,
2690 x_step: f64,
2691 color: Option<WasmColor>,
2692 stroke_width: Option<f64>,
2693 line_cap: Option<String>,
2694 line_join: Option<String>,
2695 index: Option<usize>
2696) -> WasmVectorObject {
2697 let color = match color {
2698 Some(color) => Some((
2699 color.color.red,
2700 color.color.green,
2701 color.color.blue,
2702 color.color.alpha
2703 )),
2704 None => None
2705 };
2706 let line_cap = match line_cap {
2707 Some(cap) => match cap.as_str() {
2708 "butt" => Some("butt"),
2709 "round" => Some("round"),
2710 "square" => Some("square"),
2711 _ => Some("butt")
2712 },
2713 None => None
2714 };
2715 let line_join = match line_join {
2716 Some(join) => match join.as_str() {
2717 "miter" => Some("miter"),
2718 "round" => Some("round"),
2719 "bevel" => Some("bevel"),
2720 _ => Some("miter")
2721 },
2722 None => None
2723 };
2724 return WasmVectorObject {
2725 native_vec_features: function(
2726 Box::leak(Box::new(f.clone())),
2727 x_min,
2728 x_max,
2729 x_step,
2730 color,
2731 stroke_width,
2732 line_cap,
2733 line_join,
2734 index
2735 ).await
2736 }
2737}
2738
2739
2740#[wasm_bindgen(js_name = numberLine)]
2741pub fn number_line_js(
2742 x_min: f64,
2743 x_max: f64,
2744 x_step: f64,
2745 center: Array,
2746 color: Option<WasmColor>,
2747 stroke_width: Option<f64>,
2748 line_cap: Option<String>,
2749 line_join: Option<String>,
2750 index: Option<usize>,
2751 length: Option<f64>,
2752 add_tip: Option<bool>,
2753 add_ticks: Option<bool>,
2754 tick_size: Option<f64>,
2755 angle: Option<f64>
2756) -> WasmVectorObject {
2757 let color = match color {
2758 Some(color) => Some((
2759 color.color.red,
2760 color.color.green,
2761 color.color.blue,
2762 color.color.alpha
2763 )),
2764 None => None
2765 };
2766 let line_cap = match line_cap {
2767 Some(cap) => match cap.as_str() {
2768 "butt" => Some("butt"),
2769 "round" => Some("round"),
2770 "square" => Some("square"),
2771 _ => Some("butt")
2772 },
2773 None => None
2774 };
2775 let line_join = match line_join {
2776 Some(join) => match join.as_str() {
2777 "miter" => Some("miter"),
2778 "round" => Some("round"),
2779 "bevel" => Some("bevel"),
2780 _ => Some("miter")
2781 },
2782 None => None
2783 };
2784 let center = (center.get(0).as_f64().unwrap(), center.get(1).as_f64().unwrap());
2785 return WasmVectorObject {
2786 native_vec_features: number_line(
2787 x_min,
2788 x_max,
2789 x_step,
2790 center,
2791 color,
2792 stroke_width,
2793 line_cap,
2794 line_join,
2795 index,
2796 length,
2797 add_tip,
2798 add_ticks,
2799 tick_size,
2800 angle
2801 )
2802 }
2803}
2804
2805
2806#[wasm_bindgen(js_name = numberToPoint)]
2807pub fn number_to_point_js(
2808 number_line: &WasmVectorObject,
2809 number: f64,
2810 x_min: f64,
2811 x_max: f64
2812) -> Array {
2813 let point = number_to_point(&number_line.native_vec_features, number, x_min, x_max);
2814 Array::of2(&point.0.into(), &point.1.into())
2815}
2816
2817
2818#[wasm_bindgen(js_name = pointToNumber)]
2819pub fn point_to_number_js(
2820 number_line: &WasmVectorObject,
2821 point: Array,
2822 x_min: f64,
2823 x_max: f64
2824) -> f64 {
2825 let point = (point.get(0).as_f64().unwrap(), point.get(1).as_f64().unwrap());
2826 point_to_number(&number_line.native_vec_features, point, x_min, x_max)
2827}
2828
2829
2830#[wasm_bindgen(js_name = getNumbersTex)]
2831pub async fn get_numbers_tex_js(
2832 number_line: WasmVectorObject,
2833 numbers: Array,
2834 number_to_vector: Function,
2835 x_min: f64,
2836 x_max: f64,
2837 height: f64,
2838 direction: Option<Array>,
2839 buff: Option<f64>,
2840 index: Option<usize>
2841) -> WasmVectorObject {
2842 let numbers = numbers.iter().map(|number| number.as_f64().unwrap()).collect();
2843 let direction = match direction {
2844 Some(direction) => Some((direction.get(0).as_f64().unwrap(), direction.get(1).as_f64().unwrap())),
2845 None => None
2846 };
2847 let index = match index {
2848 Some(index) => Some(index),
2849 None => None
2850 };
2851 return WasmVectorObject {
2852 native_vec_features: get_numbers_tex(
2853 number_line.native_vec_features,
2854 numbers,
2855 number_to_vector,
2856 x_min,
2857 x_max,
2858 height,
2859 direction,
2860 buff,
2861 index
2862 ).await
2863 }
2864}
2865
2866
2867#[wasm_bindgen(js_name = svgToVector)]
2868pub async fn svg_to_vector_js(
2869 svg: String,
2870 font_urls_map: Option<Map>
2871) -> WasmVectorObject {
2872 let vec_obj = WasmVectorObject {
2873 native_vec_features: svg_to_vector_pin(&svg, font_urls_map).await
2874 };
2875 vec_obj
2876}