Compare commits
2 Commits
kcl_prelud
...
angled-lin
Author | SHA1 | Date | |
---|---|---|---|
58b9382990 | |||
0947d970a6 |
BIN
src/wasm-lib/grackle/fixtures/tri_angledLineToX.png
Normal file
BIN
src/wasm-lib/grackle/fixtures/tri_angledLineToX.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 91 KiB |
BIN
src/wasm-lib/grackle/fixtures/tri_angledLineX.png
Normal file
BIN
src/wasm-lib/grackle/fixtures/tri_angledLineX.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 77 KiB |
BIN
src/wasm-lib/grackle/fixtures/zigzag_angledLine.png
Normal file
BIN
src/wasm-lib/grackle/fixtures/zigzag_angledLine.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 76 KiB |
@ -43,7 +43,12 @@ impl EpBinding {
|
|||||||
/// Look up the given property of this binding.
|
/// Look up the given property of this binding.
|
||||||
pub fn property_of(&self, property: LiteralIdentifier) -> Result<&Self, CompileError> {
|
pub fn property_of(&self, property: LiteralIdentifier) -> Result<&Self, CompileError> {
|
||||||
match property {
|
match property {
|
||||||
LiteralIdentifier::Identifier(_) => todo!("Support identifier properties"),
|
LiteralIdentifier::Identifier(ident) => {
|
||||||
|
let EpBinding::Map { length_at: _, properties } = self else {
|
||||||
|
return Err(CompileError::CannotIndex)
|
||||||
|
};
|
||||||
|
properties.get(&ident.name).ok_or(CompileError::CannotIndex)
|
||||||
|
}
|
||||||
LiteralIdentifier::Literal(litval) => match litval.value {
|
LiteralIdentifier::Literal(litval) => match litval.value {
|
||||||
// Arrays can be indexed by integers.
|
// Arrays can be indexed by integers.
|
||||||
LiteralValue::IInteger(i) => match self {
|
LiteralValue::IInteger(i) => match self {
|
||||||
|
@ -1144,10 +1144,6 @@ async fn stdlib_cube_xline_yline() {
|
|||||||
|> close(%)
|
|> close(%)
|
||||||
|> extrude(100.0, %)
|
|> extrude(100.0, %)
|
||||||
"#;
|
"#;
|
||||||
kcvm_dbg(
|
|
||||||
program,
|
|
||||||
"/home/lee/Code/Zoo/modeling-api/execution-plan-debugger/cube_xyline.json",
|
|
||||||
);
|
|
||||||
let (_plan, _scope, _last_address) = must_plan(program);
|
let (_plan, _scope, _last_address) = must_plan(program);
|
||||||
|
|
||||||
let ast = kcl_lib::parser::Parser::new(kcl_lib::token::lexer(program))
|
let ast = kcl_lib::parser::Parser::new(kcl_lib::token::lexer(program))
|
||||||
@ -1462,3 +1458,134 @@ async fn kcl_prelude() {
|
|||||||
use ept::ReadMemory;
|
use ept::ReadMemory;
|
||||||
assert_eq!(*mem.get(the_answer_to_the_universe_is).unwrap(), Primitive::from(42i64));
|
assert_eq!(*mem.get(the_answer_to_the_universe_is).unwrap(), Primitive::from(42i64));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn angled_line() {
|
||||||
|
let program = r#"
|
||||||
|
let zigzag = startSketchAt([0.0, 0.0], "test")
|
||||||
|
|> angledLine({ angle: 45.0, length: 100 }, %, "")
|
||||||
|
|> angledLine({ angle: 45.0 + 90.0, length: 100 }, %, "")
|
||||||
|
|> angledLine({ angle: 45.0, length: 100 }, %, "")
|
||||||
|
|> angledLine({ angle: 45.0 + 90.0, length: 100 }, %, "")
|
||||||
|
|> close(%)
|
||||||
|
|> extrude(100.0, %)
|
||||||
|
"#;
|
||||||
|
let ast = kcl_lib::parser::Parser::new(kcl_lib::token::lexer(program))
|
||||||
|
.ast()
|
||||||
|
.unwrap();
|
||||||
|
let mut client = Some(test_client().await);
|
||||||
|
let mem = match crate::execute(ast, &mut client).await {
|
||||||
|
Ok(mem) => mem,
|
||||||
|
Err(e) => panic!("{e}"),
|
||||||
|
};
|
||||||
|
use kittycad_modeling_cmds::{each_cmd, ok_response::OkModelingCmdResponse, ImageFormat};
|
||||||
|
let out = client
|
||||||
|
.unwrap()
|
||||||
|
.run_command(
|
||||||
|
uuid::Uuid::new_v4().into(),
|
||||||
|
kittycad_modeling_cmds::ModelingCmd::from(each_cmd::TakeSnapshot {
|
||||||
|
format: ImageFormat::Png,
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let out = match out {
|
||||||
|
OkModelingCmdResponse::TakeSnapshot(kittycad_modeling_cmds::output::TakeSnapshot { contents: b }) => b,
|
||||||
|
other => panic!("wrong output: {other:?}"),
|
||||||
|
};
|
||||||
|
|
||||||
|
use image::io::Reader as ImageReader;
|
||||||
|
let img = ImageReader::new(std::io::Cursor::new(out))
|
||||||
|
.with_guessed_format()
|
||||||
|
.unwrap()
|
||||||
|
.decode()
|
||||||
|
.unwrap();
|
||||||
|
twenty_twenty::assert_image("fixtures/zigzag_angledLine.png", &img, 0.9999);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn angled_line_to_x() {
|
||||||
|
let program = r#"
|
||||||
|
let zigzag = startSketchAt([0.0, 0.0], "test")
|
||||||
|
|> angledLineToX({ angle: toRadians(85.0), to: 300.0 }, %, "")
|
||||||
|
|> angledLineToX({ angle: toRadians(35.0), to: 550.0 }, %, "")
|
||||||
|
|> close(%)
|
||||||
|
|> extrude(100.0, %)
|
||||||
|
"#;
|
||||||
|
let ast = kcl_lib::parser::Parser::new(kcl_lib::token::lexer(program))
|
||||||
|
.ast()
|
||||||
|
.unwrap();
|
||||||
|
let mut client = Some(test_client().await);
|
||||||
|
let mem = match crate::execute(ast, &mut client).await {
|
||||||
|
Ok(mem) => mem,
|
||||||
|
Err(e) => panic!("{e}"),
|
||||||
|
};
|
||||||
|
use kittycad_modeling_cmds::{each_cmd, ok_response::OkModelingCmdResponse, ImageFormat};
|
||||||
|
let out = client
|
||||||
|
.unwrap()
|
||||||
|
.run_command(
|
||||||
|
uuid::Uuid::new_v4().into(),
|
||||||
|
kittycad_modeling_cmds::ModelingCmd::from(each_cmd::TakeSnapshot {
|
||||||
|
format: ImageFormat::Png,
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let out = match out {
|
||||||
|
OkModelingCmdResponse::TakeSnapshot(kittycad_modeling_cmds::output::TakeSnapshot { contents: b }) => b,
|
||||||
|
other => panic!("wrong output: {other:?}"),
|
||||||
|
};
|
||||||
|
|
||||||
|
use image::io::Reader as ImageReader;
|
||||||
|
let img = ImageReader::new(std::io::Cursor::new(out))
|
||||||
|
.with_guessed_format()
|
||||||
|
.unwrap()
|
||||||
|
.decode()
|
||||||
|
.unwrap();
|
||||||
|
twenty_twenty::assert_image("fixtures/tri_angledLineToX.png", &img, 0.9999);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn angled_line_x() {
|
||||||
|
let program = r#"
|
||||||
|
let zigzag = startSketchAt([0.0, 0.0], "test")
|
||||||
|
|> angledLineX({ angle: toRadians(85.0), to: 300.0 }, %, "")
|
||||||
|
|> angledLineX({ angle: toRadians(35.0), to: 550.0 }, %, "")
|
||||||
|
|> close(%)
|
||||||
|
|> extrude(100.0, %)
|
||||||
|
"#;
|
||||||
|
let ast = kcl_lib::parser::Parser::new(kcl_lib::token::lexer(program))
|
||||||
|
.ast()
|
||||||
|
.unwrap();
|
||||||
|
let mut client = Some(test_client().await);
|
||||||
|
let mem = match crate::execute(ast, &mut client).await {
|
||||||
|
Ok(mem) => mem,
|
||||||
|
Err(e) => panic!("{e}"),
|
||||||
|
};
|
||||||
|
use kittycad_modeling_cmds::{each_cmd, ok_response::OkModelingCmdResponse, ImageFormat};
|
||||||
|
let out = client
|
||||||
|
.unwrap()
|
||||||
|
.run_command(
|
||||||
|
uuid::Uuid::new_v4().into(),
|
||||||
|
kittycad_modeling_cmds::ModelingCmd::from(each_cmd::TakeSnapshot {
|
||||||
|
format: ImageFormat::Png,
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let out = match out {
|
||||||
|
OkModelingCmdResponse::TakeSnapshot(kittycad_modeling_cmds::output::TakeSnapshot { contents: b }) => b,
|
||||||
|
other => panic!("wrong output: {other:?}"),
|
||||||
|
};
|
||||||
|
|
||||||
|
use image::io::Reader as ImageReader;
|
||||||
|
let img = ImageReader::new(std::io::Cursor::new(out))
|
||||||
|
.with_guessed_format()
|
||||||
|
.unwrap()
|
||||||
|
.decode()
|
||||||
|
.unwrap();
|
||||||
|
twenty_twenty::assert_image("fixtures/tri_angledLineX.png", &img, 0.9999);
|
||||||
|
}
|
||||||
|
@ -958,7 +958,7 @@ impl TryFrom<Token> for Identifier {
|
|||||||
Err(KclError::Syntax(KclErrorDetails {
|
Err(KclError::Syntax(KclErrorDetails {
|
||||||
source_ranges: token.as_source_ranges(),
|
source_ranges: token.as_source_ranges(),
|
||||||
message: format!(
|
message: format!(
|
||||||
"Cannot assign a variable to a reserved keyword: {}",
|
"Word Cannot assign a variable to a reserved keyword: {}",
|
||||||
token.value.as_str()
|
token.value.as_str()
|
||||||
),
|
),
|
||||||
}))
|
}))
|
||||||
@ -1283,13 +1283,6 @@ fn optional_after_required(params: &[Parameter]) -> Result<(), KclError> {
|
|||||||
|
|
||||||
impl Identifier {
|
impl Identifier {
|
||||||
fn into_valid_binding_name(self) -> Result<Identifier, KclError> {
|
fn into_valid_binding_name(self) -> Result<Identifier, KclError> {
|
||||||
// Make sure they are not assigning a variable to a stdlib function.
|
|
||||||
if crate::std::name_in_stdlib(&self.name) {
|
|
||||||
return Err(KclError::Syntax(KclErrorDetails {
|
|
||||||
source_ranges: vec![SourceRange([self.start, self.end])],
|
|
||||||
message: format!("Cannot assign a variable to a reserved keyword: {}", self.name),
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
Ok(self)
|
Ok(self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,35 @@
|
|||||||
fn hey_from_one_of_the_devs_of_the_past_i_wish_you_a_great_day_and_maybe_gave_you_a_little_smile_as_youve_found_this = () => {
|
fn hey_from_one_of_the_devs_of_the_past_i_wish_you_a_great_day_and_maybe_gave_you_a_little_smile_as_youve_found_this = () => {
|
||||||
return 42
|
return 42
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let TAU = PI * 2.0
|
||||||
|
|
||||||
|
fn angledLine = (args, segment_group, tag?) => {
|
||||||
|
let x = cos(args.angle) * args.length
|
||||||
|
let y = sin(args.angle) * args.length
|
||||||
|
return line([x, y], segment_group, tag)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn angledLineTo_ = (args, axis) => {
|
||||||
|
let fn = { X: [cos, sin], Y: [sin, cos] }
|
||||||
|
let a = args.to
|
||||||
|
let length = args.to / fn[axis][0](args.angle)
|
||||||
|
let b = fn[axis][1](args.angle) * length
|
||||||
|
return [x, y]
|
||||||
|
}
|
||||||
|
|
||||||
|
fn angledLineToX = (args, segment_group, tag?) => {
|
||||||
|
return lineTo(angledLineTo_(args, "X"), segment_group, tag)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn angledLineX = (args, segment_group, tag?) => {
|
||||||
|
return line(angledLineTo_(args, "X"), segment_group, tag)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn angledLineToY = (args, segment_group, tag?) => {
|
||||||
|
return lineTo(angledLineTo_(args, "Y"), segment_group, tag)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn angledLineY = (args, segment_group, tag?) => {
|
||||||
|
return line(angledLineTo_(args, "Y"), segment_group, tag)
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user