1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
use crate::link::{
	builder::{CollisionBuilder, LinkBuilder, VisualBuilder},
	geometry::{BoxGeometry, CylinderGeometry, GeometryInterface, SphereGeometry},
};

/// TODO: Finalize, this is temp
/// TODO: ADD NAMED CHOICE for Vis & Col
/// TODO: Add material Specifierer
/// TODO: Add Inertial data options
/// TODO: ADD TEST?
pub fn new_quick_link(
	link_name: impl Into<String>,
	geometry: Box<dyn GeometryInterface + Sync + Send>,
) -> LinkBuilder {
	let link_name = link_name.into();
	let mut link = LinkBuilder::new(link_name.clone());

	let mut visual_name = link_name.clone();
	visual_name.push_str("_visual");
	link = link.add_visual(VisualBuilder::new_full(
		visual_name.into(),
		None, // TODO: NOT HOW I WANT IT
		geometry.boxed_clone(),
		None, // TODO: TEMP
	));

	let mut collision_name = link_name;
	collision_name.push_str("_collision");
	link = link.add_collider(CollisionBuilder::new_full(
		collision_name.into(),
		None,
		geometry,
	));

	link
}

/// TODO: Finalize, this is temp
/// TODO: ADD NAMED CHOICE for Vis & Col
/// TODO: Add material Specifierer
/// TODO: Add Inertial data options
/// TODO: ADD TEST?
pub fn new_box_link(
	link_name: impl Into<String>,
	side1: f32,
	side2: f32,
	side3: f32,
) -> LinkBuilder {
	let geometry = BoxGeometry::new(side1, side2, side3);

	new_quick_link(link_name, geometry.into())
}

/// TODO: Finalize, this is temp
/// TODO: ADD NAMED CHOICE for Vis & Col
/// TODO: Add material Specifierer
/// TODO: Add Inertial data options
/// TODO: ADD TEST?
/// TODO: Orientation??
pub fn new_cylinder_link(link_name: impl Into<String>, radius: f32, length: f32) -> LinkBuilder {
	let geometry = CylinderGeometry::new(radius, length);

	new_quick_link(link_name, geometry.into())
}

/// TODO: Finalize, this is temp
/// TODO: ADD NAMED CHOICE for Vis & Col
/// TODO: Add material Specifierer
/// TODO: Add Inertial data options
/// TODO: ADD TEST?
pub fn new_sphere_link(link_name: impl Into<String>, radius: f32) -> LinkBuilder {
	let geometry = SphereGeometry::new(radius);

	new_quick_link(link_name, geometry.into())
}

#[cfg(test)]
mod tests {
	use crate::{link::helper_functions::*, KinematicInterface};

	#[test]
	fn test_new_box_link() {
		let tree = new_box_link("Zelda", 2f32, 3f32, 5f32).build_tree();

		assert_eq!(tree.get_links().try_read().unwrap().len(), 1);
		assert_eq!(tree.get_newest_link().try_read().unwrap().name(), "Zelda");
		assert_eq!(tree.get_newest_link().try_read().unwrap().visuals.len(), 1);
		assert_eq!(
			tree.get_newest_link().try_read().unwrap().visuals[0].name,
			Some("Zelda_visual".into())
		);
		assert_eq!(
			tree.get_newest_link().try_read().unwrap().visuals[0]
				.geometry
				.volume(),
			30f32
		);
		assert_eq!(
			tree.get_newest_link().try_read().unwrap().visuals[0]
				.geometry
				.surface_area(),
			62f32
		);

		assert_eq!(
			tree.get_newest_link().try_read().unwrap().colliders.len(),
			1
		);
		assert_eq!(
			tree.get_newest_link().try_read().unwrap().colliders[0].name,
			Some("Zelda_collision".into())
		);
		assert_eq!(
			tree.get_newest_link().try_read().unwrap().colliders[0]
				.geometry
				.volume(),
			30f32
		);
		assert_eq!(
			tree.get_newest_link().try_read().unwrap().colliders[0]
				.geometry
				.surface_area(),
			62f32
		);
		// TODO: UPDATE WHEN FUNCTION IS FINALIZED
		// TODO: TEST INERTIAL DATA
	}
}