Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Switch to GitLab Next
Sign in / Register
Toggle navigation
Open sidebar
Starbeamrainbowlabs
line-simplification
Commits
22d30135
Commit
22d30135
authored
Oct 10, 2017
by
Starbeamrainbowlabs
Browse files
Bugfix the new algorithm
parent
04b599af
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
7 deletions
+18
-7
demo.html
demo.html
+2
-2
demo.js
demo.js
+2
-2
simplify_line.js
simplify_line.js
+14
-3
No files found.
demo.html
View file @
22d30135
...
...
@@ -2,7 +2,7 @@
<html>
<head>
<meta
charset=
'utf-8'
/>
<title>
Ramer Douglas Peucker
Demo
</title>
<title>
Line Simplification
Demo
</title>
</head>
<body>
<canvas
id=
"canvas-main"
></canvas>
...
...
@@ -10,7 +10,7 @@
<div
class=
"debug-data"
>
<ul>
<li>
Points:
<output
id=
"output-point-count"
></output>
➞
<output
id=
"output-simple-point-count"
></output></li>
<li>
Epsilon
:
<input
type=
"range"
id=
"input-epsilon"
value=
"2"
min=
"0"
max=
"100"
step=
"0.05"
/>
<output
id=
"output-epsilon"
></output>
<li>
Min Area
:
<input
type=
"range"
id=
"input-epsilon"
value=
"2"
min=
"0"
max=
"100"
step=
"0.05"
/>
<output
id=
"output-epsilon"
></output>
</ul>
</div>
...
...
demo.js
View file @
22d30135
...
...
@@ -110,10 +110,10 @@ class RDPDemo
// Clear the screen
canvas
.
width
=
canvas
.
width
;
if
(
this
.
drawSimpleLine
)
this
.
draw_line
(
canvas
,
context
,
this
.
simplePoints
,
this
.
simpleLine
)
if
(
this
.
drawRawLine
)
this
.
draw_line
(
canvas
,
context
,
this
.
points
,
this
.
rawLine
);
if
(
this
.
drawSimpleLine
)
this
.
draw_line
(
canvas
,
context
,
this
.
simplePoints
,
this
.
simpleLine
)
}
draw_line
(
canvas
,
context
,
points
,
settings
)
{
...
...
simplify_line.js
View file @
22d30135
...
...
@@ -10,10 +10,16 @@ import Vector from './lib/Vector.js';
*/
function
simplify_line
(
points
,
min_area
)
{
let
smallest_area
=
Number
.
MAX_SAFE_INTEGER
,
smallest_area_i
=
1
;
// We need 3+ points to use this algorithm!
if
(
points
.
length
<
3
)
return
points
;
while
(
smallest_area
>
min_area
)
points
=
points
.
slice
();
// Shallow clone the array
while
(
true
)
{
let
smallest_area
=
Number
.
MAX_SAFE_INTEGER
,
smallest_area_i
=
1
;
for
(
let
i
=
1
;
i
<
points
.
length
-
1
;
i
++
)
{
let
next_area
=
triangle_area
(
points
[
i
-
1
],
points
[
i
],
points
[
i
+
1
]);
...
...
@@ -23,9 +29,14 @@ function simplify_line(points, min_area)
}
}
if
(
smallest_area
>=
min_area
||
points
.
length
<=
3
)
break
;
// Remove the central point of the smallest triangle
points
.
splice
(
smallest_area_i
,
1
);
}
return
points
;
}
/**
...
...
@@ -39,7 +50,7 @@ function triangle_area(a, b, c)
{
return
Math
.
abs
(
(
a
.
x
*
(
b
.
x
-
c
.
x
)
+
a
.
x
*
(
b
.
y
-
c
.
y
)
+
b
.
x
*
(
c
.
y
-
a
.
y
)
+
c
.
x
*
(
a
.
y
-
b
.
y
)
)
/
2
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment