Remove some deprecated functions from std (#6531)

Signed-off-by: Nick Cameron <nrc@ncameron.org>
This commit is contained in:
Nick Cameron
2025-04-29 12:24:18 +12:00
committed by GitHub
parent 8867258e47
commit aca5fdb521
60 changed files with 3632 additions and 4759 deletions

View File

@ -571,33 +571,6 @@ impl Args {
)
}
pub(crate) fn get_number_with_type(&self) -> Result<TyF64, KclError> {
FromArgs::from_args(self, 0)
}
pub(crate) fn get_number_typed(&self, ty: &RuntimeType, exec_state: &mut ExecState) -> Result<f64, KclError> {
let Some(arg) = self.args.first() else {
return Err(KclError::Semantic(KclErrorDetails {
message: "Expected an argument".to_owned(),
source_ranges: vec![self.source_range],
}));
};
arg.value.coerce(ty, exec_state).map_err(|_| {
let actual_type_name = arg.value.human_friendly_type();
let message = format!(
"This function expected the input argument to be {} but it's actually of type {actual_type_name}",
ty.human_friendly_type(),
);
KclError::Semantic(KclErrorDetails {
source_ranges: arg.source_ranges(),
message,
})
})?;
Ok(TyF64::from_kcl_val(&arg.value).unwrap().n)
}
pub(crate) async fn get_adjacent_face_to_tag(
&self,
exec_state: &mut ExecState,
@ -975,6 +948,7 @@ impl<'a> FromKclValue<'a> for crate::execution::Point3d {
let_field_of!(obj, x, TyF64);
let_field_of!(obj, y, TyF64);
let_field_of!(obj, z, TyF64);
// TODO here and below we could use coercing combination.
let (a, ty) = NumericType::combine_eq_array(&[x, y, z]);
return Some(Self {
x: a[0],

View File

@ -1,41 +0,0 @@
//! Conversions between types.
use kcl_derive_docs::stdlib;
use crate::{
errors::KclError,
execution::{ExecState, KclValue},
std::Args,
};
/// Converts a number to integer.
pub async fn int(_exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
let num = args.get_number_with_type()?;
let converted = inner_int(num.n)?;
Ok(args.make_user_val_from_f64_with_type(num.map_value(converted)))
}
/// Convert a number to an integer.
///
/// DEPRECATED use floor(), ceil(), or round().
///
/// ```no_run
/// n = int(ceil(5/2))
/// assert(n, isEqualTo = 3, error = "5/2 = 2.5, rounded up makes 3")
/// // Draw n cylinders.
/// startSketchOn('XZ')
/// |> circle(center = [0, 0], radius = 2 )
/// |> extrude(length = 5)
/// |> patternTransform(instances = n, transform = fn(id) {
/// return { translate = [4 * id, 0, 0] }
/// })
/// ```
#[stdlib {
name = "int",
tags = ["convert"],
deprecated = true,
}]
fn inner_int(num: f64) -> Result<f64, KclError> {
Ok(num)
}

View File

@ -117,34 +117,6 @@ pub async fn tan(exec_state: &mut ExecState, args: Args) -> Result<KclValue, Kcl
Ok(args.make_user_val_from_f64_with_type(TyF64::count(num.tan())))
}
/// Return the value of `pi`. Archimedes constant (π).
pub async fn pi(_exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
let result = inner_pi()?;
Ok(args.make_user_val_from_f64_with_type(TyF64::count(result)))
}
/// Return the value of `pi`. Archimedes constant (π).
///
/// **DEPRECATED** use the constant PI
///
/// ```no_run
/// circumference = 70
///
/// exampleSketch = startSketchOn("XZ")
/// |> circle( center = [0, 0], radius = circumference/ (2 * pi()) )
///
/// example = extrude(exampleSketch, length = 5)
/// ```
#[stdlib {
name = "pi",
tags = ["math"],
deprecated = true,
}]
fn inner_pi() -> Result<f64, KclError> {
Ok(std::f64::consts::PI)
}
/// Compute the square root of a number.
pub async fn sqrt(exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
let input: TyF64 = args.get_unlabeled_kw_arg_typed("input", &RuntimeType::num_any(), exec_state)?;
@ -747,70 +719,6 @@ fn inner_ln(input: f64) -> f64 {
input.ln()
}
/// Return the value of Eulers number `e`.
pub async fn e(_exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
let result = inner_e()?;
Ok(args.make_user_val_from_f64_with_type(TyF64::new(result, NumericType::count())))
}
/// Return the value of Eulers number `e`.
///
/// **DEPRECATED** use the constant E
///
/// ```no_run
/// exampleSketch = startSketchOn("XZ")
/// |> startProfile(at = [0, 0])
/// |> angledLine(
/// angle = 30,
/// length = 2 * e() ^ 2,
/// )
/// |> yLine(endAbsolute = 0)
/// |> close()
///
/// example = extrude(exampleSketch, length = 10)
/// ```
#[stdlib {
name = "e",
tags = ["math"],
deprecated = true,
}]
fn inner_e() -> Result<f64, KclError> {
Ok(std::f64::consts::E)
}
/// Return the value of `tau`. The full circle constant (τ). Equal to 2π.
pub async fn tau(_exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
let result = inner_tau()?;
Ok(args.make_user_val_from_f64_with_type(TyF64::new(result, NumericType::count())))
}
/// Return the value of `tau`. The full circle constant (τ). Equal to 2π.
///
/// **DEPRECATED** use the constant TAU
///
/// ```no_run
/// exampleSketch = startSketchOn("XZ")
/// |> startProfile(at = [0, 0])
/// |> angledLine(
/// angle = 50,
/// length = 10 * tau(),
/// )
/// |> yLine(endAbsolute = 0)
/// |> close()
///
/// example = extrude(exampleSketch, length = 5)
/// ```
#[stdlib {
name = "tau",
tags = ["math"],
deprecated = true,
}]
fn inner_tau() -> Result<f64, KclError> {
Ok(std::f64::consts::TAU)
}
#[cfg(test)]
mod tests {
use pretty_assertions::assert_eq;

View File

@ -7,7 +7,6 @@ pub mod assert;
pub mod axis_or_reference;
pub mod chamfer;
pub mod clone;
pub mod convert;
pub mod csg;
pub mod edge;
pub mod extrude;
@ -25,7 +24,6 @@ pub mod shell;
pub mod sketch;
pub mod sweep;
pub mod transform;
pub mod units;
pub mod utils;
use anyhow::Result;
@ -59,7 +57,6 @@ lazy_static! {
Box::new(LegAngX),
Box::new(LegAngY),
Box::new(crate::std::appearance::Appearance),
Box::new(crate::std::convert::Int),
Box::new(crate::std::extrude::Extrude),
Box::new(crate::std::segment::SegEnd),
Box::new(crate::std::segment::SegEndX),
@ -111,9 +108,6 @@ lazy_static! {
Box::new(crate::std::math::Asin),
Box::new(crate::std::math::Atan),
Box::new(crate::std::math::Atan2),
Box::new(crate::std::math::Pi),
Box::new(crate::std::math::E),
Box::new(crate::std::math::Tau),
Box::new(crate::std::math::Sqrt),
Box::new(crate::std::math::Abs),
Box::new(crate::std::math::Rem),
@ -127,12 +121,6 @@ lazy_static! {
Box::new(crate::std::math::Log2),
Box::new(crate::std::math::Log10),
Box::new(crate::std::math::Ln),
Box::new(crate::std::units::FromMm),
Box::new(crate::std::units::FromInches),
Box::new(crate::std::units::FromFt),
Box::new(crate::std::units::FromM),
Box::new(crate::std::units::FromCm),
Box::new(crate::std::units::FromYd),
Box::new(crate::std::assert::Assert),
Box::new(crate::std::assert::AssertIs),
Box::new(crate::std::transform::Scale),

View File

@ -1177,6 +1177,12 @@ async fn inner_start_sketch_on(
}
SketchData::Plane(plane) => {
if plane.value == crate::exec::PlaneType::Uninit {
if plane.origin.units == UnitLen::Unknown {
return Err(KclError::Semantic(KclErrorDetails {
message: "Origin of plane has unknown units".to_string(),
source_ranges: vec![args.source_range],
}));
}
let plane = make_sketch_plane_from_orientation(plane.into_plane_data(), exec_state, args).await?;
Ok(SketchSurface::Plane(plane))
} else {
@ -1272,7 +1278,7 @@ async fn make_sketch_plane_from_orientation(
pub async fn start_profile(exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
// let (start, sketch_surface, tag) = args.get_data_and_sketch_surface()?;
let sketch_surface = args.get_unlabeled_kw_arg("startProfileOn")?;
let start: [TyF64; 2] = args.get_kw_arg("at")?;
let start: [TyF64; 2] = args.get_kw_arg_typed("at", &RuntimeType::point2d(), exec_state)?;
let tag = args.get_kw_arg_opt(NEW_TAG_KW)?;
let sketch = inner_start_profile(sketch_surface, start, tag, exec_state, args).await?;

View File

@ -1,311 +0,0 @@
//! Functions related to unitsematics.
use anyhow::Result;
use kcl_derive_docs::stdlib;
use crate::{
errors::KclError,
execution::{
types::{RuntimeType, UnitLen},
ExecState, KclValue,
},
std::{args::TyF64, Args},
};
/// Millimeters conversion factor for current files units.
pub async fn from_mm(exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
let input = args.get_number_typed(&RuntimeType::known_length(UnitLen::Mm), exec_state)?;
let result = inner_from_mm(input, exec_state)?;
Ok(args.make_user_val_from_f64_with_type(TyF64::new(
result,
exec_state.current_default_units().expect_default_length(),
)))
}
/// Converts a number from mm to the current default unit.
///
/// *DEPRECATED* prefer using explicit numeric suffixes (e.g., `42mm`) or the `to...` conversion functions.
///
/// No matter what units the current file uses, this function will always return a number equivalent
/// to the input in millimeters.
///
/// For example, if the current file uses inches, `fromMm(1)` will return `1/25.4`.
/// If the current file uses millimeters, `fromMm(1)` will return `1`.
///
/// **Caution**: This function is only intended to be used when you absolutely MUST
/// have different units in your code than the file settings. Otherwise, it is
/// a bad pattern to use this function.
///
/// We merely provide these functions for convenience and readability, as
/// `fromMm(10)` is more readable that your intent is "I want 10 millimeters" than
/// `10 * (1/25.4)`, if the file settings are in inches.
///
/// ```no_run
/// totalWidth = fromMm(10)
/// ```
#[stdlib {
name = "fromMm",
tags = ["units"],
deprecated = true,
}]
fn inner_from_mm(input: f64, exec_state: &ExecState) -> Result<f64, KclError> {
Ok(match exec_state.length_unit() {
UnitLen::Mm => input,
UnitLen::Inches => measurements::Length::from_millimeters(input).as_inches(),
UnitLen::Feet => measurements::Length::from_millimeters(input).as_feet(),
UnitLen::M => measurements::Length::from_millimeters(input).as_meters(),
UnitLen::Cm => measurements::Length::from_millimeters(input).as_centimeters(),
UnitLen::Yards => measurements::Length::from_millimeters(input).as_yards(),
UnitLen::Unknown => unreachable!(),
})
}
/// Inches conversion factor for current files units.
pub async fn from_inches(exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
let input = args.get_number_typed(&RuntimeType::known_length(UnitLen::Inches), exec_state)?;
let result = inner_from_inches(input, exec_state)?;
Ok(args.make_user_val_from_f64_with_type(TyF64::new(
result,
exec_state.current_default_units().expect_default_length(),
)))
}
/// Converts a number from inches to the current default unit.
///
/// *DEPRECATED* prefer using explicit numeric suffixes (e.g., `42inch`) or the `to...` conversion functions.
///
/// No matter what units the current file uses, this function will always return a number equivalent
/// to the input in inches.
///
/// For example, if the current file uses inches, `fromInches(1)` will return `1`.
/// If the current file uses millimeters, `fromInches(1)` will return `25.4`.
///
/// **Caution**: This function is only intended to be used when you absolutely MUST
/// have different units in your code than the file settings. Otherwise, it is
/// a bad pattern to use this function.
///
/// We merely provide these functions for convenience and readability, as
/// `fromInches(10)` is more readable that your intent is "I want 10 inches" than
/// `10 * 25.4`, if the file settings are in millimeters.
///
/// ```no_run
/// totalWidth = fromInches(10)
/// ```
#[stdlib {
name = "fromInches",
tags = ["units"],
deprecated = true,
}]
fn inner_from_inches(input: f64, exec_state: &ExecState) -> Result<f64, KclError> {
match exec_state.length_unit() {
UnitLen::Mm => Ok(measurements::Length::from_inches(input).as_millimeters()),
UnitLen::Inches => Ok(input),
UnitLen::Feet => Ok(measurements::Length::from_inches(input).as_feet()),
UnitLen::M => Ok(measurements::Length::from_inches(input).as_meters()),
UnitLen::Cm => Ok(measurements::Length::from_inches(input).as_centimeters()),
UnitLen::Yards => Ok(measurements::Length::from_inches(input).as_yards()),
UnitLen::Unknown => unreachable!(),
}
}
/// Feet conversion factor for current files units.
pub async fn from_ft(exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
let input = args.get_number_typed(&RuntimeType::known_length(UnitLen::Feet), exec_state)?;
let result = inner_from_ft(input, exec_state)?;
Ok(args.make_user_val_from_f64_with_type(TyF64::new(
result,
exec_state.current_default_units().expect_default_length(),
)))
}
/// Converts a number from feet to the current default unit.
///
/// *DEPRECATED* prefer using explicit numeric suffixes (e.g., `42ft`) or the `to...` conversion functions.
///
/// No matter what units the current file uses, this function will always return a number equivalent
/// to the input in feet.
///
/// For example, if the current file uses inches, `fromFt(1)` will return `12`.
/// If the current file uses millimeters, `fromFt(1)` will return `304.8`.
/// If the current file uses feet, `fromFt(1)` will return `1`.
///
/// **Caution**: This function is only intended to be used when you absolutely MUST
/// have different units in your code than the file settings. Otherwise, it is
/// a bad pattern to use this function.
///
/// We merely provide these functions for convenience and readability, as
/// `fromFt(10)` is more readable that your intent is "I want 10 feet" than
/// `10 * 304.8`, if the file settings are in millimeters.
///
/// ```no_run
/// totalWidth = fromFt(10)
/// ```
#[stdlib {
name = "fromFt",
tags = ["units"],
deprecated = true,
}]
fn inner_from_ft(input: f64, exec_state: &ExecState) -> Result<f64, KclError> {
match exec_state.length_unit() {
UnitLen::Mm => Ok(measurements::Length::from_feet(input).as_millimeters()),
UnitLen::Inches => Ok(measurements::Length::from_feet(input).as_inches()),
UnitLen::Feet => Ok(input),
UnitLen::M => Ok(measurements::Length::from_feet(input).as_meters()),
UnitLen::Cm => Ok(measurements::Length::from_feet(input).as_centimeters()),
UnitLen::Yards => Ok(measurements::Length::from_feet(input).as_yards()),
UnitLen::Unknown => unreachable!(),
}
}
/// Meters conversion factor for current files units.
pub async fn from_m(exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
let input = args.get_number_typed(&RuntimeType::known_length(UnitLen::M), exec_state)?;
let result = inner_from_m(input, exec_state)?;
Ok(args.make_user_val_from_f64_with_type(TyF64::new(
result,
exec_state.current_default_units().expect_default_length(),
)))
}
/// Converts a number from meters to the current default unit.
///
/// *DEPRECATED* prefer using explicit numeric suffixes (e.g., `42m`) or the `to...` conversion functions.
///
/// No matter what units the current file uses, this function will always return a number equivalent
/// to the input in meters.
///
/// For example, if the current file uses inches, `fromM(1)` will return `39.3701`.
/// If the current file uses millimeters, `fromM(1)` will return `1000`.
/// If the current file uses meters, `fromM(1)` will return `1`.
///
/// **Caution**: This function is only intended to be used when you absolutely MUST
/// have different units in your code than the file settings. Otherwise, it is
/// a bad pattern to use this function.
///
/// We merely provide these functions for convenience and readability, as
/// `fromM(10)` is more readable that your intent is "I want 10 meters" than
/// `10 * 1000`, if the file settings are in millimeters.
///
/// ```no_run
/// totalWidth = 10 * fromM(10)
/// ```
#[stdlib {
name = "fromM",
tags = ["units"],
deprecated = true,
}]
fn inner_from_m(input: f64, exec_state: &ExecState) -> Result<f64, KclError> {
match exec_state.length_unit() {
UnitLen::Mm => Ok(measurements::Length::from_meters(input).as_millimeters()),
UnitLen::Inches => Ok(measurements::Length::from_meters(input).as_inches()),
UnitLen::Feet => Ok(measurements::Length::from_meters(input).as_feet()),
UnitLen::M => Ok(input),
UnitLen::Cm => Ok(measurements::Length::from_meters(input).as_centimeters()),
UnitLen::Yards => Ok(measurements::Length::from_meters(input).as_yards()),
UnitLen::Unknown => unreachable!(),
}
}
/// Centimeters conversion factor for current files units.
pub async fn from_cm(exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
let input = args.get_number_typed(&RuntimeType::known_length(UnitLen::Cm), exec_state)?;
let result = inner_from_cm(input, exec_state)?;
Ok(args.make_user_val_from_f64_with_type(TyF64::new(
result,
exec_state.current_default_units().expect_default_length(),
)))
}
/// Converts a number from centimeters to the current default unit.
///
/// *DEPRECATED* prefer using explicit numeric suffixes (e.g., `42cm`) or the `to...` conversion functions.
///
/// No matter what units the current file uses, this function will always return a number equivalent
/// to the input in centimeters.
///
/// For example, if the current file uses inches, `fromCm(1)` will return `0.393701`.
/// If the current file uses millimeters, `fromCm(1)` will return `10`.
/// If the current file uses centimeters, `fromCm(1)` will return `1`.
///
/// **Caution**: This function is only intended to be used when you absolutely MUST
/// have different units in your code than the file settings. Otherwise, it is
/// a bad pattern to use this function.
///
/// We merely provide these functions for convenience and readability, as
/// `fromCm(10)` is more readable that your intent is "I want 10 centimeters" than
/// `10 * 10`, if the file settings are in millimeters.
///
/// ```no_run
/// totalWidth = fromCm(10)
/// ```
#[stdlib {
name = "fromCm",
tags = ["units"],
deprecated = true,
}]
fn inner_from_cm(input: f64, exec_state: &ExecState) -> Result<f64, KclError> {
match exec_state.length_unit() {
UnitLen::Mm => Ok(measurements::Length::from_centimeters(input).as_millimeters()),
UnitLen::Inches => Ok(measurements::Length::from_centimeters(input).as_inches()),
UnitLen::Feet => Ok(measurements::Length::from_centimeters(input).as_feet()),
UnitLen::M => Ok(measurements::Length::from_centimeters(input).as_meters()),
UnitLen::Cm => Ok(input),
UnitLen::Yards => Ok(measurements::Length::from_centimeters(input).as_yards()),
UnitLen::Unknown => unreachable!(),
}
}
/// Yards conversion factor for current files units.
pub async fn from_yd(exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
let input = args.get_number_typed(&RuntimeType::known_length(UnitLen::Yards), exec_state)?;
let result = inner_from_yd(input, exec_state)?;
Ok(args.make_user_val_from_f64_with_type(TyF64::new(
result,
exec_state.current_default_units().expect_default_length(),
)))
}
/// Converts a number from yards to the current default unit.
///
/// *DEPRECATED* prefer using explicit numeric suffixes (e.g., `42yd`) or the `to...` conversion functions.
///
/// No matter what units the current file uses, this function will always return a number equivalent
/// to the input in yards.
///
/// For example, if the current file uses inches, `fromYd(1)` will return `36`.
/// If the current file uses millimeters, `fromYd(1)` will return `914.4`.
/// If the current file uses yards, `fromYd(1)` will return `1`.
///
/// **Caution**: This function is only intended to be used when you absolutely MUST
/// have different units in your code than the file settings. Otherwise, it is
/// a bad pattern to use this function.
///
/// We merely provide these functions for convenience and readability, as
/// `fromYd(10)` is more readable that your intent is "I want 10 yards" than
/// `10 * 914.4`, if the file settings are in millimeters.
///
/// ```no_run
/// totalWidth = fromYd(10)
/// ```
#[stdlib {
name = "fromYd",
tags = ["units"],
deprecated = true,
}]
fn inner_from_yd(input: f64, exec_state: &ExecState) -> Result<f64, KclError> {
match exec_state.length_unit() {
UnitLen::Mm => Ok(measurements::Length::from_yards(input).as_millimeters()),
UnitLen::Inches => Ok(measurements::Length::from_yards(input).as_inches()),
UnitLen::Feet => Ok(measurements::Length::from_yards(input).as_feet()),
UnitLen::M => Ok(measurements::Length::from_yards(input).as_meters()),
UnitLen::Cm => Ok(measurements::Length::from_yards(input).as_centimeters()),
UnitLen::Yards => Ok(input),
UnitLen::Unknown => unreachable!(),
}
}

View File

@ -6,7 +6,7 @@ use super::args::TyF64;
use crate::execution::types::{NumericType, UnitLen};
pub(crate) fn untype_point(p: [TyF64; 2]) -> ([f64; 2], NumericType) {
let (x, y, ty) = NumericType::combine_eq(p[0].clone(), p[1].clone());
let (x, y, ty) = NumericType::combine_eq_coerce(p[0].clone(), p[1].clone());
([x, y], ty)
}