Skip to content

Commit

Permalink
rust review
Browse files Browse the repository at this point in the history
  • Loading branch information
Irev-Dev committed Sep 20, 2024
1 parent e281b22 commit 438928f
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 49 deletions.
22 changes: 18 additions & 4 deletions src/clientSideScene/ClientSideSceneComp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
}
}, [])

Expand Down
8 changes: 0 additions & 8 deletions src/clientSideScene/sceneEntities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 })
Expand All @@ -1097,7 +1090,6 @@ export class SceneEntities {
})
}
},
// eslint-disable-next-line @typescript-eslint/no-misused-promises
onDrag: async ({
selected,
intersectionPoint,
Expand Down
56 changes: 29 additions & 27 deletions src/clientSideScene/sceneInfra.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void>
export class SceneInfra {
static instance: SceneInfra
scene: Scene
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -414,7 +416,7 @@ export class SceneInfra {
planeIntersectPoint.twoD &&
planeIntersectPoint.threeD
) {
this.onDragCallback({
await this.onDragCallback({
mouseEvent,
intersectionPoint: {
twoD: planeIntersectPoint.twoD,
Expand All @@ -433,7 +435,7 @@ export class SceneInfra {
planeIntersectPoint.twoD &&
planeIntersectPoint.threeD
) {
this.onMoveCallback({
await this.onMoveCallback({
mouseEvent,
intersectionPoint: {
twoD: planeIntersectPoint.twoD,
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -615,7 +617,7 @@ export class SceneInfra {
intersects,
})
} else {
this.onClickCallback({ mouseEvent, intersects })
await this.onClickCallback({ mouseEvent, intersects })
}
}
updateOtherSelectionColors = (otherSelections: Axis[]) => {
Expand Down
13 changes: 3 additions & 10 deletions src/wasm-lib/kcl/src/std/shapes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -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();

Expand Down

0 comments on commit 438928f

Please sign in to comment.