geo_aid_script/unroll/library/
intersection.rs

1//! The `intersection` function
2
3use num_traits::One;
4
5use crate::{math::Build, token::number::ProcNum};
6
7use super::prelude::*;
8
9/// `intesection(line, line)` - intersection of two lines.
10fn intersection_function_ll(
11    k: Expr<Line>,
12    l: Expr<Line>,
13    context: &CompileContext,
14    display: Properties,
15) -> Expr<Point> {
16    // println!("{display:#?}");
17    let mut expr = context.intersection_display(k, l, display);
18
19    if let Some(node) = &mut expr.node {
20        node.set_associated(Associated);
21    }
22
23    expr
24}
25
26/// `intesection(line, circle)` - intersection of a line and a circle.
27fn intersection_function_lc(
28    k: Expr<Line>,
29    omega: Expr<Circle>,
30    context: &mut CompileContext,
31    display: Properties,
32) -> Expr<Point> {
33    let mut point = context.free_point_display(display);
34
35    context.point_on_line(&point, &k, ProcNum::one());
36    context.point_on_circle(&point, &omega, ProcNum::one());
37
38    if let Some(node) = &mut point.node {
39        node.set_associated(Associated);
40    }
41
42    point
43}
44
45/// `intesection(circle, circle)` - intersection of two circle.
46fn intersection_function_cc(
47    o1: Expr<Circle>,
48    o2: Expr<Circle>,
49    context: &mut CompileContext,
50    display: Properties,
51) -> Expr<Point> {
52    let mut point = context.free_point_display(display);
53
54    context.point_on_circle(&point, &o1, ProcNum::one());
55    context.point_on_circle(&point, &o2, ProcNum::one());
56
57    if let Some(node) = &mut point.node {
58        node.set_associated(Associated);
59    }
60
61    point
62}
63
64/// The associated data. No properties.
65#[derive(Debug)]
66pub struct Associated;
67
68impl BuildAssociated<PointNode> for Associated {
69    fn build_associated(
70        self: Box<Self>,
71        _build: &mut Build,
72        associated: &mut HierarchyNode<PointNode>,
73    ) {
74        associated.root.display_dot.set_if_unset(false);
75    }
76}
77
78/// Register the function
79pub fn register(library: &mut Library) {
80    library.add(
81        Function::new("intersection")
82            .overload(intersection_function_ll)
83            .overload(intersection_function_lc)
84            .overload(intersection_function_cc),
85    );
86}