Move sketch functions to KCL; remove Rust decl dead code (#7335)
Signed-off-by: Nick Cameron <nrc@ncameron.org>
This commit is contained in:
@ -28,14 +28,10 @@ pub mod utils;
|
||||
|
||||
use anyhow::Result;
|
||||
pub use args::Args;
|
||||
use indexmap::IndexMap;
|
||||
use lazy_static::lazy_static;
|
||||
|
||||
use crate::{
|
||||
docs::StdLibFn,
|
||||
errors::KclError,
|
||||
execution::{types::PrimitiveType, ExecState, KclValue},
|
||||
parsing::ast::types::Name,
|
||||
};
|
||||
|
||||
pub type StdFn = fn(
|
||||
@ -43,35 +39,6 @@ pub type StdFn = fn(
|
||||
Args,
|
||||
) -> std::pin::Pin<Box<dyn std::future::Future<Output = Result<KclValue, KclError>> + Send + '_>>;
|
||||
|
||||
lazy_static! {
|
||||
static ref CORE_FNS: Vec<Box<dyn StdLibFn>> = vec![
|
||||
Box::new(crate::std::sketch::InvoluteCircular),
|
||||
Box::new(crate::std::sketch::Line),
|
||||
Box::new(crate::std::sketch::XLine),
|
||||
Box::new(crate::std::sketch::YLine),
|
||||
Box::new(crate::std::sketch::AngledLine),
|
||||
Box::new(crate::std::sketch::AngledLineThatIntersects),
|
||||
Box::new(crate::std::sketch::StartSketchOn),
|
||||
Box::new(crate::std::sketch::StartProfile),
|
||||
Box::new(crate::std::sketch::ProfileStartX),
|
||||
Box::new(crate::std::sketch::ProfileStartY),
|
||||
Box::new(crate::std::sketch::ProfileStart),
|
||||
Box::new(crate::std::sketch::Close),
|
||||
Box::new(crate::std::sketch::Arc),
|
||||
Box::new(crate::std::sketch::TangentialArc),
|
||||
Box::new(crate::std::sketch::BezierCurve),
|
||||
Box::new(crate::std::sketch::Subtract2D),
|
||||
];
|
||||
}
|
||||
|
||||
pub fn name_in_stdlib(name: &str) -> bool {
|
||||
CORE_FNS.iter().any(|f| f.name() == name)
|
||||
}
|
||||
|
||||
pub fn get_stdlib_fn(name: &str) -> Option<Box<dyn StdLibFn>> {
|
||||
CORE_FNS.iter().find(|f| f.name() == name).cloned()
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct StdFnProps {
|
||||
pub name: String,
|
||||
@ -385,6 +352,70 @@ pub(crate) fn std_fn(path: &str, fn_name: &str) -> (crate::std::StdFn, StdFnProp
|
||||
|e, a| Box::pin(crate::std::segment::tangent_to_end(e, a)),
|
||||
StdFnProps::default("std::sketch::tangentToEnd"),
|
||||
),
|
||||
("sketch", "profileStart") => (
|
||||
|e, a| Box::pin(crate::std::sketch::profile_start(e, a)),
|
||||
StdFnProps::default("std::sketch::profileStart"),
|
||||
),
|
||||
("sketch", "profileStartX") => (
|
||||
|e, a| Box::pin(crate::std::sketch::profile_start_x(e, a)),
|
||||
StdFnProps::default("std::sketch::profileStartX"),
|
||||
),
|
||||
("sketch", "profileStartY") => (
|
||||
|e, a| Box::pin(crate::std::sketch::profile_start_y(e, a)),
|
||||
StdFnProps::default("std::sketch::profileStartY"),
|
||||
),
|
||||
("sketch", "startSketchOn") => (
|
||||
|e, a| Box::pin(crate::std::sketch::start_sketch_on(e, a)),
|
||||
StdFnProps::default("std::sketch::startSketchOn").include_in_feature_tree(),
|
||||
),
|
||||
("sketch", "startProfile") => (
|
||||
|e, a| Box::pin(crate::std::sketch::start_profile(e, a)),
|
||||
StdFnProps::default("std::sketch::startProfile"),
|
||||
),
|
||||
("sketch", "involuteCircular") => (
|
||||
|e, a| Box::pin(crate::std::sketch::involute_circular(e, a)),
|
||||
StdFnProps::default("std::sketch::startProfile"),
|
||||
),
|
||||
("sketch", "line") => (
|
||||
|e, a| Box::pin(crate::std::sketch::line(e, a)),
|
||||
StdFnProps::default("std::sketch::startProfile"),
|
||||
),
|
||||
("sketch", "xLine") => (
|
||||
|e, a| Box::pin(crate::std::sketch::x_line(e, a)),
|
||||
StdFnProps::default("std::sketch::startProfile"),
|
||||
),
|
||||
("sketch", "yLine") => (
|
||||
|e, a| Box::pin(crate::std::sketch::y_line(e, a)),
|
||||
StdFnProps::default("std::sketch::startProfile"),
|
||||
),
|
||||
("sketch", "angledLine") => (
|
||||
|e, a| Box::pin(crate::std::sketch::angled_line(e, a)),
|
||||
StdFnProps::default("std::sketch::startProfile"),
|
||||
),
|
||||
("sketch", "angledLineThatIntersects") => (
|
||||
|e, a| Box::pin(crate::std::sketch::angled_line_that_intersects(e, a)),
|
||||
StdFnProps::default("std::sketch::startProfile"),
|
||||
),
|
||||
("sketch", "close") => (
|
||||
|e, a| Box::pin(crate::std::sketch::close(e, a)),
|
||||
StdFnProps::default("std::sketch::startProfile"),
|
||||
),
|
||||
("sketch", "arc") => (
|
||||
|e, a| Box::pin(crate::std::sketch::arc(e, a)),
|
||||
StdFnProps::default("std::sketch::startProfile"),
|
||||
),
|
||||
("sketch", "tangentialArc") => (
|
||||
|e, a| Box::pin(crate::std::sketch::tangential_arc(e, a)),
|
||||
StdFnProps::default("std::sketch::startProfile"),
|
||||
),
|
||||
("sketch", "bezierCurve") => (
|
||||
|e, a| Box::pin(crate::std::sketch::bezier_curve(e, a)),
|
||||
StdFnProps::default("std::sketch::startProfile"),
|
||||
),
|
||||
("sketch", "subtract2d") => (
|
||||
|e, a| Box::pin(crate::std::sketch::subtract_2d(e, a)),
|
||||
StdFnProps::default("std::sketch::startProfile").include_in_feature_tree(),
|
||||
),
|
||||
("appearance", "hexString") => (
|
||||
|e, a| Box::pin(crate::std::appearance::hex_string(e, a)),
|
||||
StdFnProps::default("std::appearance::hexString"),
|
||||
@ -409,56 +440,5 @@ pub(crate) fn std_ty(path: &str, fn_name: &str) -> (PrimitiveType, StdFnProps) {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct StdLib {
|
||||
pub fns: IndexMap<String, Box<dyn StdLibFn>>,
|
||||
}
|
||||
|
||||
impl std::fmt::Debug for StdLib {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
f.debug_struct("StdLib").field("fns.len()", &self.fns.len()).finish()
|
||||
}
|
||||
}
|
||||
|
||||
impl StdLib {
|
||||
pub fn new() -> Self {
|
||||
let fns = CORE_FNS
|
||||
.clone()
|
||||
.into_iter()
|
||||
.map(|internal_fn| (internal_fn.name(), internal_fn))
|
||||
.collect();
|
||||
|
||||
Self { fns }
|
||||
}
|
||||
|
||||
// Get the combined hashmaps.
|
||||
pub fn combined(&self) -> IndexMap<String, Box<dyn StdLibFn>> {
|
||||
self.fns.clone()
|
||||
}
|
||||
|
||||
pub fn get(&self, name: &str) -> Option<Box<dyn StdLibFn>> {
|
||||
self.fns.get(name).cloned()
|
||||
}
|
||||
|
||||
pub fn get_rust_function(&self, name: &Name) -> Option<Box<dyn StdLibFn>> {
|
||||
if let Some(name) = name.local_ident() {
|
||||
if let Some(f) = self.get(name.inner) {
|
||||
return Some(f);
|
||||
}
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
|
||||
pub fn contains_key(&self, key: &str) -> bool {
|
||||
self.fns.contains_key(key)
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for StdLib {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
/// The default tolerance for modeling commands in [`kittycad_modeling_cmds::length_unit::LengthUnit`].
|
||||
const DEFAULT_TOLERANCE: f64 = 0.0000001;
|
||||
|
Reference in New Issue
Block a user