Skip to content

Commit

Permalink
Fix up tests
Browse files Browse the repository at this point in the history
  • Loading branch information
adamchalmers committed Sep 18, 2024
1 parent 75622e8 commit d00c823
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 54 deletions.
5 changes: 3 additions & 2 deletions src/wasm-lib/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/wasm-lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ anyhow = "1"
hyper = { version = "0.14.29", features = ["server", "http1"] }
image = { version = "0.25.1", default-features = false, features = ["png"] }
kittycad = { workspace = true, default-features = true }
kittycad-modeling-cmds = { workspace = true }
pretty_assertions = "1.4.1"
reqwest = { version = "0.11.26", default-features = false }
tokio = { version = "1.40.0", features = ["rt-multi-thread", "macros", "time"] }
Expand Down Expand Up @@ -72,7 +73,7 @@ members = [
http = "0.2.12"
kittycad = { version = "0.3.20", default-features = false, features = ["js", "requests"] }
kittycad-modeling-session = "0.1.4"
kittycad-modeling-cmds = { version = "0.2.58", features = ["websocket"] }
kittycad-modeling-cmds = { version = "0.2.59", features = ["websocket"] }

[[test]]
name = "executor"
Expand Down
77 changes: 41 additions & 36 deletions src/wasm-lib/kcl/src/std/sketch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,11 @@ async fn inner_line_to(
path: sketch_group.id.into(),
segment: PathSegment::Line {
end: KPoint3d {
x: LengthUnit(to[0]),
y: LengthUnit(to[1]),
z: LengthUnit(0.0),
},
x: to[0],
y: to[1],
z: 0.0,
}
.map(LengthUnit),
relative: false,
},
}),
Expand Down Expand Up @@ -308,10 +309,11 @@ async fn inner_line(
path: sketch_group.id.into(),
segment: PathSegment::Line {
end: KPoint3d {
x: LengthUnit(delta[0]),
y: LengthUnit(delta[1]),
z: LengthUnit(0.0),
},
x: delta[0],
y: delta[1],
z: 0.0,
}
.map(LengthUnit),
relative: true,
},
}),
Expand Down Expand Up @@ -495,10 +497,11 @@ async fn inner_angled_line(
path: sketch_group.id.into(),
segment: PathSegment::Line {
end: KPoint3d {
x: LengthUnit(delta[0]),
y: LengthUnit(delta[1]),
z: LengthUnit(0.0),
},
x: delta[0],
y: delta[1],
z: 0.0,
}
.map(LengthUnit),
relative,
},
}),
Expand Down Expand Up @@ -1307,10 +1310,11 @@ pub(crate) async fn inner_start_profile_at(
ModelingCmd::from(mcmd::MovePathPen {
path: path_id.into(),
to: KPoint3d {
x: LengthUnit(to[0]),
y: LengthUnit(to[1]),
z: LengthUnit(0.0),
},
x: to[0],
y: to[1],
z: 0.0,
}
.map(LengthUnit),
}),
)
.await?;
Expand Down Expand Up @@ -1616,10 +1620,7 @@ pub(crate) async fn inner_arc(
segment: PathSegment::Arc {
start: angle_start,
end: angle_end,
center: KPoint2d {
x: LengthUnit(center.x),
y: LengthUnit(center.y),
},
center: KPoint2d::from(center).map(LengthUnit),
radius: LengthUnit(radius),
relative: false,
},
Expand Down Expand Up @@ -1788,10 +1789,11 @@ fn tan_arc_to(sketch_group: &SketchGroup, to: &[f64; 2]) -> ModelingCmd {
segment: PathSegment::TangentialArcTo {
angle_snap_increment: None,
to: KPoint3d {
x: LengthUnit(to[0]),
y: LengthUnit(to[1]),
z: LengthUnit(0.0),
},
x: to[0],
y: to[1],
z: 0.0,
}
.map(LengthUnit),
},
})
}
Expand Down Expand Up @@ -2030,20 +2032,23 @@ async fn inner_bezier_curve(
path: sketch_group.id.into(),
segment: PathSegment::Bezier {
control1: KPoint3d {
x: LengthUnit(data.control1[0]),
y: LengthUnit(data.control1[1]),
z: LengthUnit(0.0),
},
x: data.control1[0],
y: data.control1[1],
z: 0.0,
}
.map(LengthUnit),
control2: KPoint3d {
x: LengthUnit(data.control2[0]),
y: LengthUnit(data.control2[1]),
z: LengthUnit(0.0),
},
x: data.control2[0],
y: data.control2[1],
z: 0.0,
}
.map(LengthUnit),
end: KPoint3d {
x: LengthUnit(delta[0]),
y: LengthUnit(delta[1]),
z: LengthUnit(0.0),
},
x: delta[0],
y: delta[1],
z: 0.0,
}
.map(LengthUnit),
relative,
},
}),
Expand Down
10 changes: 5 additions & 5 deletions src/wasm-lib/kcl/src/std/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ mod tests {

assert_eq!(results, expected);

let result = get_y_component(Angle::ZERO, 1.0);
let result = get_y_component(Angle::zero(), 1.0);
assert_eq!(result.x as i32, 1);
assert_eq!(result.y as i32, 0);

Expand Down Expand Up @@ -334,7 +334,7 @@ mod tests {

assert_eq!(results, expected);

let result = get_x_component(Angle::ZERO, 1.0);
let result = get_x_component(Angle::zero(), 1.0);
assert!(result.x > 100000.0);
assert_eq!(result.y as i32, 1);

Expand All @@ -355,7 +355,7 @@ mod tests {
fn test_arc_center_and_end() {
let (center, end) = super::arc_center_and_end(
super::Point2d { x: 0.0, y: 0.0 },
Angle::ZERO,
Angle::zero(),
Angle::from_degrees(90.0),
1.0,
);
Expand All @@ -366,7 +366,7 @@ mod tests {

let (center, end) = super::arc_center_and_end(
super::Point2d { x: 0.0, y: 0.0 },
Angle::ZERO,
Angle::zero(),
Angle::from_degrees(180.0),
1.0,
);
Expand All @@ -377,7 +377,7 @@ mod tests {

let (center, end) = super::arc_center_and_end(
super::Point2d { x: 0.0, y: 0.0 },
Angle::ZERO,
Angle::zero(),
Angle::from_degrees(180.0),
10.0,
);
Expand Down
22 changes: 12 additions & 10 deletions src/wasm-lib/tests/modify/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ use kcl_lib::{
ast::{modify::modify_ast_for_sketch, types::Program},
executor::{ExecutorContext, KclValue, PlaneType, SketchGroup, SourceRange},
};
use kittycad::types::{ModelingCmd, Point3D};
use kittycad_modeling_cmds::shared::Point3d;
use kittycad_modeling_cmds::ModelingCmd;
use kittycad_modeling_cmds::{each_cmd as mcmd, length_unit::LengthUnit};
use pretty_assertions::assert_eq;

/// Setup the engine and parse code for an ast.
Expand Down Expand Up @@ -52,14 +54,14 @@ async fn setup(code: &str, name: &str) -> Result<(ExecutorContext, Program, uuid
.send_modeling_cmd(
plane_id,
SourceRange::default(),
ModelingCmd::MakePlane {
ModelingCmd::from(mcmd::MakePlane {
clobber: false,
origin: Point3D { x: 0.0, y: 0.0, z: 0.0 },
size: 60.0,
x_axis: Point3D { x: 1.0, y: 0.0, z: 0.0 },
y_axis: Point3D { x: 0.0, y: 1.0, z: 0.0 },
origin: Point3d::default(),
size: LengthUnit(60.0),
x_axis: Point3d { x: 1.0, y: 0.0, z: 0.0 },
y_axis: Point3d { x: 0.0, y: 1.0, z: 0.0 },
hide: Some(true),
},
}),
)
.await?;

Expand All @@ -70,13 +72,13 @@ async fn setup(code: &str, name: &str) -> Result<(ExecutorContext, Program, uuid
.send_modeling_cmd(
uuid::Uuid::new_v4(),
SourceRange::default(),
ModelingCmd::EnableSketchMode {
ModelingCmd::from(mcmd::EnableSketchMode {
animated: false,
ortho: true,
entity_id: plane_id,
planar_normal: Some(Point3D { x: 0.0, y: 0.0, z: 1.0 }),
planar_normal: Some(Point3d { x: 0.0, y: 0.0, z: 1.0 }),
adjust_camera: false,
},
}),
)
.await?;

Expand Down

0 comments on commit d00c823

Please sign in to comment.