40 lines
1.1 KiB
HTML
40 lines
1.1 KiB
HTML
|
<html lang="en">
|
||
|
<head>
|
||
|
<meta charset="UTF-8" />
|
||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||
|
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
|
||
|
<title>Document</title>
|
||
|
</head>
|
||
|
|
||
|
<body>
|
||
|
<div>Original array: <span id="src">Loading...</span></div>
|
||
|
<div>Simplified array: <span id="dest">Loading...</span></div>
|
||
|
|
||
|
<script type="module">
|
||
|
import moduleFactory from './psimpl.js'
|
||
|
import { storeCoords, unflattenCoords } from '../wasm-util/coordinates.js'
|
||
|
|
||
|
const module = moduleFactory()
|
||
|
const data = [
|
||
|
[0, 0],
|
||
|
[1, 1],
|
||
|
[1, 2],
|
||
|
[2, 2],
|
||
|
[5, 5],
|
||
|
[5, 0],
|
||
|
[6, 10],
|
||
|
[10, 10]
|
||
|
]
|
||
|
document.getElementById('src').innerText = JSON.stringify(data)
|
||
|
|
||
|
module.onRuntimeInitialized = async _ => {
|
||
|
const buffer = storeCoords(module, data)
|
||
|
const result = module.douglas_peucker(buffer, data.length * 2, 2)
|
||
|
module._free(buffer)
|
||
|
const simplified = unflattenCoords(result)
|
||
|
document.getElementById('dest').innerText = JSON.stringify(simplified)
|
||
|
}
|
||
|
</script>
|
||
|
</body>
|
||
|
</html>
|