Compare commits
2 Commits
main
...
achalmers/
Author | SHA1 | Date | |
---|---|---|---|
3156653287 | |||
89d54d24d6 |
45
docs/kcl-std/functions/std-planes-xAxis.md
Normal file
45
docs/kcl-std/functions/std-planes-xAxis.md
Normal file
File diff suppressed because one or more lines are too long
45
docs/kcl-std/functions/std-planes-yAxis.md
Normal file
45
docs/kcl-std/functions/std-planes-yAxis.md
Normal file
File diff suppressed because one or more lines are too long
@ -46,6 +46,9 @@ layout: manual
|
||||
* [`sin`](/docs/kcl-std/functions/std-math-sin)
|
||||
* [`sqrt`](/docs/kcl-std/functions/std-math-sqrt)
|
||||
* [`tan`](/docs/kcl-std/functions/std-math-tan)
|
||||
* [**std::planes**](/docs/kcl-std/modules/std-planes)
|
||||
* [`planes::xAxis`](/docs/kcl-std/functions/std-planes-xAxis)
|
||||
* [`planes::yAxis`](/docs/kcl-std/functions/std-planes-yAxis)
|
||||
* [**std::sketch**](/docs/kcl-std/modules/std-sketch)
|
||||
* [`angledLine`](/docs/kcl-std/functions/std-sketch-angledLine)
|
||||
* [`angledLineThatIntersects`](/docs/kcl-std/functions/std-sketch-angledLineThatIntersects)
|
||||
|
17
docs/kcl-std/modules/std-planes.md
Normal file
17
docs/kcl-std/modules/std-planes.md
Normal file
@ -0,0 +1,17 @@
|
||||
---
|
||||
title: "planes"
|
||||
subtitle: "Module in std"
|
||||
excerpt: ""
|
||||
layout: manual
|
||||
---
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
## Functions and constants
|
||||
|
||||
* [`planes::xAxis`](/docs/kcl-std/functions/std-planes-xAxis)
|
||||
* [`planes::yAxis`](/docs/kcl-std/functions/std-planes-yAxis)
|
||||
|
@ -18,6 +18,7 @@ You might also want the [KCL language reference](/docs/kcl-lang) or the [KCL gui
|
||||
* [`appearance::appearance`](/docs/kcl-std/modules/std-appearance)
|
||||
* [`array`](/docs/kcl-std/modules/std-array)
|
||||
* [`math`](/docs/kcl-std/modules/std-math)
|
||||
* [`planes::planes`](/docs/kcl-std/modules/std-planes)
|
||||
* [`sketch`](/docs/kcl-std/modules/std-sketch)
|
||||
* [`solid`](/docs/kcl-std/modules/std-solid)
|
||||
* [`sweep::sweep`](/docs/kcl-std/modules/std-sweep)
|
||||
|
@ -92,11 +92,14 @@ pub const TEST_NAMES: &[&str] = &[
|
||||
"std-math-sin-0",
|
||||
"std-math-sqrt-0",
|
||||
"std-math-tan-0",
|
||||
"std-math-crossProduct-0",
|
||||
"std-offsetPlane-0",
|
||||
"std-offsetPlane-1",
|
||||
"std-offsetPlane-2",
|
||||
"std-offsetPlane-3",
|
||||
"std-offsetPlane-4",
|
||||
"std-planes-xAxis-0",
|
||||
"std-planes-yAxis-0",
|
||||
"std-sketch-planeOf-0",
|
||||
"std-sketch-circle-0",
|
||||
"std-sketch-circle-1",
|
||||
|
@ -92,6 +92,7 @@ pub(crate) fn read_std(mod_name: &str) -> Option<&'static str> {
|
||||
"math" => Some(include_str!("../std/math.kcl")),
|
||||
"sketch" => Some(include_str!("../std/sketch.kcl")),
|
||||
"turns" => Some(include_str!("../std/turns.kcl")),
|
||||
"planes" => Some(include_str!("../std/planes.kcl")),
|
||||
"types" => Some(include_str!("../std/types.kcl")),
|
||||
"solid" => Some(include_str!("../std/solid.kcl")),
|
||||
"units" => Some(include_str!("../std/units.kcl")),
|
||||
|
@ -424,6 +424,14 @@ pub(crate) fn std_fn(path: &str, fn_name: &str) -> (crate::std::StdFn, StdFnProp
|
||||
|e, a| Box::pin(crate::std::appearance::hex_string(e, a)),
|
||||
StdFnProps::default("std::appearance::hexString"),
|
||||
),
|
||||
("planes", "xAxis") => (
|
||||
|e, a| Box::pin(crate::std::planes::x_axis(e, a)),
|
||||
StdFnProps::default("std::planes::xAxis"),
|
||||
),
|
||||
("planes", "yAxis") => (
|
||||
|e, a| Box::pin(crate::std::planes::y_axis(e, a)),
|
||||
StdFnProps::default("std::planes::yAxis"),
|
||||
),
|
||||
(module, fn_name) => {
|
||||
panic!("No implementation found for {module}::{fn_name}, please add it to this big match statement")
|
||||
}
|
||||
|
@ -14,6 +14,30 @@ use crate::{
|
||||
std::Args,
|
||||
};
|
||||
|
||||
/// Get the axes of a plane
|
||||
pub async fn x_axis(exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
|
||||
let plane: Plane = args.get_unlabeled_kw_arg("plane", &RuntimeType::plane(), exec_state)?;
|
||||
let plane_meta = plane.meta.clone();
|
||||
let axis = plane.info.x_axis;
|
||||
Ok(KclValue::from_point3d(
|
||||
[axis.x, axis.y, axis.z],
|
||||
axis.units.into(),
|
||||
plane_meta.clone(),
|
||||
))
|
||||
}
|
||||
|
||||
/// Get the axes of a plane
|
||||
pub async fn y_axis(exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
|
||||
let plane: Plane = args.get_unlabeled_kw_arg("plane", &RuntimeType::plane(), exec_state)?;
|
||||
let plane_meta = plane.meta.clone();
|
||||
let axis = plane.info.y_axis;
|
||||
Ok(KclValue::from_point3d(
|
||||
[axis.x, axis.y, axis.z],
|
||||
axis.units.into(),
|
||||
plane_meta.clone(),
|
||||
))
|
||||
}
|
||||
|
||||
/// Find the plane of a given face.
|
||||
pub async fn plane_of(exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
|
||||
let solid = args.get_unlabeled_kw_arg("solid", &RuntimeType::solid(), exec_state)?;
|
||||
|
@ -475,3 +475,21 @@ export fn legAngY(
|
||||
/// The length of one of the triangle's legs (i.e. non-hypotenuse side).
|
||||
leg: number(Length),
|
||||
): number(deg) {}
|
||||
|
||||
/// Compute the cross product of two vectors.
|
||||
///
|
||||
/// ```kcl,no_run
|
||||
/// p = XY
|
||||
/// cross = crossProduct([planes::xAxis(p), planes::yAxis(p)])
|
||||
/// ```
|
||||
export fn crossProduct(
|
||||
/// Returns the cross product of these two vectors.
|
||||
@vectors: [Point3d; 2],
|
||||
): Point3d {
|
||||
a = vectors[0]
|
||||
b = vectors[1]
|
||||
x = a[1] * b[2] - (a[2] * b[1])
|
||||
y = a[2] * b[0] - (a[0] * b[2])
|
||||
z = a[0] * b[1] - (a[1] * b[0])
|
||||
return [x,y,z]
|
||||
}
|
||||
|
38
rust/kcl-lib/std/planes.kcl
Normal file
38
rust/kcl-lib/std/planes.kcl
Normal file
@ -0,0 +1,38 @@
|
||||
/// Find X axis of a plane.
|
||||
///```kcl
|
||||
/// mySolid = startSketchOn(XZ)
|
||||
/// |> polygon(numSides = 3, radius = 1, center = [3, 2])
|
||||
/// |> extrude(length = 5)
|
||||
///
|
||||
/// target = planeOf(mySolid, face = END)
|
||||
///
|
||||
/// xTarget = planes::xAxis(target)
|
||||
/// assert(xTarget[0], isEqualTo = 1)
|
||||
/// assert(xTarget[1], isEqualTo = 0)
|
||||
/// assert(xTarget[2], isEqualTo = 0)
|
||||
/// ```
|
||||
@(impl = std_rust)
|
||||
export fn xAxis(
|
||||
/// The solid whose face is being queried.
|
||||
@plane: Plane,
|
||||
): Point3d {}
|
||||
|
||||
/// Find Y axis of a plane.
|
||||
///```kcl
|
||||
/// mySolid = startSketchOn(XZ)
|
||||
/// |> polygon(numSides = 3, radius = 1, center = [3, 2])
|
||||
/// |> extrude(length = 5)
|
||||
///
|
||||
/// target = planeOf(mySolid, face = END)
|
||||
///
|
||||
/// yTarget = planes::yAxis(target)
|
||||
/// assert(yTarget[0], isEqualTo = 0)
|
||||
/// assert(yTarget[1], isEqualTo = 0)
|
||||
/// assert(yTarget[2], isEqualTo = 1)
|
||||
/// ```
|
||||
@(impl = std_rust)
|
||||
export fn yAxis(
|
||||
/// The solid whose face is being queried.
|
||||
@plane: Plane,
|
||||
): Point3d {}
|
||||
|
@ -23,6 +23,7 @@ export import * from "std::transform"
|
||||
export import "std::turns"
|
||||
export import "std::sweep"
|
||||
export import "std::appearance"
|
||||
export import "std::planes"
|
||||
|
||||
/// An abstract 3d plane aligned with the X and Y axes. Its normal is the positive Z axis.
|
||||
export XY = {
|
||||
|
Binary file not shown.
After Width: | Height: | Size: 60 KiB |
Binary file not shown.
After Width: | Height: | Size: 60 KiB |
Reference in New Issue
Block a user