geo_aid_script/unroll/library/
intersection.rs1use num_traits::One;
4
5use crate::{math::Build, token::number::ProcNum};
6
7use super::prelude::*;
8
9fn intersection_function_ll(
11 k: Expr<Line>,
12 l: Expr<Line>,
13 context: &CompileContext,
14 display: Properties,
15) -> Expr<Point> {
16 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
26fn 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
45fn 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#[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
78pub 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}