Skip to content

Commit 714e1e7

Browse files
committed
updates
Signed-off-by: Jess Frazelle <github@jessfraz.com>
1 parent 1f9d19b commit 714e1e7

File tree

17 files changed

+210
-222
lines changed

17 files changed

+210
-222
lines changed

flake.nix

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@
2222
rustToolchain = super.rust-bin.stable.latest.default.override {
2323
extensions = ["rustfmt" "clippy" "rust-src"];
2424
};
25+
26+
# stand-alone nightly formatter so we get the fancy unstable flags
27+
nightlyRustfmt = super.rust-bin.selectLatestNightlyWith (toolchain:
28+
toolchain.default.override {
29+
extensions = ["rustfmt"]; # just the formatter
30+
});
2531
})
2632
];
2733
pkgs = import nixpkgs {
@@ -33,6 +39,8 @@
3339
nativeBuildInputs =
3440
(with pkgs; [
3541
rustToolchain
42+
nightlyRustfmt
43+
cargo-sort
3644
toml-cli
3745
openssl
3846
postgresql
@@ -41,7 +49,7 @@
4149
++ pkgs.lib.optionals pkgs.stdenv.isDarwin (with pkgs; [
4250
]);
4351

44-
RUSTFMT = "${pkgs.rust-bin.nightly.latest.rustfmt}/bin/rustfmt";
52+
RUSTFMT = "${pkgs.nightlyRustfmt}/bin/rustfmt";
4553
};
4654
}
4755
);

src/cmd_config.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
use crate::config::{ConfigOption, CONFIG_OPTIONS};
21
use anyhow::{bail, Result};
32
use clap::Parser;
43

