Skip to main content

exact_poly/wasm/
primitives.rs

1use wasm_bindgen::prelude::*;
2
3#[wasm_bindgen]
4pub fn cross2d(ax: i64, ay: i64, bx: i64, by: i64, cx: i64, cy: i64) -> String {
5    crate::primitives::cross2d(ax, ay, bx, by, cx, cy).to_string()
6}
7
8#[wasm_bindgen]
9pub fn orientation(ax: i64, ay: i64, bx: i64, by: i64, cx: i64, cy: i64) -> String {
10    match crate::primitives::orientation(ax, ay, bx, by, cx, cy) {
11        crate::primitives::Orientation::CounterClockwise => "CounterClockwise",
12        crate::primitives::Orientation::Clockwise => "Clockwise",
13        crate::primitives::Orientation::Collinear => "Collinear",
14    }
15    .into()
16}
17
18#[wasm_bindgen]
19pub fn is_left(ax: i64, ay: i64, bx: i64, by: i64, px: i64, py: i64) -> bool {
20    crate::primitives::is_left(ax, ay, bx, by, px, py)
21}
22
23#[wasm_bindgen]
24pub fn is_left_or_on(ax: i64, ay: i64, bx: i64, by: i64, px: i64, py: i64) -> bool {
25    crate::primitives::is_left_or_on(ax, ay, bx, by, px, py)
26}
27
28#[wasm_bindgen]
29pub fn is_right(ax: i64, ay: i64, bx: i64, by: i64, px: i64, py: i64) -> bool {
30    crate::primitives::is_right(ax, ay, bx, by, px, py)
31}
32
33#[wasm_bindgen]
34pub fn is_right_or_on(ax: i64, ay: i64, bx: i64, by: i64, px: i64, py: i64) -> bool {
35    crate::primitives::is_right_or_on(ax, ay, bx, by, px, py)
36}
37
38#[wasm_bindgen]
39pub fn is_collinear_pts(ax: i64, ay: i64, bx: i64, by: i64, px: i64, py: i64) -> bool {
40    crate::primitives::is_collinear_pts(ax, ay, bx, by, px, py)
41}
42
43#[wasm_bindgen]
44pub fn is_reflex(
45    prev_x: i64,
46    prev_y: i64,
47    curr_x: i64,
48    curr_y: i64,
49    next_x: i64,
50    next_y: i64,
51) -> bool {
52    crate::primitives::is_reflex(prev_x, prev_y, curr_x, curr_y, next_x, next_y)
53}
54
55#[wasm_bindgen]
56pub fn edge_squared_length(ax: i64, ay: i64, bx: i64, by: i64) -> String {
57    crate::primitives::edge_squared_length(ax, ay, bx, by).to_string()
58}
59
60#[wasm_bindgen]
61pub fn point_on_segment(px: i64, py: i64, ax: i64, ay: i64, bx: i64, by: i64) -> bool {
62    crate::primitives::point_on_segment(px, py, ax, ay, bx, by)
63}
64
65#[wasm_bindgen]
66pub fn segments_properly_intersect(
67    a1x: i64,
68    a1y: i64,
69    a2x: i64,
70    a2y: i64,
71    b1x: i64,
72    b1y: i64,
73    b2x: i64,
74    b2y: i64,
75) -> bool {
76    crate::primitives::segments_properly_intersect(a1x, a1y, a2x, a2y, b1x, b1y, b2x, b2y)
77}
78
79#[wasm_bindgen]
80pub fn segments_intersect(
81    a1x: i64,
82    a1y: i64,
83    a2x: i64,
84    a2y: i64,
85    b1x: i64,
86    b1y: i64,
87    b2x: i64,
88    b2y: i64,
89) -> bool {
90    crate::primitives::segments_intersect(a1x, a1y, a2x, a2y, b1x, b1y, b2x, b2y)
91}