Bezier-rs: Insert function for subpath (#876)

* Add manipulator

* Add manipulator group

* Add UI

* Address comments and rebase

* Renamed add_manipulator_group to insert

Co-authored-by: Rob Nadal <robnadal44@gmail.com>
This commit is contained in:
Hannah Li
2023-01-12 18:26:25 -08:00
committed by Keavon Chambers
co-authored by Rob Nadal
parent 23b4306eab
commit 05a2cd32a5
5 changed files with 194 additions and 0 deletions
@@ -601,6 +601,13 @@ export default defineComponent({
name: "Constructor",
callback: (subpath: WasmSubpathInstance): string => subpath.to_svg(),
},
{
name: "Insert",
callback: (subpath: WasmSubpathInstance, options: Record<string, number>, _: undefined, computeType: ComputeType): string => subpath.insert(options.computeArgument, computeType),
sliderOptions: [{ ...tSliderOptions, variable: "computeArgument" }],
// TODO: Uncomment this after implementing the Euclidean version
// chooseComputeType: true,
},
{
name: "Length",
callback: (subpath: WasmSubpathInstance): string => subpath.length(),
@@ -53,6 +53,26 @@ impl WasmSubpath {
subpath_svg
}
pub fn insert(&self, t: f64, compute_type: String) -> String {
let mut subpath = self.0.clone();
let point = match compute_type.as_str() {
"Euclidean" => {
let parameter = ComputeType::Euclidean(t);
subpath.insert(parameter);
self.0.evaluate(parameter)
}
"Parametric" => {
let parameter = ComputeType::Parametric(t);
subpath.insert(parameter);
self.0.evaluate(parameter)
}
_ => panic!("Unexpected ComputeType string: '{}'", compute_type),
};
let point_text = draw_circle(point, 4., RED, 1.5, WHITE);
wrap_svg_tag(format!("{}{}", WasmSubpath(subpath).to_default_svg(), point_text))
}
pub fn length(&self) -> String {
let length_text = draw_text(format!("Length: {:.2}", self.0.length(None)), 5., 193., BLACK);
wrap_svg_tag(format!("{}{}", self.to_default_svg(), length_text))