4+
use crate::config::{ConfigOption, CONFIG_OPTIONS};
5+
56
// TODO: make this doc a function that parses from the config the options so it's not hardcoded
67
/// Manage configuration for `zoo`.
78
///
@@ -170,9 +171,7 @@ impl crate::cmd::Command for CmdConfigList {
170171
mod test {
171172
use pretty_assertions::assert_eq;
172173

173-
use crate::cmd::Command;
174-
use crate::config;
175-
use crate::config::Config;
174+
use crate::{cmd::Command, config, config::Config};
176175

177176
pub struct TestItem {
178177
name: String,

src/cmd_kcl.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
use std::{net::SocketAddr, str::FromStr};
22

3-
use crate::kcl_error_fmt;
43
use anyhow::Result;
54
use clap::Parser;
65
use kcmc::format::OutputFormat3d as OutputFormat;
76
use kittycad::types as kt;
87
use kittycad_modeling_cmds as kcmc;
98
use url::Url;
109

11-
use crate::iostreams::IoStreams;
10+
use crate::{iostreams::IoStreams, kcl_error_fmt};
1211

1312
/// Perform actions on `kcl` files.
1413
#[derive(Parser, Debug, Clone)]

src/cmd_ml/cmd_text_to_cad.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
use anyhow::Result;
22
use clap::Parser;
33
use kcl_lib::EngineManager;
4-
use kcmc::each_cmd as mcmd;
5-
use kcmc::format::InputFormat3d;
6-
use kcmc::ok_response::OkModelingCmdResponse;
7-
use kcmc::websocket::OkWebSocketResponseData;
8-
use kcmc::{ImageFormat, ModelingCmd};
4+
use kcmc::{
5+
each_cmd as mcmd, format::InputFormat3d, ok_response::OkModelingCmdResponse, websocket::OkWebSocketResponseData,
6+
ImageFormat, ModelingCmd,
7+
};
98
use kittycad_modeling_cmds::{self as kcmc, ImportFile};
109

1110
/// Perform Text-to-CAD commands.

src/context.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
use std::str::FromStr;
22

33
use anyhow::{anyhow, Result};
4-
use kcl_lib::native_engine::EngineConnection;
5-
use kcl_lib::EngineManager;
6-
use kcmc::each_cmd as mcmd;
7-
use kcmc::websocket::OkWebSocketResponseData;
4+
use kcl_lib::{native_engine::EngineConnection, EngineManager};
5+
use kcmc::{each_cmd as mcmd, websocket::OkWebSocketResponseData};
86
use kittycad::types::{ApiCallStatus, AsyncApiCallOutput, TextToCad, TextToCadCreateBody, TextToCadMultiFileIteration};
97
use kittycad_modeling_cmds::{self as kcmc, shared::FileExportFormat, websocket::ModelingSessionData, ModelingCmd};
108

src/iostreams.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
use std::io::IsTerminal;
2-
use std::{collections::HashMap, env, process::Command};
1+
use std::{collections::HashMap, env, io::IsTerminal, process::Command};
32

43
use anyhow::{anyhow, Result};
54
use terminal_size::{terminal_size, Height, Width};

src/update.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
#[cfg(target_family = "unix")]
22
use std::os::unix::fs::PermissionsExt;
3-
use std::{fs, io::IsTerminal, io::Write};
3+
use std::{
4+
fs,
5+
io::{IsTerminal, Write},
6+
};
47

58
use anyhow::{anyhow, Context, Result};
69
use serde::{Deserialize, Serialize};

tests/gear.kcl

Lines changed: 48 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,62 @@
1-
@settings(defaultLengthUnit = in)
21
// Spur Gear
32
// A rotating machine part having cut teeth or, in the case of a cogwheel, inserted teeth (called cogs), which mesh with another toothed part to transmit torque. Geared devices can change the speed, torque, and direction of a power source. The two elements that define a gear are its circular shape and the teeth that are integrated into its outer edge, which are designed to fit into the teeth of another gear.
43

4+
// Set units
5+
@settings(defaultLengthUnit = in)
56

6-
// Set Units
7-
8-
9-
// Define constants
7+
// Define parameters
108
nTeeth = 21
119
module = 0.5
1210
pitchDiameter = module * nTeeth
1311
pressureAngle = 20
1412
addendum = module
1513
deddendum = 1.25 * module
16-
baseDiameter = pitchDiameter * cos(toRadians(pressureAngle))
14+
baseDiameter = pitchDiameter * cos(units::toRadians(pressureAngle))
1715
tipDiameter = pitchDiameter + 2 * module
1816
gearHeight = 3
1917

2018
// Interpolate points along the involute curve
2119
cmo = 101
22-
rs = map([0..cmo], fn(i) {
23-
return baseDiameter / 2 + i / cmo * (tipDiameter - baseDiameter) / 2
24-
})
20+
rs = map(
21+
[0..cmo],
22+
f = fn(i) {
23+
return baseDiameter / 2 + i / cmo * (tipDiameter - baseDiameter) / 2
24+
},
25+
)
2526

2627
// Calculate operating pressure angle
27-
angles = map(rs, fn(r) {
28-
return toDegrees( acos(baseDiameter / 2 / r))
29-
})
28+
angles = map(
29+
rs,
30+
f = fn(r) {
31+
return units::toDegrees( acos(baseDiameter / 2 / r))
32+
},
33+
)
3034

3135
// Calculate the involute function
32-
invas = map(angles, fn(a) {
33-
return tan(toRadians(a)) - toRadians(a)
34-
})
36+
invas = map(
37+
angles,
38+
f = fn(a) {
39+
return tan(units::toRadians(a)) - units::toRadians(a)
40+
},
41+
)
3542

3643
// Map the involute curve
37-
xs = map([0..cmo], fn(i) {
38-
return rs[i] * cos(invas[i])
39-
})
40-
41-
ys = map([0..cmo], fn(i) {
42-
return rs[i] * sin(invas[i])
43-
})
44+
xs = map(
45+
[0..cmo],
46+
f = fn(i) {
47+
return rs[i] * cos(invas[i]: number(rad))
48+
},
49+
)
50+
51+
ys = map(
52+
[0..cmo],
53+
f = fn(i) {
54+
return rs[i] * sin(invas[i]: number(rad))
55+
},
56+
)
4457

4558
// Extrude the gear body
46-
body = startSketchOn('XY')
59+
body = startSketchOn(XY)
4760
|> circle(center = [0, 0], radius = baseDiameter / 2)
4861
|> extrude(length = gearHeight)
4962

@@ -56,21 +69,17 @@ fn leftInvolute(i, sg) {
5669
}
5770

5871
fn rightInvolute(i, sg) {
59-
x = rs[i] * cos(toRadians(-toothAngle + toDegrees(atan(ys[i] / xs[i]))))
60-
y = -rs[i] * sin(toRadians(-toothAngle + toDegrees(atan(ys[i] / xs[i]))))
72+
x = rs[i] * cos(units::toRadians(-toothAngle + units::toDegrees(atan(ys[i] / xs[i]))))
73+
y = -rs[i] * sin(units::toRadians(-toothAngle + units::toDegrees(atan(ys[i] / xs[i]))))
6174
return line(sg, endAbsolute = [x, y])
6275
}
6376

6477
// Draw gear teeth
65-
start = startSketchOn('XY')
66-
|> startProfileAt([xs[101], ys[101]], %)
67-
teeth = reduce([0..100], start, leftInvolute)
68-
|> arc({
69-
angleStart = 0,
70-
angleEnd = toothAngle,
71-
radius = baseDiameter / 2
72-
}, %)
73-
|> reduce([1..101], %, rightInvolute)
78+
start = startSketchOn(XY)
79+
|> startProfile(at = [xs[101], ys[101]])
80+
teeth = reduce([0..100], initial = start, f = leftInvolute)
81+
|> arc(angleStart = 0, angleEnd = toothAngle, radius = baseDiameter / 2)
82+
|> reduce([1..101], initial = %, f = rightInvolute)
7483
|> close()
7584
|> extrude(length = gearHeight)
7685
|> patternCircular3d(
@@ -89,23 +98,15 @@ holeRadius = 1
8998
startAngle = asin(keywayWidth / 2 / holeRadius)
9099

91100
// Sketch the keyway and center hole and extrude
92-
keyWay = startSketchOn(body, face = 'END')
93-
|> startProfileAt([
101+
keyWay = startSketchOn(body, face = END)
102+
|> startProfile(at = [
94103
holeRadius * cos(startAngle),
95104
holeRadius * sin(startAngle)
96-
], %)
105+
])
97106
|> xLine(length = keywayDepth)
98107
|> yLine(length = -keywayWidth)
99108
|> xLine(length = -keywayDepth)
100-
|> arc({
101-
angleEnd = 180,
102-
angleStart = -1 * 180 / PI * startAngle + 360,
103-
radius = holeRadius
104-
}, %)
105-
|> arc({
106-
angleEnd = 180 / PI * startAngle,
107-
angleStart = 180,
108-
radius = holeRadius
109-
}, %)
109+
|> arc(angleStart = -1 * units::toDegrees(startAngle) + 360, angleEnd = 180, radius = holeRadius)
110+
|> arc(angleStart = 180, angleEnd = units::toDegrees(startAngle), radius = holeRadius)
110111
|> close()
111112
|> extrude(length = -gearHeight)

0 commit comments

Comments
 (0)