Skip to content
Snippets Groups Projects
Commit e0b53a58 authored by Giovanni Caruso's avatar Giovanni Caruso Committed by Moritz Langenstein
Browse files

Fixed stroke radius not being synchronised correctly

parent 1cac63e9
No related branches found
No related tags found
1 merge request!45Brush size
...@@ -73,10 +73,10 @@ const smoothPath = ([...path]) => { ...@@ -73,10 +73,10 @@ const smoothPath = ([...path]) => {
return path return path
} }
const getStrokeRadius = (pressure) => { const getStrokeRadius = (pressure, radius) => {
return ( return (
MIN_STROKE_RADIUS + MIN_STROKE_RADIUS +
(stroke_radius + pressure) * (MAX_STROKE_RADIUS - MIN_STROKE_RADIUS) (radius + pressure) * (MAX_STROKE_RADIUS - MIN_STROKE_RADIUS)
) )
} }
...@@ -92,11 +92,13 @@ const createPathElem = (d, width) => { ...@@ -92,11 +92,13 @@ const createPathElem = (d, width) => {
export const renderPath = (id, points) => { export const renderPath = (id, points) => {
points = points.filter(([x]) => x != null) points = points.filter(([x]) => x != null)
let colour = "" let colour = ""
var radius = 0
// Split up points into completely non-erased segments. // Split up points into completely non-erased segments.
let segments = [[]] let segments = [[]]
for (const point of points) { for (const point of points) {
colour = point[3] colour = point[3]
radius = point[4]
if (point[5] != false) { if (point[5] != false) {
segments[segments.length - 1].push(point) segments[segments.length - 1].push(point)
} else { } else {
...@@ -134,8 +136,8 @@ export const renderPath = (id, points) => { ...@@ -134,8 +136,8 @@ export const renderPath = (id, points) => {
circleElem.setAttribute("fill", colour) circleElem.setAttribute("fill", colour)
circleElem.setAttribute("cx", subpath[0][0]) circleElem.setAttribute("cx", subpath[0][0])
circleElem.setAttribute("cy", subpath[0][1]) circleElem.setAttribute("cy", subpath[0][1])
circleElem.setAttribute("r", getStrokeRadius(subpath[0][2])) circleElem.setAttribute("r", getStrokeRadius(subpath[0][2], radius))
console.log(getStrokeRadius(subpath[0][2])) console.log(getStrokeRadius(subpath[0][2], radius))
pathGroupElem.appendChild(circleElem) pathGroupElem.appendChild(circleElem)
} else { } else {
// Further split up segments based on thickness. // Further split up segments based on thickness.
...@@ -144,13 +146,17 @@ export const renderPath = (id, points) => { ...@@ -144,13 +146,17 @@ export const renderPath = (id, points) => {
for (let i = 1; i < subpath_.length; i++) { for (let i = 1; i < subpath_.length; i++) {
if (subpath_[i][2] != w) { if (subpath_[i][2] != w) {
const d = lineFn([...subpath_.splice(0, i), subpath_[0]]) const d = lineFn([...subpath_.splice(0, i), subpath_[0]])
pathGroupElem.appendChild(createPathElem(d, getStrokeRadius(w) * 2)) pathGroupElem.appendChild(
createPathElem(d, getStrokeRadius(w, radius) * 2),
)
w = subpath_[0][2] w = subpath_[0][2]
i = 1 i = 1
} }
} }
const d = lineFn(subpath_) const d = lineFn(subpath_)
pathGroupElem.appendChild(createPathElem(d, getStrokeRadius(w) * 2)) pathGroupElem.appendChild(
createPathElem(d, getStrokeRadius(w, radius) * 2),
)
} }
} }
} }
......
...@@ -23,14 +23,14 @@ class Room extends EventTarget { ...@@ -23,14 +23,14 @@ class Room extends EventTarget {
this._y.destroy() this._y.destroy()
} }
addPath([x, y, w, colour]) { addPath([x, y, w, colour, radius]) {
const id = uuidv4() const id = uuidv4()
this._y.share.strokeAdd.set(id, Y.Array).push([[x, y, w, colour]]) this._y.share.strokeAdd.set(id, Y.Array).push([[x, y, w, colour, radius]])
return id return id
} }
extendPath(id, [x, y, w, colour]) { extendPath(id, [x, y, w, colour, radius]) {
this._y.share.strokeAdd.get(id).push([[x, y, w, colour]]) this._y.share.strokeAdd.get(id).push([[x, y, w, colour, radius]])
} }
getPaths() { getPaths() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment