diff options
author | ZackaryWelch <welch.zackary@gmail.com> | 2017-06-15 16:58:05 -0400 |
---|---|---|
committer | ZackaryWelch <welch.zackary@gmail.com> | 2017-06-15 16:58:05 -0400 |
commit | 68c6331479f3c347fd6928071edbf11967947a95 (patch) | |
tree | aa5ecf4c7e3bf5d933e4b156054956fec0a2cdc4 /src-qt5/desktop-utils/lumina-textedit/tests | |
parent | Merge branch 'master' of github.com:trueos/lumina (diff) | |
download | lumina-68c6331479f3c347fd6928071edbf11967947a95.tar.gz lumina-68c6331479f3c347fd6928071edbf11967947a95.tar.bz2 lumina-68c6331479f3c347fd6928071edbf11967947a95.zip |
HTML and Javascript syntax highlighting
Diffstat (limited to 'src-qt5/desktop-utils/lumina-textedit/tests')
-rw-r--r-- | src-qt5/desktop-utils/lumina-textedit/tests/test.html | 20 | ||||
-rw-r--r-- | src-qt5/desktop-utils/lumina-textedit/tests/test.js | 45 |
2 files changed, 65 insertions, 0 deletions
diff --git a/src-qt5/desktop-utils/lumina-textedit/tests/test.html b/src-qt5/desktop-utils/lumina-textedit/tests/test.html new file mode 100644 index 00000000..a83618bc --- /dev/null +++ b/src-qt5/desktop-utils/lumina-textedit/tests/test.html @@ -0,0 +1,20 @@ +<!DOCTYPE html> + +<html> +<head> + <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> + <title>Spoon-Knife</title> + <LINK href="styles.css" rel="stylesheet" type="text/css"> +</head> + +<body> + +<img src="forkit.gif" id="octocat" alt="" /> + +<!-- Feel free to change this text here --> +<p> + Fork me? Fork you, @octocat! +</p> + +</body> +</html> diff --git a/src-qt5/desktop-utils/lumina-textedit/tests/test.js b/src-qt5/desktop-utils/lumina-textedit/tests/test.js new file mode 100644 index 00000000..81361577 --- /dev/null +++ b/src-qt5/desktop-utils/lumina-textedit/tests/test.js @@ -0,0 +1,45 @@ +import { distance } from "./math.js"; +import { polygonCentroid } from "d3-polygon"; + +export default function(start, end) { + let distances = start.map(p1 => end.map(p2 => squaredDistance(p1, p2))), + order = bestOrder(start, end, distances); + + // Don't permute huge array + if (start.length > 8) { + return start.map((d, i) => i); + } + return bestOrder(start, end, distances); +} + +export function bestOrder(start, end, distances) { + let min = Infinity, + best = start.map((d, i) => i); + + function permute(arr, order = [], sum = 0) { + for (let i = 0; i < arr.length; i++) { + let cur = arr.splice(i, 1), + dist = distances[cur[0]][order.length]; + if (sum + dist < min) { + if (arr.length) { + permute(arr.slice(), order.concat(cur), sum + dist); + } else { + min = sum + dist; + best = order.concat(cur); + } + } + if (arr.length) { + arr.splice(i, 0, cur[0]); + } + } + } + + permute(best); + return best; +} + +function squaredDistance(p1, p2) { + let d = distance(polygonCentroid(p1), polygonCentroid(p2)); + return d * d; +} +(?:[a-z]+[\.])([a-z])+ |