Skip to content

Commit

Permalink
Fix the circle
Browse files Browse the repository at this point in the history
Signed-off-by: Dimitris Zervas <[email protected]>
  • Loading branch information
dzervas committed Jun 14, 2024
1 parent 3eed197 commit 5684fcc
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 20 deletions.
6 changes: 3 additions & 3 deletions applications/web/src/components/Face.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@
function writeWireToShape(wire: {Circle: any; Segments: any}, shape: Path) {
if (wire.Circle) {
let circle = wire.Circle
let center = pointsById[circle.center]
let radius = circle.radius
let points = circleToPoints(new Vector2(center.x, center.y), radius)
let center = circle.center.data
let radius = circle.data
let points = circleToPoints(new Vector2(center[0], center[1]), radius)
shape.setFromPoints(points)
} else if (wire.Segments) {
let points = []
Expand Down
3 changes: 2 additions & 1 deletion applications/web/src/components/FeatureHistory.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import {isPointStep, isPlaneStep, isSolidStep, isSketchStep, isExtrusionStep} from "shared/stepTypeGuards"
import type {SetCameraFocus} from "shared/types"
// @ts-ignore
const log = (function () { const context = "[FeatureHistory.svelte]"; const color="pink"; return Function.prototype.bind.call(console.log, console, `%c${context}`, `font-weight:bold;color:${color};`)})() // prettier-ignore
const minHeight = 30
Expand Down Expand Up @@ -66,7 +67,7 @@
{:else if isExtrusionStep(step)}
<ExtrusionFeature name={step.name} index={featureIndex} hash={step.hash} data={step.data} />
{:else}
TODO: {step.name} {step.result}
<!-- TODO: {step.name} {step.result} -->
{/if}
</div>
{/each}
Expand Down
33 changes: 17 additions & 16 deletions applications/web/src/components/tools/NewCircle.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import {snapPoints, sketchTool, previewGeometry, currentlyMousedOver} from "shared/stores"
import {bench} from "shared/projectUtils"
import {Vector2, Vector3, type Vector2Like} from "three"
import type {PointLikeById, Point2D, ProjectToPlane, IDictionary, Point2WithID} from "shared/types"
import type {Point2D, ProjectToPlane, IDictionary, Point2WithID} from "shared/types"
import type { Point2 } from "cadmium"
// @ts-ignore
Expand All @@ -13,7 +13,7 @@
export let active: boolean
export let projectToPlane: ProjectToPlane
let centerPoint: Point2 | null = null
let centerPoint: Point2WithID | undefined = undefined
let stack: Point2WithID[] = []
$: if ($sketchTool !== "circle") clearStack()
Expand All @@ -25,14 +25,14 @@
}
function processPoint(point: Point2WithID) {
pushToStack(point)
centerPoint = point
if (stack.length < 2) return
if (stack.length === 0) {
centerPoint = point
pushToStack(point)
return
}
const circumference = popFromStack()
const center = popFromStack()
bench.sketchAddCircle(sketchId, center!.id!, circumference!.id!)
const radius = calcDeltas(centerPoint!, point)
bench.sketchAddCircle(sketchId, centerPoint!.id!, radius)
clearStack()
}
Expand Down Expand Up @@ -68,11 +68,6 @@
else if ($snapPoints.length > 0) $snapPoints = []
if (centerPoint) {
function calcDeltas(a: Vector2Like | Point2D | {x: number; y: number}, b: Vector2Like | undefined) {
const dx = a.x - b?.x!
const dy = a.y - b?.y!
return Math.hypot(dx, dy)
}
const radius = snappedTo ? calcDeltas(snappedTo!, centerPoint) : calcDeltas(projected, centerPoint)
previewGeometry.set([
Expand Down Expand Up @@ -102,14 +97,20 @@
}
}
function calcDeltas(a: Vector2Like | Point2D | {x: number; y: number}, b: Vector2Like | undefined) {
const dx = a.x - b?.x!
const dy = a.y - b?.y!
return Math.hypot(dx, dy)
}
function clearStack() {
centerPoint = null
centerPoint = undefined
previewGeometry.set([])
snapPoints.set([])
stack = []
}
function popFromStack(): PointLikeById | undefined {
function popFromStack(): Point2WithID | undefined {
return stack.pop()
}
</script>
Expand Down

0 comments on commit 5684fcc

Please sign in to comment.