Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
drawing-app
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
hlgr
drawing-app
Commits
d3582653
Commit
d3582653
authored
5 years ago
by
Yuriy Maksymets
Browse files
Options
Downloads
Patches
Plain Diff
Fixed rendering with deleted points
parent
d721ca17
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/app.js
+54
-51
54 additions, 51 deletions
src/app.js
src/erasure.js
+4
-3
4 additions, 3 deletions
src/erasure.js
with
58 additions
and
54 deletions
src/app.js
+
54
−
51
View file @
d3582653
...
...
@@ -23,7 +23,7 @@ const tools = {
const
STROKECOLOUR
=
"
blue
"
const
STROKERADIUS
=
2
const
ERASERRADIUS
=
STROKERADIUS
*
8
const
ERASERRADIUS
=
STROKERADIUS
*
10
function
interpolatedCoordinate
(
start
,
end
,
length
)
{
const
dx
=
end
[
0
]
-
start
[
0
]
...
...
@@ -36,36 +36,47 @@ function interpolatedCoordinate(start, end, length) {
function
eraseAt
(
x
,
y
,
room
)
{
let
mousePos
=
[
x
,
y
]
room
.
getPaths
().
forEach
((
points
,
pathID
)
=>
{
const
t
=
computeErasureIntervals
(
points
,
mousePos
,
ERASERRADIUS
)
if
(
!
TEST_ERASE_INTERVAL
[
pathID
])
TEST_ERASE_INTERVAL
[
pathID
]
=
{}
TEST_ERASE_INTERVAL
[
pathID
]
=
combineErasureIntervals
(
TEST_ERASE_INTERVAL
[
pathID
],
t
,
)
room
.
dispatchEvent
(
new
CustomEvent
(
"
addOrUpdatePath
"
,
{
detail
:
{
id
:
pathID
,
points
},
}),
)
points
.
forEach
((
point
,
i
)
=>
{
const
distanceToPoint
=
getDistance
(
mousePos
,
point
)
if
(
distanceToPoint
<=
ERASERRADIUS
)
{
room
.
erasePoint
(
pathID
,
i
)
let
prev
,
next
if
(
i
>
0
)
{
prev
=
i
-
1
}
if
(
i
<
points
.
length
-
1
)
{
next
=
i
+
1
}
if
(
prev
!==
undefined
)
{
const
interpolatedPoint
=
interpolatedCoordinate
(
point
,
points
[
prev
],
ERASERRADIUS
,
)
room
.
insertIntoPath
(
pathID
,
prev
,
interpolatedPoint
)
}
if
(
next
!==
undefined
)
{
const
interpolatedPoint
=
interpolatedCoordinate
(
point
,
points
[
next
],
ERASERRADIUS
,
)
room
.
insertIntoPath
(
pathID
,
next
,
interpolatedPoint
)
}
//
let prev, next
//
if (i > 0) {
//
prev = i - 1
//
}
//
if (i < points.length - 1) {
//
next = i + 1
//
}
//
if (prev !== undefined) {
//
const interpolatedPoint = interpolatedCoordinate(
//
point,
//
points[prev],
//
ERASERRADIUS,
//
)
//
room.insertIntoPath(pathID, prev, interpolatedPoint)
//
}
//
if (next !== undefined) {
//
const interpolatedPoint = interpolatedCoordinate(
//
point,
//
points[next],
//
ERASERRADIUS,
//
)
//
room.insertIntoPath(pathID, next, interpolatedPoint)
//
}
}
})
})
...
...
@@ -82,7 +93,7 @@ const SVG = {
},
}
let
TEST_ERASE_INTERVAL
=
{
0
:
[[
0.1
,
0.3
],
[
0.4
,
0.8
]]
}
let
TEST_ERASE_INTERVAL
=
{}
//
{ 0: [[0.1, 0.3], [0.4, 0.8]] }
function
erasurePoints
(
pointA
,
pointB
,
start
,
fin
)
{
if
(
start
>=
fin
)
return
...
...
@@ -166,8 +177,15 @@ const addOrUpdatePathElem = (pathElems, id, points) => {
// Valid point inside a subpath
subPath
.
push
(
point
)
const
eraseIntervals
=
TEST_ERASE_INTERVAL
[
i
]
const
eraseIntervalsForPath
=
TEST_ERASE_INTERVAL
[
id
]
if
(
!
eraseIntervalsForPath
)
continue
const
eraseIntervals
=
TEST_ERASE_INTERVAL
[
id
][
i
]
if
(
!
eraseIntervals
)
continue
if
(
i
===
points
.
length
-
1
)
{
continue
}
const
nextPoint
=
points
[
i
+
1
]
for
(
const
eraseInterval
of
eraseIntervals
)
{
if
(
eraseInterval
)
{
...
...
@@ -176,18 +194,14 @@ const addOrUpdatePathElem = (pathElems, id, points) => {
toAdd
=
undefined
}
if
(
i
===
points
.
length
-
1
)
{
continue
}
const
nextPoint
=
points
[
i
+
1
]
const
[
start
,
fin
]
=
erasurePoints
(
const
erp
=
erasurePoints
(
point
,
nextPoint
,
eraseInterval
[
0
],
eraseInterval
[
1
],
)
if
(
!
(
erp
&&
erp
.
length
))
continue
const
[
start
,
fin
]
=
erp
subPath
.
push
(
start
)
...
...
@@ -302,20 +316,7 @@ function handleRoomConnectionEstablished(room) {
if
(
currentTool
==
tools
.
PEN
)
{
room
.
extendPath
(
pathIDsByPointerID
.
get
(
e
.
pointerId
),
mousePos
)
}
else
if
(
currentTool
==
tools
.
ERASER
)
{
room
.
getPaths
().
forEach
((
points
,
pathID
)
=>
{
const
t
=
computeErasureIntervals
(
points
,
mousePos
,
ERASERRADIUS
)
TEST_ERASE_INTERVAL
=
combineErasureIntervals
(
TEST_ERASE_INTERVAL
,
t
)
room
.
dispatchEvent
(
new
CustomEvent
(
"
addOrUpdatePath
"
,
{
detail
:
{
id
:
pathID
,
points
},
}),
)
points
.
forEach
((
point
,
i
)
=>
{
if
(
getDistance
(
mousePos
,
point
)
<=
ERASERRADIUS
)
{
room
.
erasePoint
(
pathID
,
i
)
}
})
})
eraseAt
(
e
.
offsetX
,
e
.
offsetY
,
room
)
}
}
...
...
@@ -379,8 +380,10 @@ function handleRoomConnectionEstablished(room) {
HTML
.
roomConnectButton
.
addEventListener
(
"
click
"
,
roomConnectButtonOnClick
)
let
pid
=
room
.
addPath
([
100
,
100
])
room
.
extendPath
(
pid
,
[
150
,
150
])
room
.
extendPath
(
pid
,
[
100
,
200
])
room
.
extendPath
(
pid
,
[
110
,
105
])
room
.
extendPath
(
pid
,
[
120
,
100
])
room
.
extendPath
(
pid
,
[
130
,
105
])
room
.
extendPath
(
pid
,
[
140
,
100
])
}
function
handleRoomConnectionError
(
err
)
{
...
...
This diff is collapsed.
Click to expand it.
src/erasure.js
+
4
−
3
View file @
d3582653
...
...
@@ -3,7 +3,7 @@ function distance([x1, y1], [x2, y2]) {
}
function
sqr
(
x
)
{
return
x
*
x
return
x
*
*
2
}
function
dist2
(
v
,
w
)
{
...
...
@@ -63,7 +63,7 @@ function cap1(x) {
}
function
erasureInterval
(
lineStart
,
lineEnd
,
erasureCenter
,
erasureRadius
)
{
const
[
cx
,
cy
]
=
interpolate
(
const
projectionPoint
=
interpolate
(
lineStart
,
lineEnd
,
project
(
lineStart
,
lineEnd
,
erasureCenter
),
...
...
@@ -72,9 +72,10 @@ function erasureInterval(lineStart, lineEnd, erasureCenter, erasureRadius) {
const
halfLength
=
Math
.
sqrt
(
erasureRadius
**
2
-
d
**
2
)
const
lineLength
=
distance
(
lineStart
,
lineEnd
)
const
touchFromStartDist
=
distance
(
lineStart
,
[
cx
,
cy
]
)
const
touchFromStartDist
=
distance
(
lineStart
,
projectionPoint
)
const
touchBeginFromStarDist
=
touchFromStartDist
-
halfLength
const
touchEndFromStarDist
=
touchFromStartDist
+
halfLength
return
[
cap0
(
touchBeginFromStarDist
/
lineLength
),
cap1
(
touchEndFromStarDist
/
lineLength
),
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment