frame.image 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +79 -0
- package/eslint.config.js +28 -0
- package/index.html +13 -0
- package/package.json +31 -0
- package/public/vite.svg +1 -0
- package/src/Akima.ts +134 -0
- package/src/App.css +42 -0
- package/src/App.tsx +123 -0
- package/src/DrawCanvas.tsx +191 -0
- package/src/Point.ts +97 -0
- package/src/SortedPoints.ts +219 -0
- package/src/assets/react.svg +1 -0
- package/src/index.css +68 -0
- package/src/main.tsx +10 -0
- package/src/vite-env.d.ts +1 -0
- package/tsconfig.app.json +26 -0
- package/tsconfig.json +7 -0
- package/tsconfig.node.json +24 -0
- package/vite.config.ts +7 -0
package/README.md
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# Frame Image Manager
|
|
2
|
+
|
|
3
|
+
This project is a part of the **Form Manager** suite. It provides functionality to manage and manipulate frame images effectively.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- Load and display frame images.
|
|
8
|
+
- Apply transformations (resize, crop, rotate).
|
|
9
|
+
- Export processed images in multiple formats.
|
|
10
|
+
- Easy integration with other modules in the Form Manager suite.
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
1. Clone the repository:
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
git clone https://github.com/your-repo/Form-Manager.git
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
2. Navigate to the `frame.image` directory:
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
cd Form-Manager/sample/frame.image
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
3. Install dependencies:
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
npm install
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Publish
|
|
33
|
+
|
|
34
|
+
_update package.json_
|
|
35
|
+
|
|
36
|
+
```
|
|
37
|
+
yarn build
|
|
38
|
+
npm login
|
|
39
|
+
npm publish
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Usage
|
|
43
|
+
|
|
44
|
+
1. Import the module:
|
|
45
|
+
|
|
46
|
+
```javascript
|
|
47
|
+
import { DrawCanvas } from './DrawCanvas';
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
2. Use the module in a JSX component:
|
|
51
|
+
|
|
52
|
+
```javascript
|
|
53
|
+
function App() {
|
|
54
|
+
const [show, setShow] = useState({
|
|
55
|
+
akima: true,
|
|
56
|
+
center: true,
|
|
57
|
+
polygon: false,
|
|
58
|
+
box: false,
|
|
59
|
+
points: true,
|
|
60
|
+
background: true,
|
|
61
|
+
});
|
|
62
|
+
const [dataUrl, setDataUrl] = useState<string | undefined>(undefined);
|
|
63
|
+
const width = 800;
|
|
64
|
+
const height = 600;
|
|
65
|
+
|
|
66
|
+
return (
|
|
67
|
+
<>
|
|
68
|
+
<DrawCanvas
|
|
69
|
+
width={width}
|
|
70
|
+
height={height}
|
|
71
|
+
imageUrl={dataUrl}
|
|
72
|
+
show={show}
|
|
73
|
+
/>
|
|
74
|
+
</>
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export default App;
|
|
79
|
+
```
|
package/eslint.config.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import js from '@eslint/js'
|
|
2
|
+
import globals from 'globals'
|
|
3
|
+
import reactHooks from 'eslint-plugin-react-hooks'
|
|
4
|
+
import reactRefresh from 'eslint-plugin-react-refresh'
|
|
5
|
+
import tseslint from 'typescript-eslint'
|
|
6
|
+
|
|
7
|
+
export default tseslint.config(
|
|
8
|
+
{ ignores: ['dist'] },
|
|
9
|
+
{
|
|
10
|
+
extends: [js.configs.recommended, ...tseslint.configs.recommended],
|
|
11
|
+
files: ['**/*.{ts,tsx}'],
|
|
12
|
+
languageOptions: {
|
|
13
|
+
ecmaVersion: 2020,
|
|
14
|
+
globals: globals.browser,
|
|
15
|
+
},
|
|
16
|
+
plugins: {
|
|
17
|
+
'react-hooks': reactHooks,
|
|
18
|
+
'react-refresh': reactRefresh,
|
|
19
|
+
},
|
|
20
|
+
rules: {
|
|
21
|
+
...reactHooks.configs.recommended.rules,
|
|
22
|
+
'react-refresh/only-export-components': [
|
|
23
|
+
'warn',
|
|
24
|
+
{ allowConstantExport: true },
|
|
25
|
+
],
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
)
|
package/index.html
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
7
|
+
<title>Vite + React + TS</title>
|
|
8
|
+
</head>
|
|
9
|
+
<body>
|
|
10
|
+
<div id="root"></div>
|
|
11
|
+
<script type="module" src="/src/main.tsx"></script>
|
|
12
|
+
</body>
|
|
13
|
+
</html>
|
package/package.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "frame.image",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "A React component for drawing a frame on a canvas element.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "Christian.Todd@rodenstock.com",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"dev": "vite",
|
|
10
|
+
"build": "tsc -b && vite build",
|
|
11
|
+
"lint": "eslint .",
|
|
12
|
+
"preview": "vite preview"
|
|
13
|
+
},
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"react": "^19.0.0",
|
|
16
|
+
"react-dom": "^19.0.0"
|
|
17
|
+
},
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"@eslint/js": "^9.22.0",
|
|
20
|
+
"@types/react": "^19.1.2",
|
|
21
|
+
"@types/react-dom": "^19.0.4",
|
|
22
|
+
"@vitejs/plugin-react": "^4.3.4",
|
|
23
|
+
"eslint": "^9.22.0",
|
|
24
|
+
"eslint-plugin-react-hooks": "^5.2.0",
|
|
25
|
+
"eslint-plugin-react-refresh": "^0.4.19",
|
|
26
|
+
"globals": "^16.0.0",
|
|
27
|
+
"typescript": "~5.7.2",
|
|
28
|
+
"typescript-eslint": "^8.26.1",
|
|
29
|
+
"vite": "^6.3.1"
|
|
30
|
+
}
|
|
31
|
+
}
|
package/public/vite.svg
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>
|
package/src/Akima.ts
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
export function calcSplineKoef_Akima(
|
|
2
|
+
xw_ascending: number[],
|
|
3
|
+
yw: number[]
|
|
4
|
+
// koef_akima: number[][]
|
|
5
|
+
): number[][] {
|
|
6
|
+
//WHauk: Konvertierung C#, Erweiterungen, Vereinfachungen (Extrapolation, Ringschluss), 2010
|
|
7
|
+
let fehler = 0;
|
|
8
|
+
|
|
9
|
+
const koef_akima = Array.from({ length: xw_ascending.length }, () =>
|
|
10
|
+
Array(3).fill(0)
|
|
11
|
+
);
|
|
12
|
+
|
|
13
|
+
const size = xw_ascending.length + 4; //erweitern der x-Werte an Anfang und Ende
|
|
14
|
+
const x = new Array(size).fill(0);
|
|
15
|
+
const y = new Array(size).fill(0);
|
|
16
|
+
const step_x = new Array(size).fill(0);
|
|
17
|
+
|
|
18
|
+
if (xw_ascending.length < 3) {
|
|
19
|
+
fehler = 1;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
if (fehler == 0) {
|
|
23
|
+
for (let i = 0; i < xw_ascending.length; i++) {
|
|
24
|
+
x[2 + i] = xw_ascending[i];
|
|
25
|
+
y[2 + i] = yw[i];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
for (let i = 0; i < xw_ascending.length - 1; i++) {
|
|
29
|
+
step_x[i + 2] = xw_ascending[i + 1] - xw_ascending[i];
|
|
30
|
+
if (step_x[i + 2] < 1e-7) {
|
|
31
|
+
fehler = 2;
|
|
32
|
+
break;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (fehler == 0) {
|
|
38
|
+
//Randstützstellen
|
|
39
|
+
x[1] = x[2] - step_x[2];
|
|
40
|
+
step_x[1] = step_x[2];
|
|
41
|
+
|
|
42
|
+
x[0] = x[1] - step_x[1];
|
|
43
|
+
step_x[0] = step_x[1];
|
|
44
|
+
|
|
45
|
+
x[size - 2] = x[size - 3] + step_x[size - 4];
|
|
46
|
+
step_x[size - 3] = step_x[size - 4];
|
|
47
|
+
|
|
48
|
+
x[size - 1] = x[size - 2] + step_x[size - 4];
|
|
49
|
+
step_x[size - 2] = step_x[size - 3];
|
|
50
|
+
|
|
51
|
+
//(nicht ganz korrekt bei nicht-äquidistanten Knoten)
|
|
52
|
+
y[0] = yw[yw.length - 2];
|
|
53
|
+
y[1] = yw[yw.length - 1];
|
|
54
|
+
y[size - 2] = yw[0];
|
|
55
|
+
y[size - 1] = yw[1];
|
|
56
|
+
|
|
57
|
+
//Berechnen der Steigungen -> Empirische Formel nach Akima...
|
|
58
|
+
const m = new Array(size).fill(0);
|
|
59
|
+
const t = new Array(size).fill(0);
|
|
60
|
+
|
|
61
|
+
for (let i = 0; i < size - 1; i++) m[i] = (y[i + 1] - y[i]) / step_x[i]; //Geradensteigungen
|
|
62
|
+
|
|
63
|
+
for (let i = 2; i < size - 2; i++) {
|
|
64
|
+
t[i] = Math.abs(m[i + 1] - m[i]) + Math.abs(m[i - 1] - m[i - 2]); //Summe: abs(diff Steigungen links) + abs(diff Steigungen rechts)
|
|
65
|
+
if (t[i] < 1e-7) {
|
|
66
|
+
koef_akima[i - 2][0] = (m[i - 1] + m[i]) * 0.5; //Steigung: Mittelwert r/l
|
|
67
|
+
} else {
|
|
68
|
+
koef_akima[i - 2][0] =
|
|
69
|
+
(m[i - 1] * Math.abs(m[i + 1] - m[i]) +
|
|
70
|
+
m[i] * Math.abs(m[i - 1] - m[i - 2])) /
|
|
71
|
+
t[i];
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
//Berechnen der restlichen Koeffizienten
|
|
76
|
+
for (
|
|
77
|
+
let i = 2;
|
|
78
|
+
i < size - 2;
|
|
79
|
+
i++ //i < size - 2: alle Stützstellen
|
|
80
|
+
) {
|
|
81
|
+
if (i < size - 3) {
|
|
82
|
+
koef_akima[i - 2][1] =
|
|
83
|
+
(3 * (y[i + 1] - y[i])) / (step_x[i] * step_x[i]) -
|
|
84
|
+
(2 * koef_akima[i - 2][0] + koef_akima[i - 1][0]) / step_x[i];
|
|
85
|
+
|
|
86
|
+
koef_akima[i - 2][2] =
|
|
87
|
+
(koef_akima[i - 2][0] + koef_akima[i - 1][0]) /
|
|
88
|
+
(step_x[i] * step_x[i]) -
|
|
89
|
+
(2 * (y[i + 1] - y[i])) / (step_x[i] * step_x[i] * step_x[i]);
|
|
90
|
+
} //letzte Stützstelle
|
|
91
|
+
else {
|
|
92
|
+
koef_akima[i - 2][1] =
|
|
93
|
+
(3 * (y[i + 1] - y[i])) / (step_x[i] * step_x[i]) -
|
|
94
|
+
(2 * koef_akima[i - 2][0] + koef_akima[i - 2 /*!*/][0]) / step_x[i];
|
|
95
|
+
|
|
96
|
+
koef_akima[i - 2][2] =
|
|
97
|
+
(koef_akima[i - 2][0] + koef_akima[i - 2 /*!*/][0]) /
|
|
98
|
+
(step_x[i] * step_x[i]) -
|
|
99
|
+
(2 * (y[i + 1] - y[i])) / (step_x[i] * step_x[i] * step_x[i]);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
} //if (fehler == 0)
|
|
103
|
+
|
|
104
|
+
return koef_akima;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export function getSplineWert(
|
|
108
|
+
x0: number,
|
|
109
|
+
xwerte: number[],
|
|
110
|
+
ywerte: number[],
|
|
111
|
+
koef: number[][]
|
|
112
|
+
): number {
|
|
113
|
+
let y0 = 0;
|
|
114
|
+
|
|
115
|
+
let index = xwerte.length - 1; //für Extrapolation rechts (für Notfall)
|
|
116
|
+
|
|
117
|
+
if (x0 < xwerte[0]) {
|
|
118
|
+
index = 0; //für Extrapolation links (für Notfall)
|
|
119
|
+
} else {
|
|
120
|
+
for (let i = 0; i < xwerte.length - 1; i++) {
|
|
121
|
+
if (x0 >= xwerte[i] && x0 < xwerte[i + 1]) {
|
|
122
|
+
index = i;
|
|
123
|
+
break;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
y0 = koef[index][2];
|
|
129
|
+
y0 = y0 * (x0 - xwerte[index]) + koef[index][1];
|
|
130
|
+
y0 = y0 * (x0 - xwerte[index]) + koef[index][0];
|
|
131
|
+
y0 = y0 * (x0 - xwerte[index]) + ywerte[index];
|
|
132
|
+
|
|
133
|
+
return y0;
|
|
134
|
+
}
|
package/src/App.css
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
#root {
|
|
2
|
+
max-width: 1280px;
|
|
3
|
+
margin: 0 auto;
|
|
4
|
+
padding: 2rem;
|
|
5
|
+
text-align: center;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
.logo {
|
|
9
|
+
height: 6em;
|
|
10
|
+
padding: 1.5em;
|
|
11
|
+
will-change: filter;
|
|
12
|
+
transition: filter 300ms;
|
|
13
|
+
}
|
|
14
|
+
.logo:hover {
|
|
15
|
+
filter: drop-shadow(0 0 2em #646cffaa);
|
|
16
|
+
}
|
|
17
|
+
.logo.react:hover {
|
|
18
|
+
filter: drop-shadow(0 0 2em #61dafbaa);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
@keyframes logo-spin {
|
|
22
|
+
from {
|
|
23
|
+
transform: rotate(0deg);
|
|
24
|
+
}
|
|
25
|
+
to {
|
|
26
|
+
transform: rotate(360deg);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
@media (prefers-reduced-motion: no-preference) {
|
|
31
|
+
a:nth-of-type(2) .logo {
|
|
32
|
+
animation: logo-spin infinite 20s linear;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
.card {
|
|
37
|
+
padding: 2em;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
.read-the-docs {
|
|
41
|
+
color: #888;
|
|
42
|
+
}
|
package/src/App.tsx
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { ChangeEvent, useRef, useState } from 'react';
|
|
2
|
+
import './App.css';
|
|
3
|
+
import { DrawCanvas } from './DrawCanvas';
|
|
4
|
+
|
|
5
|
+
function App() {
|
|
6
|
+
const [show, setShow] = useState({
|
|
7
|
+
akima: true,
|
|
8
|
+
center: true,
|
|
9
|
+
polygon: false,
|
|
10
|
+
box: false,
|
|
11
|
+
points: true,
|
|
12
|
+
background: true,
|
|
13
|
+
});
|
|
14
|
+
const [dataUrl, setDataUrl] = useState<string | undefined>(undefined);
|
|
15
|
+
|
|
16
|
+
const fileInputRef = useRef<HTMLInputElement | null>(null);
|
|
17
|
+
|
|
18
|
+
const width = 800;
|
|
19
|
+
const height = 600;
|
|
20
|
+
|
|
21
|
+
// Event listener for mouse click
|
|
22
|
+
|
|
23
|
+
const handleFileChange = (event: React.ChangeEvent<HTMLInputElement>) => {
|
|
24
|
+
const file = event.target.files?.[0];
|
|
25
|
+
if (file) {
|
|
26
|
+
const reader = new FileReader();
|
|
27
|
+
reader.onload = (e) => {
|
|
28
|
+
const url = e.target?.result as string;
|
|
29
|
+
setDataUrl(url);
|
|
30
|
+
// Handle the loaded image data URL (e.g., pass it to the DrawCanvas component)
|
|
31
|
+
console.log('Loaded image data URL:', url);
|
|
32
|
+
// drawImageOnCanvas(dataUrl);
|
|
33
|
+
};
|
|
34
|
+
reader.readAsDataURL(file);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
function handleCheckboxChange(key: keyof typeof show) {
|
|
39
|
+
return (e: ChangeEvent<HTMLInputElement>): void => {
|
|
40
|
+
setShow((prevShow) => ({
|
|
41
|
+
...prevShow,
|
|
42
|
+
[key]: e.target.checked,
|
|
43
|
+
}));
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const handleCheckboxBackgroundChange = handleCheckboxChange('background');
|
|
48
|
+
const handleCheckboxCenterChange = handleCheckboxChange('center');
|
|
49
|
+
const handleCheckboxBoxChange = handleCheckboxChange('box');
|
|
50
|
+
const handleCheckboxPolygonChange = handleCheckboxChange('polygon');
|
|
51
|
+
const handleCheckboxPointsChange = handleCheckboxChange('points');
|
|
52
|
+
const handleCheckboxAkimaChange = handleCheckboxChange('akima');
|
|
53
|
+
|
|
54
|
+
return (
|
|
55
|
+
<>
|
|
56
|
+
<input
|
|
57
|
+
type="file"
|
|
58
|
+
ref={fileInputRef}
|
|
59
|
+
accept="image/*"
|
|
60
|
+
onChange={handleFileChange}
|
|
61
|
+
/>
|
|
62
|
+
<br />
|
|
63
|
+
<label>
|
|
64
|
+
<input
|
|
65
|
+
type="checkbox"
|
|
66
|
+
defaultChecked
|
|
67
|
+
onChange={(e) => handleCheckboxCenterChange(e)}
|
|
68
|
+
/>{' '}
|
|
69
|
+
Center
|
|
70
|
+
</label>
|
|
71
|
+
<label>
|
|
72
|
+
<input
|
|
73
|
+
type="checkbox"
|
|
74
|
+
defaultChecked
|
|
75
|
+
onChange={(e) => handleCheckboxBackgroundChange(e)}
|
|
76
|
+
/>{' '}
|
|
77
|
+
Background
|
|
78
|
+
</label>
|
|
79
|
+
<label>
|
|
80
|
+
<input
|
|
81
|
+
type="checkbox"
|
|
82
|
+
defaultChecked
|
|
83
|
+
onChange={(e) => handleCheckboxPointsChange(e)}
|
|
84
|
+
/>{' '}
|
|
85
|
+
Points
|
|
86
|
+
</label>
|
|
87
|
+
<label>
|
|
88
|
+
<input
|
|
89
|
+
type="checkbox"
|
|
90
|
+
defaultChecked
|
|
91
|
+
onChange={(e) => handleCheckboxPolygonChange(e)}
|
|
92
|
+
/>{' '}
|
|
93
|
+
Polygon
|
|
94
|
+
</label>
|
|
95
|
+
<label>
|
|
96
|
+
<input
|
|
97
|
+
type="checkbox"
|
|
98
|
+
defaultChecked
|
|
99
|
+
onChange={(e) => handleCheckboxBoxChange(e)}
|
|
100
|
+
/>{' '}
|
|
101
|
+
Box
|
|
102
|
+
</label>
|
|
103
|
+
<label>
|
|
104
|
+
<input
|
|
105
|
+
type="checkbox"
|
|
106
|
+
defaultChecked
|
|
107
|
+
onChange={(e) => handleCheckboxAkimaChange(e)}
|
|
108
|
+
/>{' '}
|
|
109
|
+
Akima
|
|
110
|
+
</label>
|
|
111
|
+
<br />
|
|
112
|
+
|
|
113
|
+
<DrawCanvas
|
|
114
|
+
width={width}
|
|
115
|
+
height={height}
|
|
116
|
+
imageUrl={dataUrl}
|
|
117
|
+
show={show}
|
|
118
|
+
/>
|
|
119
|
+
</>
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export default App;
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import { JSX, useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
2
|
+
import { Point } from './Point';
|
|
3
|
+
import { SortedPoints } from './SortedPoints';
|
|
4
|
+
|
|
5
|
+
export function DrawCanvas(props: {
|
|
6
|
+
width: number;
|
|
7
|
+
height: number;
|
|
8
|
+
show: {
|
|
9
|
+
background: boolean;
|
|
10
|
+
center: boolean;
|
|
11
|
+
akima: boolean;
|
|
12
|
+
polygon: boolean;
|
|
13
|
+
box: boolean;
|
|
14
|
+
points: boolean;
|
|
15
|
+
};
|
|
16
|
+
imageUrl?: string;
|
|
17
|
+
}): JSX.Element {
|
|
18
|
+
const universeCenter = useMemo(
|
|
19
|
+
() => new Point(props.width / 2, props.height / 2),
|
|
20
|
+
[props.height, props.width]
|
|
21
|
+
); // Center of the canvas is [400,300]
|
|
22
|
+
|
|
23
|
+
const offset = 200;
|
|
24
|
+
const [points, setPoints] = useState<Point[]>([
|
|
25
|
+
new Point(offset, 0, universeCenter),
|
|
26
|
+
new Point(0, offset, universeCenter),
|
|
27
|
+
new Point(-offset, 0, universeCenter),
|
|
28
|
+
new Point(0, -offset, universeCenter),
|
|
29
|
+
]); // Store points
|
|
30
|
+
|
|
31
|
+
const canvasRef = useRef<HTMLCanvasElement | null>(null);
|
|
32
|
+
|
|
33
|
+
const drawObjects = useCallback(
|
|
34
|
+
(context: CanvasRenderingContext2D) => {
|
|
35
|
+
const sortedPoints = new SortedPoints(points, universeCenter);
|
|
36
|
+
if (props.show.center) {
|
|
37
|
+
sortedPoints.drawCenter(context);
|
|
38
|
+
}
|
|
39
|
+
if (props.show.box) {
|
|
40
|
+
sortedPoints.drawBox(context);
|
|
41
|
+
}
|
|
42
|
+
if (props.show.polygon) {
|
|
43
|
+
sortedPoints.drawPolygon(context);
|
|
44
|
+
}
|
|
45
|
+
if (props.show.points) {
|
|
46
|
+
sortedPoints.drawPoints(context);
|
|
47
|
+
}
|
|
48
|
+
if (props.show.akima) {
|
|
49
|
+
sortedPoints.drawAkima(context);
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
[
|
|
53
|
+
points,
|
|
54
|
+
props.show.akima,
|
|
55
|
+
props.show.box,
|
|
56
|
+
props.show.center,
|
|
57
|
+
props.show.points,
|
|
58
|
+
props.show.polygon,
|
|
59
|
+
universeCenter,
|
|
60
|
+
]
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
const drawBackground = useCallback(
|
|
64
|
+
(context: CanvasRenderingContext2D) => {
|
|
65
|
+
const canvas = canvasRef.current;
|
|
66
|
+
if (canvas) {
|
|
67
|
+
if (props.imageUrl && props.show.background) {
|
|
68
|
+
const img = new Image();
|
|
69
|
+
img.onload = () => {
|
|
70
|
+
context.clearRect(0, 0, canvas.width, canvas.height);
|
|
71
|
+
// Draw the image on the canvas
|
|
72
|
+
context.drawImage(img, 0, 0, canvas.width, canvas.height);
|
|
73
|
+
|
|
74
|
+
// Redraw points after the background
|
|
75
|
+
drawObjects(context);
|
|
76
|
+
};
|
|
77
|
+
img.src = props.imageUrl;
|
|
78
|
+
} else {
|
|
79
|
+
context.clearRect(0, 0, canvas.width, canvas.height);
|
|
80
|
+
context.fillStyle = 'lightgrey';
|
|
81
|
+
context.fillRect(0, 0, canvas.width, canvas.height);
|
|
82
|
+
|
|
83
|
+
// Redraw points after the background
|
|
84
|
+
drawObjects(context);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
[props.imageUrl, props.show.background, drawObjects] // Include points in dependencies
|
|
89
|
+
);
|
|
90
|
+
|
|
91
|
+
const getCurrentPoint = useCallback(
|
|
92
|
+
(canvas: HTMLCanvasElement, event: MouseEvent): Point => {
|
|
93
|
+
const rect = canvas.getBoundingClientRect();
|
|
94
|
+
const x = event.clientX - rect.left - universeCenter.X;
|
|
95
|
+
const y = universeCenter.Y - (event.clientY - rect.top);
|
|
96
|
+
return new Point(x, y, universeCenter);
|
|
97
|
+
},
|
|
98
|
+
[universeCenter]
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
// Event listener for mouse click
|
|
102
|
+
const handleMouseClick = useCallback(
|
|
103
|
+
(event: MouseEvent) => {
|
|
104
|
+
event.preventDefault();
|
|
105
|
+
const canvas = canvasRef.current;
|
|
106
|
+
if (!canvas) return;
|
|
107
|
+
|
|
108
|
+
const context = canvas.getContext('2d');
|
|
109
|
+
if (!context) return;
|
|
110
|
+
|
|
111
|
+
const point = getCurrentPoint(canvas, event);
|
|
112
|
+
|
|
113
|
+
// Add the new point to the list
|
|
114
|
+
setPoints((prevPoints) => [...prevPoints, point]);
|
|
115
|
+
|
|
116
|
+
// Draw the new point
|
|
117
|
+
context.fillStyle = 'red';
|
|
118
|
+
context.beginPath();
|
|
119
|
+
context.arc(point.X, point.Y, 5, 0, 2 * Math.PI);
|
|
120
|
+
context.fill();
|
|
121
|
+
},
|
|
122
|
+
[getCurrentPoint]
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
const handleContextMenu = useCallback(
|
|
126
|
+
(event: MouseEvent) => {
|
|
127
|
+
event.preventDefault();
|
|
128
|
+
const canvas = canvasRef.current;
|
|
129
|
+
if (!canvas) return;
|
|
130
|
+
const point = getCurrentPoint(canvas, event);
|
|
131
|
+
const minIndex = point.findMinDistPoint(points);
|
|
132
|
+
setPoints((prevPoints) =>
|
|
133
|
+
prevPoints.filter((_, index) => index !== minIndex)
|
|
134
|
+
);
|
|
135
|
+
},
|
|
136
|
+
[getCurrentPoint, points]
|
|
137
|
+
);
|
|
138
|
+
|
|
139
|
+
useEffect(() => {
|
|
140
|
+
const canvas = canvasRef.current;
|
|
141
|
+
if (canvas) {
|
|
142
|
+
const context = canvas.getContext('2d');
|
|
143
|
+
if (context /*&& dataUrl*/) {
|
|
144
|
+
drawBackground(context);
|
|
145
|
+
// new Point(0, 0, universeCenter).draw(context, 'blue', {
|
|
146
|
+
// text: 'origin',
|
|
147
|
+
// offset: 5,
|
|
148
|
+
// });
|
|
149
|
+
// new Point(100, 0, universeCenter).draw(context, 'blue', {
|
|
150
|
+
// text: '1',
|
|
151
|
+
// offset: 5,
|
|
152
|
+
// });
|
|
153
|
+
// new Point(-100, 0, universeCenter).draw(context, 'blue', {
|
|
154
|
+
// text: '2',
|
|
155
|
+
// offset: 5,
|
|
156
|
+
// });
|
|
157
|
+
// new Point(0, 100, universeCenter).draw(context, 'blue', {
|
|
158
|
+
// text: '3',
|
|
159
|
+
// offset: 5,
|
|
160
|
+
// });
|
|
161
|
+
// new Point(0, -100, universeCenter).draw(context, 'blue', {
|
|
162
|
+
// text: '4',
|
|
163
|
+
// offset: 5,
|
|
164
|
+
// });
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// Add event listener
|
|
168
|
+
canvas.addEventListener('click', handleMouseClick);
|
|
169
|
+
canvas.addEventListener('contextmenu', handleContextMenu);
|
|
170
|
+
|
|
171
|
+
// Cleanup event listeners and interval on component unmount
|
|
172
|
+
return () => {
|
|
173
|
+
canvas.removeEventListener('click', handleMouseClick);
|
|
174
|
+
canvas.removeEventListener('contextmenu', handleContextMenu);
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
}, [drawBackground, handleContextMenu, handleMouseClick, universeCenter]);
|
|
178
|
+
|
|
179
|
+
return (
|
|
180
|
+
<canvas
|
|
181
|
+
ref={canvasRef}
|
|
182
|
+
width={props.width}
|
|
183
|
+
height={props.height}
|
|
184
|
+
id="idCanvas"
|
|
185
|
+
style={{ backgroundColor: 'lightgrey' }}
|
|
186
|
+
// onClick={handleCanvasClick} // Add the click event listener
|
|
187
|
+
>
|
|
188
|
+
Your browser does not support the HTML canvas tag.
|
|
189
|
+
</canvas>
|
|
190
|
+
);
|
|
191
|
+
}
|
package/src/Point.ts
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
export class Point {
|
|
2
|
+
private x: number;
|
|
3
|
+
private y: number;
|
|
4
|
+
private xOrigin: number;
|
|
5
|
+
private yOrigin: number;
|
|
6
|
+
|
|
7
|
+
constructor(x: number, y: number, origin?: Point) {
|
|
8
|
+
this.xOrigin = origin ? origin.X : 0;
|
|
9
|
+
this.yOrigin = origin ? origin.Y : 0;
|
|
10
|
+
this.x = x;
|
|
11
|
+
this.y = y;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
get X() {
|
|
15
|
+
return this.x;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
get Y() {
|
|
19
|
+
return this.y;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
get Origin(): Point {
|
|
23
|
+
return new Point(this.xOrigin, this.yOrigin);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
get Radius(): number {
|
|
27
|
+
return (
|
|
28
|
+
Math.round(Math.sqrt(this.X * this.X + this.Y * this.Y) * 1000) / 1000
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
relAtan(origin: Point): number {
|
|
33
|
+
const cos = this.X - origin.X;
|
|
34
|
+
const sin = this.Y - origin.Y;
|
|
35
|
+
let atan2 = Math.atan2(sin, cos); // atan2 range is [-PI, PI]
|
|
36
|
+
if (atan2 < 0) {
|
|
37
|
+
// atan2 is negative, add 2 * Math.PI to make it positive
|
|
38
|
+
atan2 += Math.PI * 2;
|
|
39
|
+
}
|
|
40
|
+
return Math.round(atan2 * 1000) / 1000;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
draw(
|
|
44
|
+
context: CanvasRenderingContext2D,
|
|
45
|
+
strokeStyle?: string,
|
|
46
|
+
index?: {
|
|
47
|
+
text: string;
|
|
48
|
+
offset: number;
|
|
49
|
+
}
|
|
50
|
+
): void {
|
|
51
|
+
context.fillStyle = strokeStyle ?? 'magenta';
|
|
52
|
+
context.beginPath();
|
|
53
|
+
context.arc(
|
|
54
|
+
this.X + this.xOrigin,
|
|
55
|
+
this.yOrigin - this.Y,
|
|
56
|
+
5,
|
|
57
|
+
0,
|
|
58
|
+
2 * Math.PI
|
|
59
|
+
);
|
|
60
|
+
context.fill();
|
|
61
|
+
if (index) {
|
|
62
|
+
context.font = '12px Arial';
|
|
63
|
+
context.fillStyle = 'black';
|
|
64
|
+
context.fillText(
|
|
65
|
+
index.text,
|
|
66
|
+
this.X + this.xOrigin + index.offset,
|
|
67
|
+
this.yOrigin - this.Y - index.offset
|
|
68
|
+
); // Adjust text position
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
drawCross(context: CanvasRenderingContext2D): void {
|
|
73
|
+
context.strokeStyle = 'red';
|
|
74
|
+
this.drawLine(context, new Point(this.X + 100, this.Y));
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
drawLine(context: CanvasRenderingContext2D, point: Point): void {
|
|
78
|
+
context.strokeStyle = 'green';
|
|
79
|
+
context.lineWidth = 2;
|
|
80
|
+
context.beginPath();
|
|
81
|
+
context.moveTo(this.X + this.xOrigin, this.yOrigin - this.Y);
|
|
82
|
+
context.lineTo(point.X + point.xOrigin, point.yOrigin - point.Y);
|
|
83
|
+
context.stroke();
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
findMinDistPoint(points: Point[]): number {
|
|
87
|
+
const minDistArray = points.map((p) => {
|
|
88
|
+
const dx = p.X - this.X;
|
|
89
|
+
const dy = p.Y - this.Y;
|
|
90
|
+
const dist = Math.sqrt(dx * dx + dy * dy);
|
|
91
|
+
return dist;
|
|
92
|
+
});
|
|
93
|
+
const minDist = Math.min(...minDistArray);
|
|
94
|
+
const minIndex = minDistArray.findIndex((dist) => dist === minDist);
|
|
95
|
+
return minIndex;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import { calcSplineKoef_Akima, getSplineWert } from './Akima';
|
|
2
|
+
import { Point } from './Point';
|
|
3
|
+
|
|
4
|
+
export class SortedPoints {
|
|
5
|
+
private points: Point[] = [];
|
|
6
|
+
private universeCenter: Point;
|
|
7
|
+
|
|
8
|
+
constructor(points: Point[], universeCenter: Point) {
|
|
9
|
+
let xMin = Infinity;
|
|
10
|
+
let xMax = -Infinity;
|
|
11
|
+
let yMin = Infinity;
|
|
12
|
+
let yMax = -Infinity;
|
|
13
|
+
if (points.length >= 2) {
|
|
14
|
+
xMin = points.reduce((min, p) => Math.min(min, p.X), Infinity);
|
|
15
|
+
xMax = points.reduce((max, p) => Math.max(max, p.X), -Infinity);
|
|
16
|
+
yMin = points.reduce((min, p) => Math.min(min, p.Y), Infinity);
|
|
17
|
+
yMax = points.reduce((max, p) => Math.max(max, p.Y), -Infinity);
|
|
18
|
+
}
|
|
19
|
+
const center = new Point(
|
|
20
|
+
xMin + (xMax - xMin) / 2,
|
|
21
|
+
yMin + (yMax - yMin) / 2
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
this.points = points.sort((a: Point, b: Point) => {
|
|
25
|
+
return a.relAtan(center) - b.relAtan(center);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
this.universeCenter = universeCenter;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
get Center() {
|
|
32
|
+
let xMin = Infinity;
|
|
33
|
+
let xMax = -Infinity;
|
|
34
|
+
let yMin = Infinity;
|
|
35
|
+
let yMax = -Infinity;
|
|
36
|
+
if (this.points.length >= 2) {
|
|
37
|
+
xMin = this.points.reduce((min, p) => Math.min(min, p.X), Infinity);
|
|
38
|
+
xMax = this.points.reduce((max, p) => Math.max(max, p.X), -Infinity);
|
|
39
|
+
yMin = this.points.reduce((min, p) => Math.min(min, p.Y), Infinity);
|
|
40
|
+
yMax = this.points.reduce((max, p) => Math.max(max, p.Y), -Infinity);
|
|
41
|
+
}
|
|
42
|
+
const center = new Point(
|
|
43
|
+
xMin + (xMax - xMin) / 2,
|
|
44
|
+
yMin + (yMax - yMin) / 2
|
|
45
|
+
);
|
|
46
|
+
return center;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
get NrRadii(): number {
|
|
50
|
+
return 128;
|
|
51
|
+
// return (this.points.length - 1) * 8;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
get RadianKoeffs(): number[] {
|
|
55
|
+
return this.points.map((point) => {
|
|
56
|
+
return point.relAtan(this.Center);
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
get RadiusKoeffs(): number[] {
|
|
61
|
+
return this.points.map((point) => {
|
|
62
|
+
return point.Radius;
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
drawPoints(context: CanvasRenderingContext2D): void {
|
|
67
|
+
this.points.forEach((point, index) => {
|
|
68
|
+
point.draw(context, 'magenta', {
|
|
69
|
+
text: `${index}`,
|
|
70
|
+
offset: 10,
|
|
71
|
+
});
|
|
72
|
+
point.drawLine(
|
|
73
|
+
context,
|
|
74
|
+
new Point(this.Center.X, this.Center.Y, this.universeCenter)
|
|
75
|
+
);
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
drawCenter(context: CanvasRenderingContext2D): void {
|
|
80
|
+
if (this.points.length >= 2) {
|
|
81
|
+
const point1 = new Point(
|
|
82
|
+
this.Center.X - 50,
|
|
83
|
+
this.Center.Y,
|
|
84
|
+
this.universeCenter
|
|
85
|
+
);
|
|
86
|
+
point1.drawLine(
|
|
87
|
+
context,
|
|
88
|
+
new Point(this.Center.X + 50, this.Center.Y, this.universeCenter)
|
|
89
|
+
);
|
|
90
|
+
const point2 = new Point(
|
|
91
|
+
this.Center.X,
|
|
92
|
+
this.Center.Y - 50,
|
|
93
|
+
this.universeCenter
|
|
94
|
+
);
|
|
95
|
+
point2.drawLine(
|
|
96
|
+
context,
|
|
97
|
+
new Point(this.Center.X, this.Center.Y + 50, this.universeCenter)
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
drawBox(context: CanvasRenderingContext2D): void {
|
|
103
|
+
if (this.points.length >= 2) {
|
|
104
|
+
const xMin = this.points.reduce((min, p) => Math.min(min, p.X), Infinity);
|
|
105
|
+
const xMax = this.points.reduce(
|
|
106
|
+
(max, p) => Math.max(max, p.X),
|
|
107
|
+
-Infinity
|
|
108
|
+
);
|
|
109
|
+
const yMin = this.points.reduce((min, p) => Math.min(min, p.Y), Infinity);
|
|
110
|
+
const yMax = this.points.reduce(
|
|
111
|
+
(max, p) => Math.max(max, p.Y),
|
|
112
|
+
-Infinity
|
|
113
|
+
);
|
|
114
|
+
context.fillStyle = 'red';
|
|
115
|
+
const topLeft = new Point(xMin, yMin, this.universeCenter);
|
|
116
|
+
const bottomRight = new Point(xMax, yMax, this.universeCenter);
|
|
117
|
+
context.strokeStyle = 'blue';
|
|
118
|
+
context.lineWidth = 5;
|
|
119
|
+
const width = bottomRight.X - topLeft.X;
|
|
120
|
+
const height = topLeft.Y - bottomRight.Y;
|
|
121
|
+
context.strokeRect(
|
|
122
|
+
topLeft.X + topLeft.Origin.X,
|
|
123
|
+
topLeft.Origin.Y - topLeft.Y,
|
|
124
|
+
width,
|
|
125
|
+
height
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
drawPolygon(context: CanvasRenderingContext2D): void {
|
|
131
|
+
if (this.points.length >= 2) {
|
|
132
|
+
context.fillStyle = 'blue';
|
|
133
|
+
context.globalAlpha = 0.4; // Set transparency to 40%
|
|
134
|
+
context.beginPath();
|
|
135
|
+
context.moveTo(
|
|
136
|
+
this.points[0].Origin.X + this.points[0].X,
|
|
137
|
+
this.points[0].Origin.Y - this.points[0].Y
|
|
138
|
+
);
|
|
139
|
+
for (let i = 1; i < this.points.length; i++) {
|
|
140
|
+
context.lineTo(
|
|
141
|
+
this.points[i].Origin.X + this.points[i].X,
|
|
142
|
+
this.points[i].Origin.Y - this.points[i].Y
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
context.closePath();
|
|
146
|
+
context.fill();
|
|
147
|
+
context.globalAlpha = 1.0; // Reset transparency to default
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
private getSplineKoeff(
|
|
152
|
+
radian: number,
|
|
153
|
+
xKoef: number[],
|
|
154
|
+
yKoef: number[],
|
|
155
|
+
koef: number[][]
|
|
156
|
+
): { x: number; y: number } {
|
|
157
|
+
const xMin = getSplineWert(radian, xKoef, yKoef, koef);
|
|
158
|
+
const sin = Math.round(Math.sin(radian) * xMin * 1000) / 1000;
|
|
159
|
+
const cos = Math.round(Math.cos(radian) * xMin * 1000) / 1000;
|
|
160
|
+
return { x: cos, y: sin };
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
drawAkima(context: CanvasRenderingContext2D): void {
|
|
164
|
+
if (this.points.length >= 2) {
|
|
165
|
+
const radianKoeffs = this.RadianKoeffs;
|
|
166
|
+
const radiusKoeffs = this.RadiusKoeffs;
|
|
167
|
+
|
|
168
|
+
const koef = calcSplineKoef_Akima(radianKoeffs, radiusKoeffs);
|
|
169
|
+
|
|
170
|
+
const akimaKoords = [];
|
|
171
|
+
const centeredAkimaKoords = [];
|
|
172
|
+
const nrRadii = this.NrRadii;
|
|
173
|
+
const positions = [];
|
|
174
|
+
// for (let i = 0; i < this.points.length; i++) {
|
|
175
|
+
// const point = this.points[i];
|
|
176
|
+
// const pos = point.relAtan(this.Center);
|
|
177
|
+
// positions.push(pos);
|
|
178
|
+
// }
|
|
179
|
+
for (let i = 0; i < nrRadii; i++) {
|
|
180
|
+
const pos = ((Math.PI * 2) / nrRadii) * i;
|
|
181
|
+
positions.push(pos);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
for (let i = 0; i < positions.length; i++) {
|
|
185
|
+
const { x, y } = this.getSplineKoeff(
|
|
186
|
+
positions[i],
|
|
187
|
+
radianKoeffs,
|
|
188
|
+
radiusKoeffs,
|
|
189
|
+
koef
|
|
190
|
+
);
|
|
191
|
+
akimaKoords.push(new Point(x, y, this.universeCenter));
|
|
192
|
+
centeredAkimaKoords.push(
|
|
193
|
+
new Point(this.Center.X + x, this.Center.Y + y, this.universeCenter)
|
|
194
|
+
);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
// now draw the akima points
|
|
198
|
+
context.fillStyle = 'green';
|
|
199
|
+
context.globalAlpha = 0.4; // Set transparency to 40%
|
|
200
|
+
context.beginPath();
|
|
201
|
+
context.moveTo(
|
|
202
|
+
akimaKoords[0].Origin.X + akimaKoords[0].X,
|
|
203
|
+
akimaKoords[0].Origin.Y - akimaKoords[0].Y
|
|
204
|
+
);
|
|
205
|
+
|
|
206
|
+
const radianLength = centeredAkimaKoords.length - 1;
|
|
207
|
+
for (let i = 1; i <= radianLength; i++) {
|
|
208
|
+
const centeredPoint = akimaKoords[i];
|
|
209
|
+
context.lineTo(
|
|
210
|
+
akimaKoords[i].Origin.X + centeredPoint.X,
|
|
211
|
+
akimaKoords[i].Origin.Y - centeredPoint.Y
|
|
212
|
+
);
|
|
213
|
+
}
|
|
214
|
+
context.closePath();
|
|
215
|
+
context.fill();
|
|
216
|
+
context.globalAlpha = 1.0; // Reset transparency to default
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="35.93" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 228"><path fill="#00D8FF" d="M210.483 73.824a171.49 171.49 0 0 0-8.24-2.597c.465-1.9.893-3.777 1.273-5.621c6.238-30.281 2.16-54.676-11.769-62.708c-13.355-7.7-35.196.329-57.254 19.526a171.23 171.23 0 0 0-6.375 5.848a155.866 155.866 0 0 0-4.241-3.917C100.759 3.829 77.587-4.822 63.673 3.233C50.33 10.957 46.379 33.89 51.995 62.588a170.974 170.974 0 0 0 1.892 8.48c-3.28.932-6.445 1.924-9.474 2.98C17.309 83.498 0 98.307 0 113.668c0 15.865 18.582 31.778 46.812 41.427a145.52 145.52 0 0 0 6.921 2.165a167.467 167.467 0 0 0-2.01 9.138c-5.354 28.2-1.173 50.591 12.134 58.266c13.744 7.926 36.812-.22 59.273-19.855a145.567 145.567 0 0 0 5.342-4.923a168.064 168.064 0 0 0 6.92 6.314c21.758 18.722 43.246 26.282 56.54 18.586c13.731-7.949 18.194-32.003 12.4-61.268a145.016 145.016 0 0 0-1.535-6.842c1.62-.48 3.21-.974 4.76-1.488c29.348-9.723 48.443-25.443 48.443-41.52c0-15.417-17.868-30.326-45.517-39.844Zm-6.365 70.984c-1.4.463-2.836.91-4.3 1.345c-3.24-10.257-7.612-21.163-12.963-32.432c5.106-11 9.31-21.767 12.459-31.957c2.619.758 5.16 1.557 7.61 2.4c23.69 8.156 38.14 20.213 38.14 29.504c0 9.896-15.606 22.743-40.946 31.14Zm-10.514 20.834c2.562 12.94 2.927 24.64 1.23 33.787c-1.524 8.219-4.59 13.698-8.382 15.893c-8.067 4.67-25.32-1.4-43.927-17.412a156.726 156.726 0 0 1-6.437-5.87c7.214-7.889 14.423-17.06 21.459-27.246c12.376-1.098 24.068-2.894 34.671-5.345a134.17 134.17 0 0 1 1.386 6.193ZM87.276 214.515c-7.882 2.783-14.16 2.863-17.955.675c-8.075-4.657-11.432-22.636-6.853-46.752a156.923 156.923 0 0 1 1.869-8.499c10.486 2.32 22.093 3.988 34.498 4.994c7.084 9.967 14.501 19.128 21.976 27.15a134.668 134.668 0 0 1-4.877 4.492c-9.933 8.682-19.886 14.842-28.658 17.94ZM50.35 144.747c-12.483-4.267-22.792-9.812-29.858-15.863c-6.35-5.437-9.555-10.836-9.555-15.216c0-9.322 13.897-21.212 37.076-29.293c2.813-.98 5.757-1.905 8.812-2.773c3.204 10.42 7.406 21.315 12.477 32.332c-5.137 11.18-9.399 22.249-12.634 32.792a134.718 134.718 0 0 1-6.318-1.979Zm12.378-84.26c-4.811-24.587-1.616-43.134 6.425-47.789c8.564-4.958 27.502 2.111 47.463 19.835a144.318 144.318 0 0 1 3.841 3.545c-7.438 7.987-14.787 17.08-21.808 26.988c-12.04 1.116-23.565 2.908-34.161 5.309a160.342 160.342 0 0 1-1.76-7.887Zm110.427 27.268a347.8 347.8 0 0 0-7.785-12.803c8.168 1.033 15.994 2.404 23.343 4.08c-2.206 7.072-4.956 14.465-8.193 22.045a381.151 381.151 0 0 0-7.365-13.322Zm-45.032-43.861c5.044 5.465 10.096 11.566 15.065 18.186a322.04 322.04 0 0 0-30.257-.006c4.974-6.559 10.069-12.652 15.192-18.18ZM82.802 87.83a323.167 323.167 0 0 0-7.227 13.238c-3.184-7.553-5.909-14.98-8.134-22.152c7.304-1.634 15.093-2.97 23.209-3.984a321.524 321.524 0 0 0-7.848 12.897Zm8.081 65.352c-8.385-.936-16.291-2.203-23.593-3.793c2.26-7.3 5.045-14.885 8.298-22.6a321.187 321.187 0 0 0 7.257 13.246c2.594 4.48 5.28 8.868 8.038 13.147Zm37.542 31.03c-5.184-5.592-10.354-11.779-15.403-18.433c4.902.192 9.899.29 14.978.29c5.218 0 10.376-.117 15.453-.343c-4.985 6.774-10.018 12.97-15.028 18.486Zm52.198-57.817c3.422 7.8 6.306 15.345 8.596 22.52c-7.422 1.694-15.436 3.058-23.88 4.071a382.417 382.417 0 0 0 7.859-13.026a347.403 347.403 0 0 0 7.425-13.565Zm-16.898 8.101a358.557 358.557 0 0 1-12.281 19.815a329.4 329.4 0 0 1-23.444.823c-7.967 0-15.716-.248-23.178-.732a310.202 310.202 0 0 1-12.513-19.846h.001a307.41 307.41 0 0 1-10.923-20.627a310.278 310.278 0 0 1 10.89-20.637l-.001.001a307.318 307.318 0 0 1 12.413-19.761c7.613-.576 15.42-.876 23.31-.876H128c7.926 0 15.743.303 23.354.883a329.357 329.357 0 0 1 12.335 19.695a358.489 358.489 0 0 1 11.036 20.54a329.472 329.472 0 0 1-11 20.722Zm22.56-122.124c8.572 4.944 11.906 24.881 6.52 51.026c-.344 1.668-.73 3.367-1.15 5.09c-10.622-2.452-22.155-4.275-34.23-5.408c-7.034-10.017-14.323-19.124-21.64-27.008a160.789 160.789 0 0 1 5.888-5.4c18.9-16.447 36.564-22.941 44.612-18.3ZM128 90.808c12.625 0 22.86 10.235 22.86 22.86s-10.235 22.86-22.86 22.86s-22.86-10.235-22.86-22.86s10.235-22.86 22.86-22.86Z"></path></svg>
|
package/src/index.css
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
:root {
|
|
2
|
+
font-family: system-ui, Avenir, Helvetica, Arial, sans-serif;
|
|
3
|
+
line-height: 1.5;
|
|
4
|
+
font-weight: 400;
|
|
5
|
+
|
|
6
|
+
color-scheme: light dark;
|
|
7
|
+
color: rgba(255, 255, 255, 0.87);
|
|
8
|
+
background-color: #242424;
|
|
9
|
+
|
|
10
|
+
font-synthesis: none;
|
|
11
|
+
text-rendering: optimizeLegibility;
|
|
12
|
+
-webkit-font-smoothing: antialiased;
|
|
13
|
+
-moz-osx-font-smoothing: grayscale;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
a {
|
|
17
|
+
font-weight: 500;
|
|
18
|
+
color: #646cff;
|
|
19
|
+
text-decoration: inherit;
|
|
20
|
+
}
|
|
21
|
+
a:hover {
|
|
22
|
+
color: #535bf2;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
body {
|
|
26
|
+
margin: 0;
|
|
27
|
+
display: flex;
|
|
28
|
+
place-items: center;
|
|
29
|
+
min-width: 320px;
|
|
30
|
+
min-height: 100vh;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
h1 {
|
|
34
|
+
font-size: 3.2em;
|
|
35
|
+
line-height: 1.1;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
button {
|
|
39
|
+
border-radius: 8px;
|
|
40
|
+
border: 1px solid transparent;
|
|
41
|
+
padding: 0.6em 1.2em;
|
|
42
|
+
font-size: 1em;
|
|
43
|
+
font-weight: 500;
|
|
44
|
+
font-family: inherit;
|
|
45
|
+
background-color: #1a1a1a;
|
|
46
|
+
cursor: pointer;
|
|
47
|
+
transition: border-color 0.25s;
|
|
48
|
+
}
|
|
49
|
+
button:hover {
|
|
50
|
+
border-color: #646cff;
|
|
51
|
+
}
|
|
52
|
+
button:focus,
|
|
53
|
+
button:focus-visible {
|
|
54
|
+
outline: 4px auto -webkit-focus-ring-color;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
@media (prefers-color-scheme: light) {
|
|
58
|
+
:root {
|
|
59
|
+
color: #213547;
|
|
60
|
+
background-color: #ffffff;
|
|
61
|
+
}
|
|
62
|
+
a:hover {
|
|
63
|
+
color: #747bff;
|
|
64
|
+
}
|
|
65
|
+
button {
|
|
66
|
+
background-color: #f9f9f9;
|
|
67
|
+
}
|
|
68
|
+
}
|
package/src/main.tsx
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/// <reference types="vite/client" />
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
|
|
4
|
+
"target": "ES2020",
|
|
5
|
+
"useDefineForClassFields": true,
|
|
6
|
+
"lib": ["ES2020", "DOM", "DOM.Iterable"],
|
|
7
|
+
"module": "ESNext",
|
|
8
|
+
"skipLibCheck": true,
|
|
9
|
+
|
|
10
|
+
/* Bundler mode */
|
|
11
|
+
"moduleResolution": "bundler",
|
|
12
|
+
"allowImportingTsExtensions": true,
|
|
13
|
+
"isolatedModules": true,
|
|
14
|
+
"moduleDetection": "force",
|
|
15
|
+
"noEmit": true,
|
|
16
|
+
"jsx": "react-jsx",
|
|
17
|
+
|
|
18
|
+
/* Linting */
|
|
19
|
+
"strict": true,
|
|
20
|
+
"noUnusedLocals": true,
|
|
21
|
+
"noUnusedParameters": true,
|
|
22
|
+
"noFallthroughCasesInSwitch": true,
|
|
23
|
+
"noUncheckedSideEffectImports": true
|
|
24
|
+
},
|
|
25
|
+
"include": ["src"]
|
|
26
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
|
|
4
|
+
"target": "ES2022",
|
|
5
|
+
"lib": ["ES2023"],
|
|
6
|
+
"module": "ESNext",
|
|
7
|
+
"skipLibCheck": true,
|
|
8
|
+
|
|
9
|
+
/* Bundler mode */
|
|
10
|
+
"moduleResolution": "bundler",
|
|
11
|
+
"allowImportingTsExtensions": true,
|
|
12
|
+
"isolatedModules": true,
|
|
13
|
+
"moduleDetection": "force",
|
|
14
|
+
"noEmit": true,
|
|
15
|
+
|
|
16
|
+
/* Linting */
|
|
17
|
+
"strict": true,
|
|
18
|
+
"noUnusedLocals": true,
|
|
19
|
+
"noUnusedParameters": true,
|
|
20
|
+
"noFallthroughCasesInSwitch": true,
|
|
21
|
+
"noUncheckedSideEffectImports": true
|
|
22
|
+
},
|
|
23
|
+
"include": ["vite.config.ts"]
|
|
24
|
+
}
|