* Die Messung, die AC5 verlangt: JEDER Knoten in den Bildraum gerechnet. * * Sie steht in der Szene, weil nur hier die Kamera steht, und sie ist eine * Funktion und kein Wert: fuenftausend Punkte bei jedem Bild zu projizieren * waere eine Messung, die das Gemessene aendert. Gerechnet wird erst,
({ nodes }: { nodes: GraphNode[] })
| 747 | * jemand fragt, und dann mit genau der Kamera, die gerade zeichnet. |
| 748 | */ |
| 749 | function FitProbe({ nodes }: { nodes: GraphNode[] }): null { |
| 750 | const camera = useThree((state) => state.camera); |
| 751 | const size = useThree((state) => state.size); |
| 752 | |
| 753 | useEffect(() => { |
| 754 | const measure = (): FitMeasurement => { |
| 755 | camera.updateMatrixWorld(); |
| 756 | const point = new THREE.Vector3(); |
| 757 | const view = new THREE.Vector3(); |
| 758 | const direction = new THREE.Vector3(); |
| 759 | camera.getWorldDirection(direction); |
| 760 | let inside = 0; |
| 761 | let outside = 0; |
| 762 | let behind = 0; |
| 763 | let marginPx = Number.POSITIVE_INFINITY; |
| 764 | let left = Number.POSITIVE_INFINITY; |
| 765 | let right = Number.NEGATIVE_INFINITY; |
| 766 | let top = Number.POSITIVE_INFINITY; |
| 767 | let bottom = Number.NEGATIVE_INFINITY; |
| 768 | const seen: { name: string; x: number; y: number; margin: number }[] = []; |
| 769 | for (const node of nodes) { |
| 770 | point.set(node.x, node.y, node.z); |
| 771 | view.copy(point).applyMatrix4(camera.matrixWorldInverse); |
| 772 | point.project(camera); |
| 773 | const x = ((point.x + 1) / 2) * size.width; |
| 774 | const y = ((1 - point.y) / 2) * size.height; |
| 775 | // z im Blickraum ist vor der Kamera negativ. Ein Punkt dahinter |
| 776 | // hat auf dem Schirm keine Lage, die etwas bedeutet. |
| 777 | if (view.z >= 0) { |
| 778 | behind += 1; |
| 779 | outside += 1; |
| 780 | marginPx = Math.min(marginPx, -1); |
| 781 | seen.push({ name: node.qualified_name ?? node.name, x, y, margin: -1 }); |
| 782 | continue; |
| 783 | } |
| 784 | const margin = Math.min(x, size.width - x, y, size.height - y); |
| 785 | marginPx = Math.min(marginPx, margin); |
| 786 | left = Math.min(left, x); |
| 787 | right = Math.max(right, x); |
| 788 | top = Math.min(top, y); |
| 789 | bottom = Math.max(bottom, y); |
| 790 | if (margin >= 0) { |
| 791 | inside += 1; |
| 792 | } else { |
| 793 | outside += 1; |
| 794 | } |
| 795 | seen.push({ name: node.qualified_name ?? node.name, x, y, margin }); |
| 796 | } |
| 797 | seen.sort((a, b) => a.margin - b.margin); |
| 798 | const visibleWidth = right - left; |
| 799 | const visibleHeight = bottom - top; |
| 800 | return { |
| 801 | nodes: nodes.length, |
| 802 | inside, |
| 803 | outside, |
| 804 | behind, |
| 805 | marginPx: Number.isFinite(marginPx) ? Number(marginPx.toFixed(2)) : -1, |
| 806 | box: { |
nothing calls this directly
no outgoing calls
no test coverage detected