UNPKG

@woosh/meep-engine

Version:

Pure JavaScript game engine. Fully featured and production ready.

23 lines (19 loc) 1.06 kB
import { BinaryDataType } from "../binary/type/BinaryDataType.js"; import { SquareMatrix } from "../math/matrix/SquareMatrix.js"; import { graph_compute_adjacency_matrix } from "./graph_compute_adjacency_matrix.js"; import { graph_compute_degree_matrix } from "./graph_compute_degree_matrix.js"; /** * Computes the Laplacian matrix of a graph. * Does NOT clear the matrix before writing. * @template T Type of graph nodes. * @param {Graph<T>} graph Input graph. * @param {SquareMatrix} result Output: Laplacian matrix (modified in-place). * @param {Map<T,number>} node_indices Map from graph nodes to matrix indices. */ export function graph_compute_laplacian_matrix(graph, result, node_indices) { const degree = new SquareMatrix(result.size, BinaryDataType.Uint8); const adjacency = new SquareMatrix(result.size, BinaryDataType.Uint8); graph_compute_degree_matrix(graph, degree, node_indices); graph_compute_adjacency_matrix(graph, adjacency, node_indices); result.subtractMatrices(degree, adjacency); }