@graphty/layout
Version:
graph layout algorithms based on networkx
30 lines • 1.16 kB
JavaScript
/**
* Main planarity checking function
*/
import { isK5, isK33 } from './special-graphs';
import { lrPlanarityTest } from './lr-test';
import { createTriangulationEmbedding } from './embedding';
/**
* Check if graph is planar using a simplified version of Boyer-Myrvold algorithm.
* Returns planarity and embedding information.
*
* @param G - Graph
* @param nodes - List of nodes
* @param edges - List of edges
* @returns Object containing isPlanar flag and embedding
*/
export function checkPlanarity(G, nodes, edges, seed = null) {
// For small graphs (n <= 4), all are planar
if (nodes.length <= 4) {
return { isPlanar: true, embedding: createTriangulationEmbedding(nodes, edges, seed) };
}
// For K5 (complete graph with 5 nodes) and K3,3 (complete bipartite with 3,3 nodes)
// these are not planar by Kuratowski's theorem
if (isK5(nodes, edges) || isK33(nodes, edges)) {
return { isPlanar: false, embedding: null };
}
// For other graphs, use LR algorithm (Left-Right Planarity Test)
const result = lrPlanarityTest(nodes, edges, seed);
return result;
}
//# sourceMappingURL=check.js.map