Skip to content

Commit a064e75

Browse files
committed
fix: FreehandLines no longer have cracks
- These were caused by line segments becoming too short and the line fattening algorithm not working. - Also has the effect of smoothing the line somewhat.
1 parent abcb833 commit a064e75

File tree

6 files changed

+26
-16
lines changed

6 files changed

+26
-16
lines changed

src/Tools/CreateTools/CreateCircleTool.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class CreateCircleTool extends CreateGeomTool {
2929
*
3030
* @param xfo - The xfo param.
3131
*/
32-
createStart(xfo: Xfo): void {
32+
createStart(xfo: Xfo, event: ZeaPointerEvent): void {
3333
this.change = new CreateCircleChange(this.parentItem, xfo, this.colorParam.value)
3434
UndoRedoManager.getInstance().addChange(this.change)
3535

src/Tools/CreateTools/CreateFreehandLineTool.ts

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {
22
BooleanParameter,
33
TreeItem,
4+
Vec2,
45
Vec3,
56
XRPoseEvent,
67
Xfo,
@@ -22,8 +23,11 @@ import { AppData } from '../../../types/types'
2223
* @extends CreateLineTool
2324
*/
2425
class CreateFreehandLineTool extends CreateLineTool {
25-
invXfo: Xfo
26-
prevP: Vec3
26+
private invXfo: Xfo
27+
private prevPointerPos: Vec2
28+
29+
drawLineOnSurface = true
30+
2731
/**
2832
* Create a create freehand line tool.
2933
*
@@ -34,15 +38,15 @@ class CreateFreehandLineTool extends CreateLineTool {
3438
}
3539

3640
screenPosToXfo(event: ZeaMouseEvent | ZeaTouchEvent): Xfo {
37-
return super.screenPosToXfo(event, true)
41+
return super.screenPosToXfo(event, this.drawLineOnSurface)
3842
}
3943

4044
/**
4145
* Starts the creation of a free hand line.
4246
*
4347
* @param xfo - The xfo param.
4448
*/
45-
createStart(xfo: Xfo): void {
49+
createStart(xfo: Xfo, event: ZeaPointerEvent): void {
4650
const color = this.colorParam.value
4751
const lineThickness = this.lineThickness.value
4852

@@ -52,7 +56,7 @@ class CreateFreehandLineTool extends CreateLineTool {
5256
this.xfo = xfo
5357
this.invXfo = xfo.inverse()
5458
this.stage = 1
55-
this.prevP = xfo.tr
59+
this.prevPointerPos = event.pointerPos
5660
this.length = 0
5761
}
5862

@@ -62,14 +66,20 @@ class CreateFreehandLineTool extends CreateLineTool {
6266
* @param pt - The pt param.
6367
*/
6468
createMove(pt: Vec3, event: ZeaPointerEvent): void {
69+
const pointerPos = event.pointerPos
70+
6571
const p = this.invXfo.transformVec3(pt)
66-
const delta = p.subtract(this.prevP).length()
67-
this.change.update({
68-
point: p,
69-
})
72+
const delta = pointerPos.distanceTo(this.prevPointerPos)
73+
// Add a point only if the distance is greater than 5 pixels.
74+
// This is to avoid adding too many points when the mouse is moved slowly.
75+
if (delta > 5) {
76+
this.change.update({
77+
point: p,
78+
})
7079

71-
this.length += delta
72-
this.prevP = p
80+
this.length += delta
81+
this.prevPointerPos = pointerPos
82+
}
7383
}
7484

7585
/**

src/Tools/CreateTools/CreateLineTool.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class CreateLineTool extends CreateGeomTool {
3232
*
3333
* @param xfo - The xfo param.
3434
*/
35-
createStart(xfo: Xfo): void {
35+
createStart(xfo: Xfo, event: ZeaPointerEvent): void {
3636
const color = this.colorParam.value
3737
const lineThickness = this.lineThickness.value
3838
this.change = new CreateLineChange(this.parentItem, xfo, color, lineThickness)

src/Tools/CreateTools/CreateMultiLineTool.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class CreateMultiLineTool extends CreateGeomTool {
4040
*
4141
* @param xfo - The xfo param.
4242
*/
43-
createStart(xfo: Xfo): void {
43+
createStart(xfo: Xfo, event: ZeaPointerEvent): void {
4444
if (this.stage == 1) return
4545

4646
this.change = new CreateMultiLineChange(this.parentItem, xfo, this.colorParam.value)

src/Tools/CreateTools/CreateRectTool.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class CreateRectTool extends CreateGeomTool {
3030
*
3131
* @param xfo - The xfo param.
3232
*/
33-
createStart(xfo: Xfo): void {
33+
createStart(xfo: Xfo, event: ZeaPointerEvent): void {
3434
this.change = new CreateRectChange(this.parentItem, xfo, this.colorParam.value)
3535

3636
// During construction, make it note selectable.

src/Tools/CreateTools/CreateSphereTool.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class CreateSphereTool extends CreateGeomTool {
3030
*
3131
* @param xfo - The xfo param.
3232
*/
33-
createStart(xfo: Xfo): void {
33+
createStart(xfo: Xfo, event: ZeaPointerEvent): void {
3434
this.change = new CreateSphereChange(this.parentItem, xfo, this.colorParam.value)
3535

3636
// During construction, make it note selectable.

0 commit comments

Comments
 (0)