From 438928ffc305f869134222efbee7e3842a521653 Mon Sep 17 00:00:00 2001 From: Kurt Hutten Irev-Dev Date: Sat, 21 Sep 2024 07:47:47 +1000 Subject: [PATCH] rust review --- src/clientSideScene/ClientSideSceneComp.tsx | 22 ++++++-- src/clientSideScene/sceneEntities.ts | 8 --- src/clientSideScene/sceneInfra.ts | 56 +++++++++++---------- src/wasm-lib/kcl/src/std/shapes.rs | 13 ++--- 4 files changed, 50 insertions(+), 49 deletions(-) diff --git a/src/clientSideScene/ClientSideSceneComp.tsx b/src/clientSideScene/ClientSideSceneComp.tsx index 6f3090d2d6..0832da6da2 100644 --- a/src/clientSideScene/ClientSideSceneComp.tsx +++ b/src/clientSideScene/ClientSideSceneComp.tsx @@ -96,15 +96,29 @@ export const ClientSideScene = ({ canvas.appendChild(sceneInfra.renderer.domElement) canvas.appendChild(sceneInfra.labelRenderer.domElement) sceneInfra.animate() - canvas.addEventListener('mousemove', sceneInfra.onMouseMove, false) + canvas.addEventListener( + 'mousemove', + toSync(sceneInfra.onMouseMove, reportRejection), + false + ) canvas.addEventListener('mousedown', sceneInfra.onMouseDown, false) - canvas.addEventListener('mouseup', sceneInfra.onMouseUp, false) + canvas.addEventListener( + 'mouseup', + toSync(sceneInfra.onMouseUp, reportRejection), + false + ) sceneInfra.setSend(send) engineCommandManager.modelingSend = send return () => { - canvas?.removeEventListener('mousemove', sceneInfra.onMouseMove) + canvas?.removeEventListener( + 'mousemove', + toSync(sceneInfra.onMouseMove, reportRejection) + ) canvas?.removeEventListener('mousedown', sceneInfra.onMouseDown) - canvas?.removeEventListener('mouseup', sceneInfra.onMouseUp) + canvas?.removeEventListener( + 'mouseup', + toSync(sceneInfra.onMouseUp, reportRejection) + ) } }, []) diff --git a/src/clientSideScene/sceneEntities.ts b/src/clientSideScene/sceneEntities.ts index e625b89cbe..d9427e5360 100644 --- a/src/clientSideScene/sceneEntities.ts +++ b/src/clientSideScene/sceneEntities.ts @@ -336,7 +336,6 @@ export class SceneEntities { ) } sceneInfra.setCallbacks({ - // eslint-disable-next-line @typescript-eslint/no-misused-promises onClick: async (args) => { if (!args) return if (args.mouseEvent.which !== 1) return @@ -643,7 +642,6 @@ export class SceneEntities { draftExpressionsIndices, }) sceneInfra.setCallbacks({ - // eslint-disable-next-line @typescript-eslint/no-misused-promises onClick: async (args) => { if (!args) return if (args.mouseEvent.which !== 1) return @@ -784,7 +782,6 @@ export class SceneEntities { }) sceneInfra.setCallbacks({ - // eslint-disable-next-line @typescript-eslint/no-misused-promises onMove: async (args) => { // Update the width and height of the draft rectangle const pathToNodeTwo = structuredClone(sketchPathToNode) @@ -832,7 +829,6 @@ export class SceneEntities { this.updateSegment(seg, index, 0, _ast, orthoFactor, sketchGroup) ) }, - // eslint-disable-next-line @typescript-eslint/no-misused-promises onClick: async (args) => { // Commit the rectangle to the full AST/code and return to sketch.idle const cornerPoint = args.intersectionPoint?.twoD @@ -945,7 +941,6 @@ export class SceneEntities { }) sceneInfra.setCallbacks({ - // eslint-disable-next-line @typescript-eslint/no-misused-promises onMove: async (args) => { const pathToNodeTwo = structuredClone(sketchPathToNode) pathToNodeTwo[1][0] = 0 @@ -1012,7 +1007,6 @@ export class SceneEntities { this.updateSegment(seg, index, 0, _ast, orthoFactor, sketchGroup) ) }, - // eslint-disable-next-line @typescript-eslint/no-misused-promises onClick: async (args) => { // Commit the rectangle to the full AST/code and return to sketch.idle const cornerPoint = args.intersectionPoint?.twoD @@ -1076,7 +1070,6 @@ export class SceneEntities { }) => { let addingNewSegmentStatus: 'nothing' | 'pending' | 'added' = 'nothing' sceneInfra.setCallbacks({ - // eslint-disable-next-line @typescript-eslint/no-misused-promises onDragEnd: async () => { if (addingNewSegmentStatus !== 'nothing') { await this.tearDownSketch({ removeAxis: false }) @@ -1097,7 +1090,6 @@ export class SceneEntities { }) } }, - // eslint-disable-next-line @typescript-eslint/no-misused-promises onDrag: async ({ selected, intersectionPoint, diff --git a/src/clientSideScene/sceneInfra.ts b/src/clientSideScene/sceneInfra.ts index dc4de65000..3b463cca12 100644 --- a/src/clientSideScene/sceneInfra.ts +++ b/src/clientSideScene/sceneInfra.ts @@ -92,6 +92,8 @@ interface OnMoveCallbackArgs { // This singleton class is responsible for all of the under the hood setup for the client side scene. // That is the cameras and switching between them, raycasters for click mouse events and their abstractions (onClick etc), setting up controls. // Anything that added the the scene for the user to interact with is probably in SceneEntities.ts + +type Voidish = void | Promise export class SceneInfra { static instance: SceneInfra scene: Scene @@ -107,21 +109,21 @@ export class SceneInfra { _theme: Themes = Themes.System extraSegmentTexture: Texture lastMouseState: MouseState = { type: 'idle' } - onDragStartCallback: (arg: OnDragCallbackArgs) => void = () => {} - onDragEndCallback: (arg: OnDragCallbackArgs) => void = () => {} - onDragCallback: (arg: OnDragCallbackArgs) => void = () => {} - onMoveCallback: (arg: OnMoveCallbackArgs) => void = () => {} - onClickCallback: (arg: OnClickCallbackArgs) => void = () => {} - onMouseEnter: (arg: OnMouseEnterLeaveArgs) => void = () => {} - onMouseLeave: (arg: OnMouseEnterLeaveArgs) => void = () => {} + onDragStartCallback: (arg: OnDragCallbackArgs) => Voidish = () => {} + onDragEndCallback: (arg: OnDragCallbackArgs) => Voidish = () => {} + onDragCallback: (arg: OnDragCallbackArgs) => Voidish = () => {} + onMoveCallback: (arg: OnMoveCallbackArgs) => Voidish = () => {} + onClickCallback: (arg: OnClickCallbackArgs) => Voidish = () => {} + onMouseEnter: (arg: OnMouseEnterLeaveArgs) => Voidish = () => {} + onMouseLeave: (arg: OnMouseEnterLeaveArgs) => Voidish = () => {} setCallbacks = (callbacks: { - onDragStart?: (arg: OnDragCallbackArgs) => void - onDragEnd?: (arg: OnDragCallbackArgs) => void - onDrag?: (arg: OnDragCallbackArgs) => void - onMove?: (arg: OnMoveCallbackArgs) => void - onClick?: (arg: OnClickCallbackArgs) => void - onMouseEnter?: (arg: OnMouseEnterLeaveArgs) => void - onMouseLeave?: (arg: OnMouseEnterLeaveArgs) => void + onDragStart?: (arg: OnDragCallbackArgs) => Voidish + onDragEnd?: (arg: OnDragCallbackArgs) => Voidish + onDrag?: (arg: OnDragCallbackArgs) => Voidish + onMove?: (arg: OnMoveCallbackArgs) => Voidish + onClick?: (arg: OnClickCallbackArgs) => Voidish + onMouseEnter?: (arg: OnMouseEnterLeaveArgs) => Voidish + onMouseLeave?: (arg: OnMouseEnterLeaveArgs) => Voidish }) => { this.onDragStartCallback = callbacks.onDragStart || this.onDragStartCallback this.onDragEndCallback = callbacks.onDragEnd || this.onDragEndCallback @@ -389,7 +391,7 @@ export class SceneInfra { intersection: planeIntersects[0], } } - onMouseMove = (mouseEvent: MouseEvent) => { + onMouseMove = async (mouseEvent: MouseEvent) => { this.currentMouseVector.x = (mouseEvent.clientX / window.innerWidth) * 2 - 1 this.currentMouseVector.y = -(mouseEvent.clientY / window.innerHeight) * 2 + 1 @@ -414,7 +416,7 @@ export class SceneInfra { planeIntersectPoint.twoD && planeIntersectPoint.threeD ) { - this.onDragCallback({ + await this.onDragCallback({ mouseEvent, intersectionPoint: { twoD: planeIntersectPoint.twoD, @@ -433,7 +435,7 @@ export class SceneInfra { planeIntersectPoint.twoD && planeIntersectPoint.threeD ) { - this.onMoveCallback({ + await this.onMoveCallback({ mouseEvent, intersectionPoint: { twoD: planeIntersectPoint.twoD, @@ -448,12 +450,12 @@ export class SceneInfra { if (this.hoveredObject !== firstIntersectObject) { const hoveredObj = this.hoveredObject this.hoveredObject = null - this.onMouseLeave({ + await this.onMouseLeave({ selected: hoveredObj, mouseEvent: mouseEvent, }) this.hoveredObject = firstIntersectObject - this.onMouseEnter({ + await this.onMouseEnter({ selected: this.hoveredObject, dragSelected: this.selected?.object, mouseEvent: mouseEvent, @@ -468,7 +470,7 @@ export class SceneInfra { if (this.hoveredObject) { const hoveredObj = this.hoveredObject this.hoveredObject = null - this.onMouseLeave({ + await this.onMouseLeave({ selected: hoveredObj, dragSelected: this.selected?.object, mouseEvent: mouseEvent, @@ -555,7 +557,7 @@ export class SceneInfra { } } - onMouseUp = (mouseEvent: MouseEvent) => { + onMouseUp = async (mouseEvent: MouseEvent) => { this.currentMouseVector.x = (mouseEvent.clientX / window.innerWidth) * 2 - 1 this.currentMouseVector.y = -(mouseEvent.clientY / window.innerHeight) * 2 + 1 @@ -565,7 +567,7 @@ export class SceneInfra { if (this.selected) { if (this.selected.hasBeenDragged) { // TODO do the types properly here - this.onDragEndCallback({ + await this.onDragEndCallback({ intersectionPoint: { twoD: planeIntersectPoint?.twoD as any, threeD: planeIntersectPoint?.threeD as any, @@ -586,7 +588,7 @@ export class SceneInfra { } } else if (planeIntersectPoint?.twoD && planeIntersectPoint?.threeD) { // fire onClick event as there was no drags - this.onClickCallback({ + await this.onClickCallback({ mouseEvent, intersectionPoint: { twoD: planeIntersectPoint.twoD, @@ -596,17 +598,17 @@ export class SceneInfra { selected: this.selected.object, }) } else if (planeIntersectPoint) { - this.onClickCallback({ + await this.onClickCallback({ mouseEvent, intersects, }) } else { - this.onClickCallback({ mouseEvent, intersects }) + await this.onClickCallback({ mouseEvent, intersects }) } // Clear the selected state whether it was dragged or not this.selected = null } else if (planeIntersectPoint?.twoD && planeIntersectPoint?.threeD) { - this.onClickCallback({ + await this.onClickCallback({ mouseEvent, intersectionPoint: { twoD: planeIntersectPoint.twoD, @@ -615,7 +617,7 @@ export class SceneInfra { intersects, }) } else { - this.onClickCallback({ mouseEvent, intersects }) + await this.onClickCallback({ mouseEvent, intersects }) } } updateOtherSelectionColors = (otherSelections: Axis[]) => { diff --git a/src/wasm-lib/kcl/src/std/shapes.rs b/src/wasm-lib/kcl/src/std/shapes.rs index a54cd0319f..50d0233a95 100644 --- a/src/wasm-lib/kcl/src/std/shapes.rs +++ b/src/wasm-lib/kcl/src/std/shapes.rs @@ -14,7 +14,7 @@ use serde::{Deserialize, Serialize}; use crate::{ ast::types::TagDeclarator, - errors::{KclError, KclErrorDetails}, + errors::KclError, executor::{BasePath, ExecState, GeoMeta, KclValue, Path, SketchGroup, SketchSurface}, std::Args, }; @@ -93,15 +93,8 @@ async fn inner_circle( ) .await?; - let angle_start = Angle::from_degrees(0.0); - let angle_end = Angle::from_degrees(360.0); - - if angle_start == angle_end { - return Err(KclError::Type(KclErrorDetails { - message: "Arc start and end angles must be different".to_string(), - source_ranges: vec![args.source_range], - })); - } + let angle_start = Angle::zero(); + let angle_end = Angle::turn(); let id = uuid::Uuid::new_v4();