MCPcopy Create free account
hub / github.com/DFin/Neural-Network-Visualisation / trySelectNeuron

Method trySelectNeuron

assets/main.js:1973–2003  ·  view source on GitHub ↗
(event)

Source from the content-addressed store, hash-verified

1971 }
1972
1973 trySelectNeuron(event) {
1974 if (!this.layerMeshes.length || !this.camera) return;
1975 const rect = this.renderer.domElement.getBoundingClientRect();
1976 if (rect.width === 0 || rect.height === 0) return;
1977 const x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
1978 const y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
1979 this.pointerVector.set(x, y);
1980 this.raycaster.setFromCamera(this.pointerVector, this.camera);
1981
1982 const intersections = [];
1983 this.layerMeshes.forEach((layer, layerIndex) => {
1984 if (!layer?.mesh) return;
1985 const hits = this.raycaster.intersectObject(layer.mesh, false);
1986 hits.forEach((hit) => {
1987 if (Number.isInteger(hit.instanceId)) {
1988 intersections.push({
1989 distance: hit.distance,
1990 layerIndex,
1991 neuronIndex: hit.instanceId,
1992 });
1993 }
1994 });
1995 });
1996 intersections.sort((a, b) => a.distance - b.distance);
1997 const hit = intersections[0];
1998 if (!hit) {
1999 this.clearSelection();
2000 return;
2001 }
2002 this.setSelectedNeuron(hit.layerIndex, hit.neuronIndex);
2003 }
2004
2005 setSelectedNeuron(layerIndex, neuronIndex) {
2006 if (!Number.isInteger(layerIndex) || !Number.isInteger(neuronIndex)) return;

Callers 1

handleScenePointerUpMethod · 0.95

Calls 2

clearSelectionMethod · 0.95
setSelectedNeuronMethod · 0.95

Tested by

no test coverage detected