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
sweng-group-15
drawing-app
Commits
d066cb98
Commit
d066cb98
authored
5 years ago
by
Moritz Langenstein
Browse files
Options
Downloads
Patches
Plain Diff
(ml5717) Compressed erase intervals representation, fixed singular point erasing
parent
90763166
No related branches found
Branches containing commit
No related tags found
1 merge request
!57
Erasure intervals
Pipeline
#104621
passed
5 years ago
Stage: fetch
Stage: deps
Stage: check
Stage: build
Stage: test
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/canvas.js
+5
-1
5 additions, 1 deletion
src/canvas.js
src/erasure.js
+43
-4
43 additions, 4 deletions
src/erasure.js
src/room.js
+20
-13
20 additions, 13 deletions
src/room.js
with
68 additions
and
18 deletions
src/canvas.js
+
5
−
1
View file @
d066cb98
...
...
@@ -200,9 +200,13 @@ const applyErasureIntervals = (pathID, points, erasureIntervals) => {
pathID
,
i
,
)
if
(
!
eraseIntervals
||
nextPoint
===
undefined
)
{
if
(
!
eraseIntervals
)
{
subpath
.
push
(
point
)
continue
}
else
if
(
nextPoint
===
undefined
)
{
if
(
JSON
.
stringify
(
eraseIntervals
)
!=
"
[[0,0]]
"
)
subpath
.
push
(
point
)
continue
}
if
(
!
pointWasErased
(
eraseIntervals
)
||
subpath
.
length
)
{
...
...
This diff is collapsed.
Click to expand it.
src/erasure.js
+
43
−
4
View file @
d066cb98
...
...
@@ -45,14 +45,19 @@ function project([x1, y1], [x2, y2], [x3, y3]) {
}
function
erasureInterval
(
lineStart
,
lineEnd
,
erasureCenter
,
erasureRadius
)
{
if
(
!
(
lineStart
&&
lineEnd
&&
erasureCenter
))
return
if
(
!
(
lineStart
&&
erasureCenter
))
return
undefined
if
(
!
lineEnd
)
{
const
dist2ToSingularity
=
distanceSquared
(
erasureCenter
,
lineStart
)
return
dist2ToSingularity
<=
erasureRadius
**
2
?
[
0
,
0
]
:
undefined
}
const
distToSegment2
=
distToSegmentSquared
(
lineStart
,
lineEnd
,
erasureCenter
)
if
(
erasureRadius
**
2
<
distToSegment2
)
return
if
(
erasureRadius
**
2
<
distToSegment2
)
return
undefined
const
lineLength
=
distance
(
lineStart
,
lineEnd
)
if
(
lineLength
===
0
)
{
return
distToSegment2
<=
erasureRadius
**
2
?
[
0
,
1
]
:
[
0
,
0
]
return
distToSegment2
<=
erasureRadius
**
2
?
[
0
,
1
]
:
undefined
}
const
projT
=
project
(
lineStart
,
lineEnd
,
erasureCenter
)
...
...
@@ -98,7 +103,6 @@ function overlaps([s1, e1], [, e2]) {
function
mergeIntervals
(...
intervals
)
{
if
(
!
intervals
.
length
)
return
[]
const
sorted
=
intervals
.
sort
(([
a
],
[
b
])
=>
a
>
b
)
const
stack
=
[
sorted
[
0
]]
sorted
.
forEach
((
x
)
=>
{
...
...
@@ -121,3 +125,38 @@ export function combineErasureIntervals(i1, i2) {
})
return
{
...
i2
,
...
_i1
}
}
export
function
spreadErasureIntervals
(
intervals
)
{
const
spread
=
[]
intervals
.
forEach
(([
l
,
u
])
=>
{
if
(
u
>
l
)
{
for
(
let
li
=
Math
.
floor
(
l
);
li
<
u
;
li
++
)
{
const
list
=
spread
[
li
]
||
[]
const
[
il
,
iu
]
=
[
Math
.
max
(
li
,
l
),
Math
.
min
(
li
+
1
,
u
)]
list
.
push
([
il
%
1
,
iu
==
li
+
1
?
1
:
iu
%
1
])
spread
[
li
]
=
list
}
}
else
{
spread
[
Math
.
floor
(
l
)]
=
[[
l
%
1
,
u
%
1
]]
}
})
return
spread
}
export
function
flattenErasureIntervals
(
intervals
)
{
const
flatten
=
[]
for
(
const
idx
in
intervals
)
{
if
(
intervals
[
idx
])
flatten
.
push
(
intervals
[
idx
].
map
(([
l
,
u
])
=>
[
parseInt
(
idx
)
+
l
,
parseInt
(
idx
)
+
u
]),
)
}
return
flatten
.
flat
()
}
This diff is collapsed.
Click to expand it.
src/room.js
+
20
−
13
View file @
d066cb98
...
...
@@ -11,6 +11,12 @@ yMap(Y)
yArray
(
Y
)
yWebrtc
(
Y
)
import
{
combineErasureIntervals
,
spreadErasureIntervals
,
flattenErasureIntervals
,
}
from
"
./erasure.js
"
class
Room
extends
EventTarget
{
constructor
(
name
)
{
super
()
...
...
@@ -37,23 +43,22 @@ class Room extends EventTarget {
extendErasureIntervals
(
pathID
,
pointID
,
newIntervals
)
{
const
self
=
this
const
afterJSON
=
JSON
.
stringify
(
newIntervals
)
// eslint-disable-next-line require-yield
this
.
_y
.
db
.
requestTransaction
(
function
*
requestTransaction
()
{
const
pathIntervals
=
yield
*
JSON
.
parse
(
self
.
sharedMergeIntervals
.
get
(
pathID
)
||
"
{}
"
,
)
const
prevJSON
=
self
.
sharedMergeIntervals
.
get
(
pathID
)
||
"
[]
"
const
pathIntervals
=
JSON
.
parse
(
prevJSON
)
const
combinedIntervals
=
combineErasureIntervals
(
[
pathIntervals
],
[
flattenErasureIntervals
({
[
pointID
]:
newIntervals
})],
)[
0
]
const
postJSON
=
JSON
.
stringify
(
combinedIntervals
)
if
(
after
JSON
==
JSON
.
stringify
(
pathIntervals
[
pointID
])
)
{
if
(
prev
JSON
==
post
JSON
)
{
return
}
pathIntervals
[
pointID
]
=
newIntervals
yield
*
self
.
sharedMergeIntervals
.
set
(
pathID
,
JSON
.
stringify
(
pathIntervals
),
)
self
.
sharedMergeIntervals
.
set
(
pathID
,
postJSON
)
})
}
...
...
@@ -88,8 +93,10 @@ class Room extends EventTarget {
_generateRemovedIntervals
(
id
)
{
const
intervals
=
this
.
sharedMergeIntervals
.
get
(
id
)
if
(
!
intervals
)
return
[]
return
JSON
.
parse
(
intervals
)
return
spreadErasureIntervals
(
JSON
.
parse
(
intervals
))
}
inviteUser
(
id
)
{
...
...
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