|
|
@@ -80,29 +80,50 @@ export default class BrushSession extends BaseSession {
|
|
80
|
80
|
}
|
|
81
|
81
|
}
|
|
82
|
82
|
|
|
83
|
|
- // Low pass the current input point against the previous one
|
|
84
|
|
- point = vec.med(this.previous, point)
|
|
85
|
|
-
|
|
86
|
|
- this.previous = point
|
|
87
|
|
-
|
|
88
|
83
|
// Round the new point (helps keep our data tidy)
|
|
89
|
|
- const next = vec.round([...vec.sub(point, this.origin), pressure])
|
|
|
84
|
+ const temporaryPoints = [0.7, 0.9, 0.95, 1].map((v) =>
|
|
|
85
|
+ vec.round([
|
|
|
86
|
+ ...vec.sub(vec.lrp(this.previous, point, v), this.origin),
|
|
|
87
|
+ pressure,
|
|
|
88
|
+ ])
|
|
|
89
|
+ )
|
|
|
90
|
+
|
|
|
91
|
+ // Low pass the current input point against the previous one
|
|
|
92
|
+ this.previous = vec.med(this.previous, point)
|
|
90
|
93
|
|
|
91
|
94
|
// Don't add duplicate points. It's important to test against the
|
|
92
|
95
|
// adjusted (low-passed) point rather than the input point.
|
|
93
|
|
- if (vec.isEqual(this.last, next)) return
|
|
94
|
96
|
|
|
95
|
|
- this.last = next
|
|
|
97
|
+ const newPoint = vec.round([
|
|
|
98
|
+ ...vec.sub(this.previous, this.origin),
|
|
|
99
|
+ pressure,
|
|
|
100
|
+ ])
|
|
|
101
|
+
|
|
|
102
|
+ if (vec.isEqual(this.last, newPoint)) return
|
|
96
|
103
|
|
|
97
|
|
- this.points.push(next)
|
|
|
104
|
+ this.last = newPoint
|
|
|
105
|
+
|
|
|
106
|
+ this.points.push(newPoint)
|
|
98
|
107
|
|
|
99
|
108
|
// We draw a dot when the number of points is 1 or 2, so this guard
|
|
100
|
109
|
// prevents a "flash" of a dot when a user begins drawing a line.
|
|
101
|
110
|
if (this.points.length <= 2) return
|
|
102
|
111
|
|
|
103
|
|
- // ...otherwise, update the points and update the shape's parents.
|
|
|
112
|
+ // If the delta between the averaged point and the real point is
|
|
|
113
|
+ // too great, skip the temporary points. This avoids "sawblading".
|
|
|
114
|
+ const tooFarForTemporaryPoints = vec.dist(newPoint, temporaryPoints[3]) > 32
|
|
|
115
|
+
|
|
|
116
|
+ // Update the points and update the shape's parents.
|
|
104
|
117
|
const shape = getShape(data, snapshot.id) as DrawShape
|
|
105
|
|
- getShapeUtils(shape).setProperty(shape, 'points', [...this.points])
|
|
|
118
|
+
|
|
|
119
|
+ getShapeUtils(shape).setProperty(
|
|
|
120
|
+ shape,
|
|
|
121
|
+ 'points',
|
|
|
122
|
+ tooFarForTemporaryPoints
|
|
|
123
|
+ ? [...this.points]
|
|
|
124
|
+ : [...this.points, ...temporaryPoints]
|
|
|
125
|
+ )
|
|
|
126
|
+
|
|
106
|
127
|
updateParents(data, [shape.id])
|
|
107
|
128
|
}
|
|
108
|
129
|
|
|
|
@@ -118,9 +139,11 @@ export default class BrushSession extends BaseSession {
|
|
118
|
139
|
const page = getPage(data)
|
|
119
|
140
|
const shape = page.shapes[snapshot.id] as DrawShape
|
|
120
|
141
|
|
|
121
|
|
- getShapeUtils(shape)
|
|
122
|
|
- .setProperty(shape, 'points', [...this.points])
|
|
123
|
|
- .onSessionComplete(shape)
|
|
|
142
|
+ if (shape.points.length < this.points.length) {
|
|
|
143
|
+ getShapeUtils(shape).setProperty(shape, 'points', this.points)
|
|
|
144
|
+ }
|
|
|
145
|
+
|
|
|
146
|
+ getShapeUtils(shape).onSessionComplete(shape)
|
|
124
|
147
|
|
|
125
|
148
|
updateParents(data, [shape.id])
|
|
126
|
149
|
|