-
Notifications
You must be signed in to change notification settings - Fork 88
Add majorDiameter and minorDiameter to ellipse fns #8057
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 10 commits
3731713
84f7a48
72c69ce
4b8f2ce
ca30487
868f2d5
d472d29
b9d4894
98bee68
c1064ff
46fcecf
684acef
d677325
2e9b33c
72c1f8f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -539,10 +539,40 @@ pub async fn ellipse(exec_state: &mut ExecState, args: Args) -> Result<KclValue, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
args.get_unlabeled_kw_arg("sketchOrSurface", &RuntimeType::sketch_or_surface(), exec_state)?; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
let center = args.get_kw_arg("center", &RuntimeType::point2d(), exec_state)?; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
let major_radius = args.get_kw_arg_opt("majorRadius", &RuntimeType::length(), exec_state)?; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
let major_diameter: Option<TyF64> = args.get_kw_arg_opt("majorDiameter", &RuntimeType::length(), exec_state)?; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
let major_axis = args.get_kw_arg_opt("majorAxis", &RuntimeType::point2d(), exec_state)?; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
let minor_radius = args.get_kw_arg("minorRadius", &RuntimeType::length(), exec_state)?; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
let minor_radius = args.get_kw_arg_opt("minorRadius", &RuntimeType::length(), exec_state)?; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
let minor_diameter: Option<TyF64> = args.get_kw_arg_opt("minorDiameter", &RuntimeType::length(), exec_state)?; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
let tag = args.get_kw_arg_opt("tag", &RuntimeType::tag_decl(), exec_state)?; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
let major_radius = match (major_radius, major_diameter) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
(Some(_), Some(_)) | (None, None) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return Err(KclError::new_type(KclErrorDetails::new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"Provide either `majorDiameter` or `majorRadius`, not both.".to_string(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
vec![args.source_range], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
))); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
(Some(major_radius), _) => Some(major_radius), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
(_, Some(major_diameter)) => Some(TyF64 { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
n: 0.5 * major_diameter.n, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ty: major_diameter.ty, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+537
to
+549
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Validation logic issue with optional parameters There's a validation error in the (Some(_), Some(_)) | (None, None) => {
return Err(KclError::new_type(KclErrorDetails::new(
"Provide either `majorDiameter` or `majorRadius`, not both.".to_string(),
vec![args.source_range],
)));
} However, according to the function signature, The validation should only reject cases where both diameter and radius are provided simultaneously, not when both are absent.
Suggested change
Spotted by Diamond |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
let minor_radius = match (minor_radius, minor_diameter) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
(Some(_), Some(_)) | (None, None) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return Err(KclError::new_type(KclErrorDetails::new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"Provide either `minorDiameter` or `minorRadius`, not both.".to_string(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
vec![args.source_range], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
))); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
(Some(minor_radius), _) => minor_radius, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
(_, Some(minor_diameter)) => TyF64 { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
n: 0.5 * minor_diameter.n, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ty: minor_diameter.ty, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
let sketch = inner_ellipse( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
sketch_or_surface, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
center, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Uh oh!
There was an error while loading. Please reload this page.