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
3912ba19
Commit
3912ba19
authored
5 years ago
by
Yuriy Maksymets
Browse files
Options
Downloads
Patches
Plain Diff
Length based matrix weights
parent
0c2de929
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/shapes.js
+24
-25
24 additions, 25 deletions
src/shapes.js
with
24 additions
and
25 deletions
src/shapes.js
+
24
−
25
View file @
3912ba19
...
...
@@ -13,7 +13,7 @@ const numAngleCells = 180 / angleStep
const
rhoMax
=
1000
const
getDistance
=
(
a
,
b
)
=>
{
if
(
!
(
a
&
b
))
return
0
if
(
!
(
a
&
&
b
))
return
0
return
Math
.
sqrt
(
(
a
[
0
]
-
b
[
0
])
*
(
a
[
0
]
-
b
[
0
])
+
(
a
[
1
]
-
b
[
1
])
*
(
a
[
1
]
-
b
[
1
]),
)
...
...
@@ -73,6 +73,14 @@ function boundingCoords(points) {
}
}
const
LINE_Q
=
10
function
couldBeLine
(
points
)
{
const
{
maxX
,
minX
,
maxY
,
minY
}
=
boundingCoords
(
points
)
const
[
dx
,
dy
]
=
[
maxX
-
minX
,
maxY
-
minY
].
map
((
x
)
=>
x
+
0.00001
)
return
dy
/
dx
>
LINE_Q
||
dx
/
dy
>
LINE_Q
}
const
MATRIX_SIZE
=
3
const
MATRIX_CENTER_RATIO
=
0.65
...
...
@@ -97,24 +105,27 @@ function computeClusters(points, xBounds, yBounds) {
.
map
(()
=>
Array
(
MATRIX_SIZE
)
.
fill
()
.
map
(()
=>
[]
),
.
map
(()
=>
({
arr
:
[],
sum
:
0
})
),
)
const
intervals
=
points
.
map
((
point
,
i
)
=>
({
point
,
dist
:
getDistance
(
point
,
points
[
i
+
1
]),
}))
let
totalSum
=
0
intervals
.
forEach
((
interval
)
=>
{
const
{
x
,
y
}
=
getCluster
(
interval
.
point
,
xBounds
,
yBounds
)
clusters
[
x
][
y
].
push
(
interval
)
clusters
[
x
][
y
].
arr
.
push
(
interval
)
clusters
[
x
][
y
].
sum
+=
interval
.
dist
totalSum
+=
interval
.
dist
})
return
clusters
return
{
arr
:
clusters
,
totalSum
}
}
function
clusterCoefficients
(
clusters
,
points
)
{
return
clusters
.
map
((
rowCluster
)
=>
rowCluster
.
map
((
cluster
)
=>
cluster
.
length
/
points
.
length
),
function
clusterCoefficients
(
clusters
)
{
return
clusters
.
arr
.
map
((
rowCluster
)
=>
rowCluster
.
map
((
cluster
)
=>
cluster
.
sum
/
clusters
.
totalSum
),
)
}
...
...
@@ -127,16 +138,8 @@ export function computeMatrixCoefficients(points, boundingRect) {
return
coefficients
}
const
LINE_Q
=
10
function
couldBeLine
(
points
)
{
const
{
maxX
,
minX
,
maxY
,
minY
}
=
boundingCoords
(
points
)
const
[
dx
,
dy
]
=
[
maxX
-
minX
,
maxY
-
minY
].
map
((
x
)
=>
x
+
0.00001
)
return
dy
/
dx
>
LINE_Q
||
dx
/
dy
>
LINE_Q
}
const
RECT_THRESHOLD_CENTER
=
0.05
const
RECT_THRESHOLD_SIDE_VARIANCE
=
0.12
const
RECT_THRESHOLD_CENTER
=
0
const
RECT_THRESHOLD_SIDE_VARIANCE
=
0.25
function
couldBeRect
(
points
)
{
if
(
points
.
length
<
4
)
return
false
...
...
@@ -145,8 +148,8 @@ function couldBeRect(points) {
const
matrixCoefficients
=
computeMatrixCoefficients
(
points
,
boundingRect
)
let
[
maxC
,
minC
]
=
[
0
,
1
]
for
(
let
i
=
0
;
i
<
3
;
i
++
)
{
for
(
let
j
=
0
;
j
<
3
;
j
++
)
{
for
(
let
i
=
0
;
i
<
MATRIX_SIZE
;
i
++
)
{
for
(
let
j
=
0
;
j
<
MATRIX_SIZE
;
j
++
)
{
if
(
!
(
i
===
j
&&
j
===
1
))
{
maxC
=
Math
.
max
(
maxC
,
matrixCoefficients
[
i
][
j
])
minC
=
Math
.
min
(
minC
,
matrixCoefficients
[
i
][
j
])
...
...
@@ -154,13 +157,9 @@ function couldBeRect(points) {
}
}
console
.
log
(
matrixCoefficients
)
if
(
(
matrixCoefficients
[
1
][
1
]
<
RECT_THRESHOLD_CENTER
&&
maxC
-
minC
<
RECT_THRESHOLD_SIDE_VARIANCE
)
||
(
maxC
-
minC
<
RECT_THRESHOLD_SIDE_VARIANCE
*
2
&&
matrixCoefficients
[
1
][
1
]
===
0
)
matrixCoefficients
[
1
][
1
]
<=
RECT_THRESHOLD_CENTER
&&
maxC
-
minC
<
RECT_THRESHOLD_SIDE_VARIANCE
)
{
return
{
coefficients
:
matrixCoefficients
,
boundingRect
}
}
...
...
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