Graph | Matterport SDK
Usage of the SDK constitutes your agreement with the Matterport SDK Agreement. Email developers@matterport.com with any questions.

Index

Types

AStarResult

AStarResult: object

The result of doing an A* search.

Type declaration

  • cost: number

    The total cost of tranversing the path.

  • path: Array<Graph.Vertex<T>>

    On success, contains the path of vertices.

  • status: Graph.AStarStatus

    Whether the search was successful, timed out, or if there was no path found.

Edge

Edge: object

A weighted, directed connection between two vertices.

Type declaration

  • Readonly dst: Graph.Vertex<T>

    The vertex at the destination of this edge.

  • Readonly src: Graph.Vertex<T>

    The vertex at the source of this edge.

  • Readonly weight: number

    The weight associated with this edge.

EdgeDescriptor

EdgeDescriptor: object

A descriptor for a graph edge. Used when adding edges to a graph.

Type declaration

  • dst: Graph.Vertex<T>

    The destination vertex.

  • src: Graph.Vertex<T>

    The source vertex.

  • Optional weight?: undefined | number

    The weight of the edge.

Vertex

Vertex: object

A node in the graph.

Type declaration

  • Readonly data: T

    User data associated with the vertex.

  • Readonly edgesIn: IterableIterator<Graph.Edge<T>>

    An iterable of all edges that have this vertex as its destination endpoint.

    const vertex = graph.vertex('a');
    for (const edgeIn of vertex.edgesIn) {
      console.log(`vertex "${edgeIn.dst.id}" has an edge coming in from a vertex "${edgeIn.src.id}"`);
    }
    
  • Readonly edgesInCount: number

    The nubmer of edges that have this vertex as its destination endpoint.

    const vertex = graph.vertex('a');
    console.log(`vertex "${vertex.id}" has ${vertex.edgesInCount} edges out");
    
  • Readonly edgesOut: IterableIterator<Graph.Edge<T>>

    An iterable of all edges that have this vertex as its source endpoint.

    const vertex = graph.vertex('a');
    for (const edgeOut of vertex.edgesOut) {
      console.log(`vertex "${edgeOut.src.id}" has an edge going to a vertex "${edgeOut.dst.id}"`);
    }
    
  • Readonly edgesOutCount: number

    The nubmer of edges that have this vertex as its source endpoint.

    const vertex = graph.vertex('a');
    console.log(`vertex "${vertex.id}" has ${vertex.edgeOutCount} edges out");
    
  • Readonly id: string

    The vertex's id.

  • Readonly neighbors: IterableIterator<Graph.Vertex<T>>

    An iterable of all vertices that can be traversed to from this vertex.

    const vertex = graph.vertex('a');
    for (const neighbor of vertex.neighbors) {
      console.log(`vertex "${vertex.id}" shares an edge with "${neighbor.id}");
    }
    
  • findEdgeIn: function
    • findEdgeIn(predicate: function, thisArg?: any): Graph.Edge<T> | undefined
    • Find an edge into this vertex.

      const vertex = graph.vertex('a');
      // find an edge into 'a' and out from 'b'
      vertex.findEdgeIn(edge => edge.src.id === 'b');
      

      Parameters

      • predicate: function

        The callback to run against each inward edge until one is found (by returning true.)

      • Optional thisArg: any

        The "this" argument to use in predicate

      Returns Graph.Edge<T> | undefined

  • findEdgeOut: function
    • findEdgeOut(predicate: function, thisArg?: any): Graph.Edge<T> | undefined
    • Find an edge out of this vertex.

      const vertex = graph.vertex('a');
      // find an edge out from 'a' and into 'b'
      vertex.findEdgeIn(edge => edge.src.id === 'b');
      

      Parameters

      • predicate: function

        The callback to run against each outward edge until one is found (by returning true.)

      • Optional thisArg: any

        The "this" argument to use in predicate

      Returns Graph.Edge<T> | undefined

VertexDescriptor

VertexDescriptor: object

A descriptor for a graph vertex. Used when adding vertices to a graph.

Type declaration

  • data: T

    Any user data to be associated with this vertex

  • id: string

    The id that can be used to lookup this vertex in the graph

VertexIdDescriptor

VertexIdDescriptor: object

A descriptor for a graph vertex when no extra data will be associated with each vertex. Used when adding vertices to a graph.

Type declaration

  • id: string

    The id that can be used to lookup this vertex in the graph

Methods

cloneGraph

  • Introduced 25.6.1

    Clone a graph, creating new vertices and edges. Doesnt clone any of the vertices' .data.

    const graph = mpSdk.Graph.createDirectedGraph();
    // ... setup graph vertices and edges
    const clone = sdk.Graph.cloneGraph(graph);
    

    Type parameters

    • T

    Parameters

    Returns Graph.IDirectedGraph<T>

createAStarRunner

  • embed
    bundle

    Introduced 3.1.55.2-34-ga9934ccd93

    Create a "runner" for the A* algorithm around a graph, and start and end vertices.

    The runner encapsulates the details of the graph and search, caches the results of A*, and provides a way to subscribe to potential changes in the path signifying that the results of [[Graph.AStarRunner.exec]] may have changed.

    const graph = mpSdk.Graph.createDirectedGraph();
    // ... setup graph vertices and edges
    const start = graph.vertex('start');
    const end = graph.vertex('end');
    const aStarRunner = mpSdk.Graph.createAStarRunner(graph, start, end);
    const result = aStarRunner.exec();
    

    Type parameters

    • T

    Parameters

    Returns Graph.IAStarRunner<T>

    A runner for A* that can execute the search or be subscribed to.

createDirectedGraph

  • embed
    bundle

    Introduced 3.1.55.2-34-ga9934ccd93

    Create an empty graph data structure.

    const graph = mpSdk.Graph.createDirectedGraph();
    

    Type parameters

    • T

      The type of any user data associated with each vertex in the graph.

    Parameters

    • Optional onDispose: undefined | function

      An optional callback to be called when IDirectedGraph.dispose is called

    Returns Graph.IDirectedGraph<T>

findCycle

  • embed
    bundle

    Introduced 25.6.1

    Find a cycle in a graph.

    const graph = mpSdk.Graph.createDirectedGraph();
    // assuming graph has edges A -> B, B -> C, C -> D, D -> B
    // should find the cycle [B, C, D]
    const cycle = sdk.Graph.findCyle(graph);
    

    Type parameters

    • T

    Parameters

    Returns Iterable<Graph.Vertex<T>>

    an Iterable of vertices that represent a found cycle or [] if none were found

findCycles

  • embed
    bundle

    Introduced 25.6.1

    Find multiple cycles in a graph. Note: If a vertex is in multiple cycles, only one will be reported.

    const graph = mpSdk.Graph.createDirectedGraph();
    // assuming graph has edges A -> B, B -> C, C -> A, D -> E, E -> D
    // should find cycles [A, B, C], and [D, E]
    const cycle = sdk.Graph.findCyle(graph);
    

    Type parameters

    • T

    Parameters

    Returns Iterable<Iterable<Graph.Vertex<T>>>

    an iterbale of iterables (like an array of arrays) of vertices