### LineRep: Get Begin Point Source: https://github.com/aksem/libavoid-js/blob/master/api_docs_build/glue.js.html Retrieves the starting point of a LineRep object. Returns a Point object. ```javascript LineRep.prototype['get_begin'] = LineRep.prototype.get_begin = function() { var self = this.ptr; return wrapPointer(_emscripten_bind_LineRep_get_begin_0(self), Point); }; ``` -------------------------------- ### ShapeConnectionPin Class Setup Source: https://github.com/aksem/libavoid-js/blob/master/api_docs_build/glue.js.html Sets up the prototype, constructor, and cache for the ShapeConnectionPin class, making it available on the Module object. ```javascript ShapeConnectionPin.prototype = Object.create(WrapperObject.prototype); ShapeConnectionPin.prototype.constructor = ShapeConnectionPin; ShapeConnectionPin.prototype.__class__ = ShapeConnectionPin; ShapeConnectionPin.__cache__ = {}; Module['ShapeConnectionPin'] = ShapeConnectionPin; ``` -------------------------------- ### Initialize MinimumTerminalSpanningTree Source: https://github.com/aksem/libavoid-js/blob/master/api_docs_build/MinimumTerminalSpanningTree.html Instantiates a new MinimumTerminalSpanningTree object. No specific setup or imports are mentioned for this constructor. ```javascript new MinimumTerminalSpanningTree() ``` -------------------------------- ### Initialize Libavoid JS Library Source: https://context7.com/aksem/libavoid-js/llms.txt Loads the WebAssembly module and gets an instance of the Avoid router. Essential before creating any routing objects. For Node.js, a custom WASM path can be specified. ```javascript import { AvoidLib } from 'libavoid-js'; async function initializeLibrary() { // Load the WebAssembly module await AvoidLib.load(); // Get the Avoid instance for creating routing objects const Avoid = AvoidLib.getInstance(); // Now you can use the library const router = new Avoid.Router(Avoid.PolyLineRouting); console.log('Library initialized successfully'); return Avoid; } // For Node.js with custom wasm path async function initializeWithCustomPath() { await AvoidLib.load('/path/to/libavoid.wasm'); return AvoidLib.getInstance(); } ``` -------------------------------- ### Point Class Source: https://github.com/aksem/libavoid-js/blob/master/api_docs_build/glue.js.html Represents a point with methods for getting and setting its 'vn' property and a destructor. ```APIDOC ## Point Class ### Description Represents a point in the system. Provides methods to access and modify its properties. ### Methods #### get_vn Gets the 'vn' property of the point. #### set_vn Sets the 'vn' property of the point. #### __destroy__ Destroys the Point object. ### Endpoint N/A (Class definition) ### Parameters N/A for class definition. Methods have their own parameters. ### Request Body N/A ### Response N/A for class definition. Methods have their own return types. ### Request Example N/A ### Response Example N/A ``` -------------------------------- ### LineRep: Set Begin Point Source: https://github.com/aksem/libavoid-js/blob/master/api_docs_build/glue.js.html Sets the starting point of a LineRep object. The point should be a valid object or pointer. ```javascript LineRep.prototype['set_begin'] = LineRep.prototype.set_begin = function(arg0) { var self = this.ptr; if (arg0 && typeof arg0 === 'object') arg0 = arg0.ptr; _emscripten_bind_LineRep_set_begin_1(self, arg0); }; ``` -------------------------------- ### Perform A* Search Source: https://github.com/aksem/libavoid-js/blob/master/api_docs_build/glue.js.html Executes the A* search algorithm. Requires a line reference, source, target, and starting point. ```javascript AStarPath.prototype['search'] = AStarPath.prototype.search = function(lineRef, src, tar, start) { var self = this.ptr; if (lineRef && typeof lineRef === 'object') lineRef = lineRef.ptr; if (src && typeof src === 'object') src = src.ptr; if (tar && typeof tar === 'object') tar = tar.ptr; if (start && typeof start === 'object') start = start.ptr; _emscripten_bind_AStarPath_search_4(self, lineRef, src, tar, start); }; ``` -------------------------------- ### Obstacle Class Definition and Methods Source: https://github.com/aksem/libavoid-js/blob/master/api_docs_build/glue.js.html Defines the Obstacle class and its prototype methods for interacting with Emscripten-bound C++ functions. Includes methods for getting ID, polygon, router, and position. ```javascript Obstacle.prototype = Object.create(WrapperObject.prototype); Obstacle.prototype.constructor = Obstacle; Obstacle.prototype.__class__ = Obstacle; Obstacle.__cache__ = {}; Module['Obstacle'] = Obstacle; /** * * @returns UnsignedLong */ Obstacle.prototype['id'] = Obstacle.prototype.id = function() { var self = this.ptr; return _emscripten_bind_Obstacle_id_0(self); }; ``` ```javascript /** * * @returns Polygon (Wrapper) */ Obstacle.prototype['polygon'] = Obstacle.prototype.polygon = function() { var self = this.ptr; return wrapPointer(_emscripten_bind_Obstacle_polygon_0(self), Polygon); }; ``` ```javascript /** * * @returns Router (Wrapper) */ Obstacle.prototype['router'] = Obstacle.prototype.router = function() { var self = this.ptr; return wrapPointer(_emscripten_bind_Obstacle_router_0(self), Router); }; ``` ```javascript /** * * @returns Point (Wrapper) */ Obstacle.prototype['position'] = Obstacle.prototype.position = function() { var self = this.ptr; return wrapPointer(_emscripten_bind_Obstacle_position_0(self), Point); }; ``` ```javascript Obstacle.prototype['__destroy__'] = Obstacle.prototype.__destroy__ = function() { var self = this.ptr; _emscripten_bind_Obstacle___destroy___0(self); }; ``` -------------------------------- ### Build Diagram with Obstacle Avoidance in JavaScript Source: https://context7.com/aksem/libavoid-js/llms.txt Initializes the library, creates a router with specific routing parameters, defines node shapes, and establishes connections between them. It then processes the routing and extracts the paths for rendering. Ensure the library is loaded before use. ```javascript import { AvoidLib } from 'libavoid-js'; async function buildDiagram() { // Initialize library await AvoidLib.load(); const Avoid = AvoidLib.getInstance(); // Create and configure router const router = new Avoid.Router( Avoid.PolyLineRouting | Avoid.OrthogonalRouting ); router.setRoutingParameter(Avoid.crossingPenalty, 200); router.setRoutingParameter(Avoid.idealNudgingDistance, 25); // Create node shapes const nodes = []; const nodePositions = [ { x: 100, y: 100, width: 80, height: 40 }, { x: 300, y: 100, width: 80, height: 40 }, { x: 200, y: 250, width: 80, height: 40 } ]; nodePositions.forEach((node, i) => { const poly = new Avoid.Polygon(4); poly.set_ps(0, new Avoid.Point(node.x, node.y)); poly.set_ps(1, new Avoid.Point(node.x + node.width, node.y)); poly.set_ps(2, new Avoid.Point(node.x + node.width, node.y + node.height)); poly.set_ps(3, new Avoid.Point(node.x, node.y + node.height)); const shape = new Avoid.ShapeRef(router, poly, i + 1); nodes.push(shape); }); // Create connections between nodes const connections = [ { from: 0, to: 1 }, { from: 0, to: 2 }, { from: 1, to: 2 } ]; const connectors = connections.map(conn => { const fromPos = nodePositions[conn.from]; const toPos = nodePositions[conn.to]; const srcPt = new Avoid.Point( fromPos.x + fromPos.width / 2, fromPos.y + fromPos.height ); const dstPt = new Avoid.Point( toPos.x + toPos.width / 2, toPos.y ); const connector = new Avoid.ConnRef(router, new Avoid.ConnEnd(srcPt), new Avoid.ConnEnd(dstPt) ); connector.setRoutingType(2); // Orthogonal return connector; }); // Process all routing router.processTransaction(); // Extract route paths for rendering const paths = connectors.map((conn, i) => { const route = conn.displayRoute(); const points = []; for (let j = 0; j < route.size(); j++) { const pt = route.get_ps(j); points.push({ x: pt.x, y: pt.y }); } return { connectionIndex: i, points }; }); console.log('Diagram routes:', JSON.stringify(paths, null, 2)); // Cleanup Avoid.destroy(router); return paths; } buildDiagram().catch(console.error); ``` -------------------------------- ### Get Size Source: https://github.com/aksem/libavoid-js/blob/master/api_docs_build/PolygonInterface.html Retrieves the size of the object. ```APIDOC ## size() ### Description Retrieves the size of the object. ### Method GET ### Endpoint /aksem/libavoid-js/size ### Returns #### Success Response (200) - **number** (number) - The size of the object. ### Response Example { "example": "100" } ``` -------------------------------- ### Create and Manage Junction References Source: https://context7.com/aksem/libavoid-js/llms.txt Demonstrates creating junction points, connecting multiple connectors to them, and managing junction properties like position and fixed status. Ensure libavoid is loaded before use. ```javascript async function junctionExample() { await AvoidLib.load(); const Avoid = AvoidLib.getInstance(); const router = new Avoid.Router(Avoid.PolyLineRouting); // Create a junction point const junctionPoint = new Avoid.Point(200, 200); const junction = new Avoid.JunctionRef(router, junctionPoint); // Create connectors that connect to the junction const conn1 = new Avoid.ConnRef(router, new Avoid.ConnEnd(new Avoid.Point(50, 100)), Avoid.ConnEnd.createConnEndFromJunctionRef(junction, 0) ); const conn2 = new Avoid.ConnRef(router, Avoid.ConnEnd.createConnEndFromJunctionRef(junction, 0), new Avoid.ConnEnd(new Avoid.Point(350, 100)) ); const conn3 = new Avoid.ConnRef(router, Avoid.ConnEnd.createConnEndFromJunctionRef(junction, 0), new Avoid.ConnEnd(new Avoid.Point(200, 350)) ); router.processTransaction(); // Get junction properties const pos = junction.position(); console.log(`Junction position: (${pos.x}, ${pos.y})`); // Fix junction position junction.setPositionFixed(true); console.log(`Position fixed: ${junction.positionFixed()}`); // Get recommended position for optimal routing const recommended = junction.recommendedPosition(); console.log(`Recommended position: (${recommended.x}, ${recommended.y})`); // Move junction to new position router.moveJunction(junction, new Avoid.Point(220, 220)); router.processTransaction(); return { router, junction, conn1, conn2, conn3 }; } ``` -------------------------------- ### Get ID Source: https://github.com/aksem/libavoid-js/blob/master/api_docs_build/PolygonInterface.html Retrieves the ID of the object. ```APIDOC ## id() ### Description Retrieves the ID of the object. ### Method GET ### Endpoint /aksem/libavoid-js/id ### Returns #### Success Response (200) - **Long** (Long) - The ID of the object. ### Response Example { "example": "1234567890" } ``` -------------------------------- ### Initialize ActionInfo (2 arguments) Source: https://github.com/aksem/libavoid-js/blob/master/api_docs_build/glue.js.html Constructor for ActionInfo with two arguments (t, s). ```javascript function ActionInfo(t, s, p, fm) { if (t && typeof t === 'object') t = t.ptr; if (s && typeof s === 'object') s = s.ptr; if (p && typeof p === 'object') p = p.ptr; if (fm && typeof fm === 'object') fm = fm.ptr; if (p === undefined) { this.ptr = _emscripten_bind_ActionInfo_ActionInfo_2(t, s); getCache(ActionInfo)[this.ptr] = this;return } ``` -------------------------------- ### ActionInfo.prototype.get_type Source: https://github.com/aksem/libavoid-js/blob/master/api_docs_build/glue.js.html Gets the type of the ActionInfo. This is a getter method. ```javascript ActionInfo.prototype['get_type'] = ActionInfo.prototype.get_type = function() { var self = this.ptr; return _emscripten_bind_ActionInfo_get_type_0(self); }; ``` -------------------------------- ### Initialize AStarPath Source: https://github.com/aksem/libavoid-js/blob/master/api_docs_build/glue.js.html Constructor for AStarPath. Use this to create a new A* pathfinding object. ```javascript function AStarPath() { this.ptr = _emscripten_bind_AStarPath_AStarPath_0(); getCache(AStarPath)[this.ptr] = this; }; ``` -------------------------------- ### JunctionRef.recommendedPosition() Source: https://github.com/aksem/libavoid-js/blob/master/api_docs_build/JunctionRef.html Gets the recommended position for the junction reference. ```APIDOC ## JunctionRef.recommendedPosition() ### Description Gets the recommended position for the junction reference. ### Method GET ### Endpoint /JunctionRef/recommendedPosition ### Parameters None ### Request Example ```javascript const recommendedPos = junctionRef.recommendedPosition(); ``` ### Response #### Success Response (200) - **position** (Point) - The recommended position for the junction reference. #### Response Example ```json { "x": 15, "y": 25 } ``` ``` -------------------------------- ### Point y Property Source: https://github.com/aksem/libavoid-js/blob/master/api_docs_build/glue.js.html Accessor for getting and setting the y-coordinate of the point. ```javascript Object.defineProperty(Point.prototype, 'y', { get: Point.prototype.get_y, set: Point.prototype.set_y }); ``` -------------------------------- ### Manage Shape Connection Pins with libavoid-js Source: https://context7.com/aksem/libavoid-js/llms.txt Illustrates creating and using connection pins on shapes for precise connector attachment points. Requires AvoidLib to be loaded. ```javascript async function connectionPinsExample() { await AvoidLib.load(); const Avoid = AvoidLib.getInstance(); const router = new Avoid.Router(Avoid.OrthogonalRouting); // Create a shape const shapePoly = new Avoid.Polygon(4); shapePoly.set_ps(0, new Avoid.Point(100, 100)); shapePoly.set_ps(1, new Avoid.Point(200, 100)); shapePoly.set_ps(2, new Avoid.Point(200, 150)); shapePoly.set_ps(3, new Avoid.Point(100, 150)); const shape = new Avoid.ShapeRef(router, shapePoly, 1001); // Connection direction flags const ConnDirUp = 1; const ConnDirDown = 2; const ConnDirLeft = 4; const ConnDirRight = 8; const ConnDirAll = 15; const PIN_CLASS_ID = 2147483646; // Create pins at different positions on the shape // Parameters: (shape, classId, xOffset, yOffset, proportional, insideOffset, directions) // Center pin allowing all directions const centerPin = new Avoid.ShapeConnectionPin( shape, PIN_CLASS_ID, 0.5, 0.5, true, 0, ConnDirAll ); centerPin.setExclusive(false); // Left side pin const leftPin = new Avoid.ShapeConnectionPin( shape, PIN_CLASS_ID, 0, 0.5, true, 0, ConnDirLeft ); leftPin.setExclusive(false); // Right side pin const rightPin = new Avoid.ShapeConnectionPin( shape, PIN_CLASS_ID, 1.0, 0.5, true, 0, ConnDirRight ); rightPin.setExclusive(false); // Create connector attached to shape pin const srcConnEnd = new Avoid.ConnEnd(shape, PIN_CLASS_ID); const dstConnEnd = new Avoid.ConnEnd(new Avoid.Point(300, 125)); const connector = new Avoid.ConnRef(router, srcConnEnd, dstConnEnd); connector.setRoutingType(2); // Orthogonal router.processTransaction(); // Get pin information const pinPos = centerPin.position(); console.log(`Center pin position: (${pinPos.x}, ${pinPos.y})`); console.log(`Pin exclusive: ${centerPin.isExclusive()}`); return { router, shape, connector }; } ``` -------------------------------- ### Get VertID PROP_ConnPoint Source: https://github.com/aksem/libavoid-js/blob/master/api_docs_build/glue.js.html Retrieves the PROP_ConnPoint property of a VertID object. ```javascript VertID.prototype['get_PROP_ConnPoint'] = VertID.prototype.get_PROP_ConnPoint = function() { var self = this.ptr; }; ``` -------------------------------- ### Create Geometric Primitives Source: https://context7.com/aksem/libavoid-js/llms.txt Demonstrates the creation of individual points, polygons (rectangle and triangle), and rectangles using helper classes. ```javascript async function createGeometryExamples() { await AvoidLib.load(); const Avoid = AvoidLib.getInstance(); // Create individual points const point1 = new Avoid.Point(100, 200); const point2 = new Avoid.Point(300, 400); console.log(`Point coordinates: (${point1.x}, ${point1.y})`); // Create a polygon with 4 vertices (rectangle) const rectPoly = new Avoid.Polygon(4); rectPoly.set_ps(0, new Avoid.Point(50, 50)); rectPoly.set_ps(1, new Avoid.Point(150, 50)); rectPoly.set_ps(2, new Avoid.Point(150, 100)); rectPoly.set_ps(3, new Avoid.Point(50, 100)); // Create a triangle polygon const trianglePoly = new Avoid.Polygon(3); trianglePoly.set_ps(0, new Avoid.Point(200, 200)); trianglePoly.set_ps(1, new Avoid.Point(250, 150)); trianglePoly.set_ps(2, new Avoid.Point(300, 200)); // Create a rectangle using the Rectangle helper class const center = new Avoid.Point(400, 300); const rectangle = new Avoid.Rectangle(center, 100, 50); // width, height return { point1, point2, rectPoly, trianglePoly, rectangle }; } ``` -------------------------------- ### Get VertID tar Source: https://github.com/aksem/libavoid-js/blob/master/api_docs_build/glue.js.html Retrieves the tar property of a VertID object. ```javascript VertID.prototype['get_tar'] = VertID.prototype.get_tar = function() { var self = this.ptr; return _emscripten_bind_VertID_get_tar_0(self); }; ``` -------------------------------- ### Create and Configure Router Source: https://context7.com/aksem/libavoid-js/llms.txt Creates a router instance supporting polyline and orthogonal routing, and configures various routing parameters like segment penalty and nudging distance. ```javascript import { AvoidLib } from 'libavoid-js'; async function createConfiguredRouter() { await AvoidLib.load(); const Avoid = AvoidLib.getInstance(); // Create router with combined routing flags const router = new Avoid.Router( Avoid.PolyLineRouting | Avoid.OrthogonalRouting ); // Configure routing parameters router.setRoutingParameter(Avoid.segmentPenalty, 50); router.setRoutingParameter(Avoid.anglePenalty, 0); router.setRoutingParameter(Avoid.crossingPenalty, 200); router.setRoutingParameter(Avoid.clusterCrossingPenalty, 4000); router.setRoutingParameter(Avoid.fixedSharedPathPenalty, 110); router.setRoutingParameter(Avoid.idealNudgingDistance, 25); return router; } ``` -------------------------------- ### Class: AStarPath Source: https://github.com/aksem/libavoid-js/blob/master/api_docs_build/VertID.html Implements the A* pathfinding algorithm. ```APIDOC ## Class: AStarPath ### Description Provides A* pathfinding capabilities. ### Methods #### search(start, end, obstacles) Performs a path search. ``` -------------------------------- ### Get VertID src Source: https://github.com/aksem/libavoid-js/blob/master/api_docs_build/glue.js.html Retrieves the src property of a VertID object. ```javascript VertID.prototype['get_src'] = VertID.prototype.get_src = function() { var self = this.ptr; return _emscripten_bind_VertID_get_src_0(self); }; ``` -------------------------------- ### Get VertID props Source: https://github.com/aksem/libavoid-js/blob/master/api_docs_build/glue.js.html Retrieves the props property of a VertID object. ```javascript VertID.prototype['get_props'] = VertID.prototype.get_props = function() { var self = this.ptr; return _emscripten_bind_VertID_get_props_0(self); }; ``` -------------------------------- ### MinimumTerminalSpanningTree Constructor Source: https://github.com/aksem/libavoid-js/blob/master/api_docs_build/MinimumTerminalSpanningTree.html Initializes a new MinimumTerminalSpanningTree object. ```APIDOC ## new MinimumTerminalSpanningTree() ### Description Creates a new instance of the MinimumTerminalSpanningTree. ### Method Constructor ### Endpoint N/A ### Parameters None ### Request Example ```javascript const mst = new MinimumTerminalSpanningTree(); ``` ### Response #### Success Response (200) - **mst** (MinimumTerminalSpanningTree) - A new instance of MinimumTerminalSpanningTree. #### Response Example ```javascript // Returns an instance of MinimumTerminalSpanningTree ``` -------------------------------- ### Get VertID vn Source: https://github.com/aksem/libavoid-js/blob/master/api_docs_build/glue.js.html Retrieves the vn property of a VertID object. ```javascript VertID.prototype['get_vn'] = VertID.prototype.get_vn = function() { var self = this.ptr; return _emscripten_bind_VertID_get_vn_0(self); }; ``` -------------------------------- ### Get VertID objID Source: https://github.com/aksem/libavoid-js/blob/master/api_docs_build/glue.js.html Retrieves the objID property of a VertID object. ```javascript VertID.prototype['get_objID'] = VertID.prototype.get_objID = function() { var self = this.ptr; return _emscripten_bind_VertID_get_objID_0(self); }; ``` -------------------------------- ### Point id Property Source: https://github.com/aksem/libavoid-js/blob/master/api_docs_build/glue.js.html Accessor for getting and setting the ID of the point. ```javascript Object.defineProperty(Point.prototype, 'id', { get: Point.prototype.get_id, set: Point.prototype.set_id }); ``` -------------------------------- ### ActionInfo Class Methods Source: https://github.com/aksem/libavoid-js/blob/master/api_docs_build/glue.js.html Provides methods for setting the 'firstMove' property and destroying an ActionInfo object. Ensure 'arg0' is a valid pointer or object. ```javascript ActionInfo.prototype['set_firstMove'] = ActionInfo.prototype.set_firstMove = function(arg0) { var self = this.ptr; if (arg0 && typeof arg0 === 'object') arg0 = arg0.ptr; _emscripten_bind_ActionInfo_set_firstMove_1(self, arg0); }; Object.defineProperty(ActionInfo.prototype, 'firstMove', { get: ActionInfo.prototype.get_firstMove, set: ActionInfo.prototype.set_firstMove }); ActionInfo.prototype['__destroy__'] = ActionInfo.prototype.__destroy__ = function() { var self = this.ptr; _emscripten_bind_ActionInfo___destroy___0(self); }; ``` -------------------------------- ### Point x Property Source: https://github.com/aksem/libavoid-js/blob/master/api_docs_build/glue.js.html Accessor for getting and setting the x-coordinate of the point. ```javascript Object.defineProperty(Point.prototype, 'x', { get: Point.prototype.get_x, set: Point.prototype.set_x }); ``` -------------------------------- ### ActionInfo Constructor Source: https://github.com/aksem/libavoid-js/blob/master/api_docs_build/glue.js.html Initializes an ActionInfo object. Handles cases where the 'fm' parameter is undefined. ```javascript if (fm === undefined) { this.ptr = _emscripten_bind_ActionInfo_ActionInfo_3(t, s, p); getCache(ActionInfo)[this.ptr] = this;return } this.ptr = _emscripten_bind_ActionInfo_ActionInfo_4(t, s, p, fm); getCache(ActionInfo)[this.ptr] = this; ``` -------------------------------- ### LineRep Class Methods Source: https://github.com/aksem/libavoid-js/blob/master/api_docs_build/glue.js.html Methods for accessing and modifying the start and end points of a LineRep. ```APIDOC ## LineRep Class Methods ### get_begin Retrieves the starting point of the line. ### Method GET ### Endpoint N/A (Class method) ### Parameters None ### Request Example ```javascript var startPoint = lineRep.get_begin(); ``` ### Response #### Success Response (200) - **Point** (Wrapper) - The starting point of the line. ### set_begin Sets the starting point of the line. ### Method SET ### Endpoint N/A (Class method) ### Parameters - **arg0** (Point) - The new starting point. ### Request Example ```javascript lineRep.set_begin(newPoint); ``` ### get_end Retrieves the ending point of the line. ### Method GET ### Endpoint N/A (Class method) ### Parameters None ### Request Example ```javascript var endPoint = lineRep.get_end(); ``` ### Response #### Success Response (200) - **Point** (Wrapper) - The ending point of the line. ### set_end Sets the ending point of the line. ### Method SET ### Endpoint N/A (Class method) ### Parameters - **arg0** (Point) - The new ending point. ### Request Example ```javascript lineRep.set_end(newPoint); ``` ### Destructor Frees the memory associated with the LineRep object. ### Method DESTROY ### Endpoint N/A ### Parameters None ### Request Example ```javascript lineRep.__destroy__(); ``` ``` -------------------------------- ### ShapeConnectionPin Class Source: https://github.com/aksem/libavoid-js/blob/master/api_docs_build/glue.js.html Documentation for the ShapeConnectionPin class, including its constructor and methods. ```APIDOC ## ShapeConnectionPin Class ### Description Represents a connection pin for a shape, used in layout algorithms. ### Constructor #### ShapeConnectionPin ##### Parameters - **shape** (object | pointer) - The associated shape. - **classId** (object | pointer) - The class ID. - **xOffset** (Double | object | pointer) - The X offset. - **yOffset** (Double | object | pointer) - The Y offset. - **proportional** (Boolean | object | pointer) - Proportional flag. - **insideOffset** (object | pointer) - Inside offset. - **visDirs** (object | pointer) - Visible directions. *Note: The constructor has multiple overloads based on the number of arguments provided.* ### Methods #### setConnectionCost ##### Description Sets the connection cost for the shape connection pin. ##### Parameters - **cost** (Double) - The cost to set. ##### Request Example ```javascript shapeConnectionPinInstance.setConnectionCost(10.5); ``` #### position ##### Description Gets or sets the position of the connection pin. ##### Parameters - **newPoly** (Polygon | object | pointer) - The new position polygon (optional). ##### Returns - **Point (Wrapper)** - The position of the pin. ##### Request Example ```javascript const currentPosition = shapeConnectionPinInstance.position(); shapeConnectionPinInstance.position(newPolygonInstance); ``` #### directions ##### Description Gets the available directions for the connection pin. ##### Returns - **UnsignedLong** - The directions. ##### Request Example ```javascript const pinDirections = shapeConnectionPinInstance.directions(); ``` #### setExclusive ##### Description Sets the exclusivity of the connection pin. ##### Parameters - **exclusive** (Boolean) - Whether the pin is exclusive. ##### Request Example ```javascript shapeConnectionPinInstance.setExclusive(true); ``` #### isExclusive ##### Description Checks if the connection pin is exclusive. ##### Returns - **Boolean** - True if exclusive, false otherwise. ##### Request Example ```javascript const isPinExclusive = shapeConnectionPinInstance.isExclusive(); ``` #### __destroy__ ##### Description Destroys the ShapeConnectionPin object. ##### Request Example ```javascript shapeConnectionPinInstance.__destroy__(); ``` ``` -------------------------------- ### Get Box Height Source: https://github.com/aksem/libavoid-js/blob/master/api_docs_build/glue.js.html Retrieves the height of a Box object. This method is part of the Box class. ```javascript Box.prototype['height'] = Box.prototype.height = function() { var self = this.ptr; return _emscripten_bind_Box_height_0(self); };; ``` -------------------------------- ### Router Constructor Source: https://github.com/aksem/libavoid-js/blob/master/api_docs_build/glue.js.html Initializes a Router object with optional flags. Flags should be a valid object or pointer. ```javascript function Router(flags) { if (flags && typeof flags === 'object') flags = flags.ptr; this.ptr = _emscripten_bind_Router_Router_1(flags); getCache(Router)[this.ptr] = this; };; ``` -------------------------------- ### Point Class Documentation Source: https://github.com/aksem/libavoid-js/blob/master/api_docs_build/Point.html Documentation for the Point class, including its constructor and methods. ```APIDOC ## Point Class ### Description Represents a point in 2D space. ### Methods #### new Point() Constructor for the Point class. #### equal(rhs) → {Boolean} Compares this point with another point for equality. ##### Parameters: | Name | Type | Description | | ---- | ----------- | ---------------------------- | | rhs | [Point](Point.html) | The other point to compare with. | ``` -------------------------------- ### Get Box Width Source: https://github.com/aksem/libavoid-js/blob/master/api_docs_build/glue.js.html Retrieves the width of a Box object. This method is part of the Box class. ```javascript Box.prototype['width'] = Box.prototype.width = function() { var self = this.ptr; return _emscripten_bind_Box_width_0(self); };; ``` -------------------------------- ### Get Box Length Source: https://github.com/aksem/libavoid-js/blob/master/api_docs_build/glue.js.html Retrieves the length of a Box object. This method is part of the Box class. ```javascript Box.prototype['length'] = Box.prototype.length = function() { var self = this.ptr; return _emscripten_bind_Box_length_1(self, dimension); };; ``` -------------------------------- ### Move Shapes and Update Routes with libavoid-js Source: https://context7.com/aksem/libavoid-js/llms.txt Demonstrates dynamic shape movement and automatic route recalculation. Ensure AvoidLib is loaded before use. ```javascript async function moveShapesExample() { await AvoidLib.load(); const Avoid = AvoidLib.getInstance(); const router = new Avoid.Router(Avoid.PolyLineRouting); // Create a shape const shapePoly = new Avoid.Polygon(4); shapePoly.set_ps(0, new Avoid.Point(100, 100)); shapePoly.set_ps(1, new Avoid.Point(150, 100)); shapePoly.set_ps(2, new Avoid.Point(150, 150)); shapePoly.set_ps(3, new Avoid.Point(100, 150)); const shape = new Avoid.ShapeRef(router, shapePoly); // Create a connector that routes around the shape const connector = new Avoid.ConnRef(router, new Avoid.ConnEnd(new Avoid.Point(50, 125)), new Avoid.ConnEnd(new Avoid.Point(200, 125)) ); router.processTransaction(); console.log('Initial route calculated'); // Move shape by offset (xDiff, yDiff) router.moveShape(shape, 50, 0); router.processTransaction(); console.log('Shape moved right by 50 units'); // Move shape to new polygon position const newPoly = new Avoid.Polygon(4); newPoly.set_ps(0, new Avoid.Point(200, 200)); newPoly.set_ps(1, new Avoid.Point(250, 200)); newPoly.set_ps(2, new Avoid.Point(250, 250)); newPoly.set_ps(3, new Avoid.Point(200, 250)); shape.setNewPoly(newPoly); router.processTransaction(); console.log('Shape moved to new position'); // Delete the shape router.deleteShape(shape); router.processTransaction(); console.log('Shape deleted'); return { router, connector }; } ``` -------------------------------- ### Get Class of Wrapped Object Source: https://github.com/aksem/libavoid-js/blob/master/api_docs_build/glue.js.html Retrieves the JavaScript class associated with a wrapped C++ object. ```javascript function getClass(obj) { return obj.__class__; } ``` -------------------------------- ### Initialize HyperedgeTreeNode Source: https://github.com/aksem/libavoid-js/blob/master/api_docs_build/glue.js.html Constructor for HyperedgeTreeNode. Use this to create a new node in the hyperedge tree. ```javascript function HyperedgeTreeNode() { this.ptr = _emscripten_bind_HyperedgeTreeNode_HyperedgeTreeNode_0(); getCache(HyperedgeTreeNode)[this.ptr] = this; }; ``` -------------------------------- ### Callback Configuration Source: https://github.com/aksem/libavoid-js/blob/master/api_docs_build/ConnRef.html Method for setting a callback function. ```APIDOC ## POST /api/callback/set ### Description Sets a callback function to be invoked. ### Method POST ### Endpoint /api/callback/set ### Parameters #### Request Body - **cb** (ConnRefCallback) - Required - The callback function. - **ptr** (VoidPtr) - Required - A pointer to user data. ### Request Example ```json { "cb": "callback_function_reference", "ptr": "user_data_pointer" } ``` ### Response #### Success Response (200) - **status** (string) - Indicates success. #### Response Example ```json { "status": "success" } ``` ``` -------------------------------- ### LineRep Class Documentation Source: https://github.com/aksem/libavoid-js/blob/master/api_docs_build/LineRep.html Documentation for the LineRep class, including its constructor. ```APIDOC ## LineRep Class ### Description Represents a line in the libavoid-js library. ### Constructor #### new LineRep() Initializes a new instance of the LineRep class. ``` -------------------------------- ### LineRep: Get End Point Source: https://github.com/aksem/libavoid-js/blob/master/api_docs_build/glue.js.html Retrieves the ending point of a LineRep object. Returns a Point object. ```javascript LineRep.prototype['get_end'] = LineRep.prototype.get_end = function() { var self = this.ptr; return wrapPointer(_emscripten_bind_LineRep_get_end_0(self), Point); }; ``` -------------------------------- ### Global Functions Source: https://github.com/aksem/libavoid-js/blob/master/api_docs_build/Box.html Documentation for global utility functions. ```APIDOC ## Global Functions ### `castObject(ptr, cls)` #### Description Casts a pointer to a specific class type. ### `compare(a, b)` #### Description Compares two values. ### `destroy(obj)` #### Description Destroys an object. ### `ensureCache()` #### Description Ensures the cache is initialized. ### `ensureFloat32(value)` #### Description Ensures the value is a Float32. ### `ensureFloat64(value)` #### Description Ensures the value is a Float64. ### `ensureInt8(value)` #### Description Ensures the value is an Int8. ### `ensureInt16(value)` #### Description Ensures the value is an Int16. ### `ensureInt32(value)` #### Description Ensures the value is an Int32. ### `ensureString(value)` #### Description Ensures the value is a string. ### `getCache()` #### Description Retrieves the cache. ### `getClass(obj)` #### Description Gets the class of an object. ### `getPointer(obj)` #### Description Gets the pointer to an object. ### `WrapperObject(ptr)` #### Description Creates a wrapper object. ### `wrapPointer(ptr, cls)` #### Description Wraps a pointer with a class type. ``` -------------------------------- ### Router Class Methods Source: https://github.com/aksem/libavoid-js/blob/master/api_docs_build/Box.html Documentation for the methods available on the Router class. ```APIDOC ## Router Class Methods ### `deleteConnector(connectorId)` #### Description Deletes a connector from the router. ### `deleteShape(shapeId)` #### Description Deletes a shape from the router. ### `moveJunction(junctionId, newPosition)` #### Description Moves a junction to a new position. #### Parameters - **junctionId** (any) - The ID of the junction to move. - **newPosition** (Point) - The new position for the junction. ### `moveShape(shapeId, newPosition)` #### Description Moves a shape to a new position. #### Parameters - **shapeId** (any) - The ID of the shape to move. - **newPosition** (Point) - The new position for the shape. ### `printInfo()` #### Description Prints information about the router's current state. ### `processTransaction()` #### Description Processes a transaction to update the routing. ### `setRoutingOption(option, value)` #### Description Sets a routing option. #### Parameters - **option** (string) - The name of the routing option. - **value** (any) - The value for the routing option. ### `setRoutingParameter(parameter, value)` #### Description Sets a routing parameter. #### Parameters - **parameter** (string) - The name of the routing parameter. - **value** (any) - The value for the routing parameter. ``` -------------------------------- ### Get Polygon Interface ID Source: https://github.com/aksem/libavoid-js/blob/master/api_docs_build/glue.js.html Returns the ID of the PolygonInterface. This method is part of the PolygonInterface class and returns a long. ```javascript PolygonInterface.prototype['id'] = PolygonInterface.prototype.id = function() { var self = this.ptr; return _emscripten_bind_PolygonInterface_id_0(self); };; ``` -------------------------------- ### Routing Configuration Methods Source: https://github.com/aksem/libavoid-js/blob/master/api_docs_build/Router.html Methods for configuring routing options and parameters. ```APIDOC ## setRoutingOption(option, value) ### Description Sets a routing option to a specified value. ### Method Not specified (likely a method of a class or object) ### Endpoint Not applicable (client-side library function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```json { "option": "Avoid_RoutingOption", "value": "Boolean" } ``` ### Response #### Success Response (200) None specified #### Response Example None specified ``` ```APIDOC ## setRoutingParameter(parameter, value) ### Description Sets a routing parameter to a specified numeric value. ### Method Not specified (likely a method of a class or object) ### Endpoint Not applicable (client-side library function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```json { "parameter": "Avoid_RoutingParameter", "value": "number" } ``` ### Response #### Success Response (200) None specified #### Response Example None specified ``` -------------------------------- ### Get C++ Pointer from Wrapped Object Source: https://github.com/aksem/libavoid-js/blob/master/api_docs_build/glue.js.html Retrieves the raw C++ pointer associated with a wrapped JavaScript object. ```javascript function getPointer(obj) { return obj.ptr; } ``` -------------------------------- ### ActionInfo Class Methods Source: https://github.com/aksem/libavoid-js/blob/master/api_docs_build/LineRep.html Documentation for methods within the ActionInfo class. ```APIDOC ## ActionInfo Class Methods ### addConnEndUpdate Adds a connection end update. ### conn Gets the connection associated with this action. ### junction Gets the junction associated with this action. ### obstacle Gets the obstacle associated with this action. ### shape Gets the shape associated with this action. ``` -------------------------------- ### ActionInfo Class Documentation Source: https://github.com/aksem/libavoid-js/blob/master/api_docs_build/ActionInfo.html Details on the ActionInfo class and its methods. ```APIDOC ## ActionInfo Class ### Description Provides information and methods related to actions within the routing system. ### Methods #### `addConnEndUpdate(type, connEnd, isConnPinMoveUpdate)` ##### Parameters: - **type** (number) - Description not provided. - **connEnd** ([ConnEnd](ConnEnd.html)) - The connection end object. - **isConnPinMoveUpdate** (Boolean) - Indicates if this is a connection pin move update. ``` -------------------------------- ### Get ConnRef ID Source: https://github.com/aksem/libavoid-js/blob/master/api_docs_build/glue.js.html Provides a method 'id' for the ConnRef prototype to retrieve the connection's ID. Returns an UnsignedLong. ```javascript ConnRef.prototype['id'] = ConnRef.prototype.id = function() { var self = this.ptr; return _emscripten_bind_ConnRef_id_0(self); };; ``` -------------------------------- ### ActionInfo Constructors Source: https://github.com/aksem/libavoid-js/blob/master/api_docs_build/glue.js.html Constructs an ActionInfo object. It can be initialized with or without a 'fm' parameter. ```APIDOC ## ActionInfo Constructors ### Description Initializes a new instance of the ActionInfo class. The constructor can take three or four arguments. ### Method Constructor ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```javascript // Example with 3 arguments let actionInfo1 = new ActionInfo(t, s, p); // Example with 4 arguments let actionInfo2 = new ActionInfo(t, s, p, fm); ``` ### Response None (constructor) ``` -------------------------------- ### ShapeConnectionPin.position Source: https://github.com/aksem/libavoid-js/blob/master/api_docs_build/glue.js.html Gets or sets the position of a ShapeConnectionPin. If 'newPoly' is provided, it sets the position; otherwise, it returns the current position as a Point object. ```javascript ShapeConnectionPin.prototype['position'] = ShapeConnectionPin.prototype.position = function(newPoly) { var self = this.ptr; if (newPoly && typeof newPoly === 'object') newPoly = newPoly.ptr; if (newPoly === undefined) { return wrapPointer(_emscripten_bind_ShapeConnectionPin_position_0(self), Point) } return wrapPointer(_emscripten_bind_ShapeConnectionPin_position_1(self, newPoly), Point); ``` -------------------------------- ### PolygonInterface Class Methods Source: https://github.com/aksem/libavoid-js/blob/master/api_docs_build/LineRep.html Documentation for methods within the PolygonInterface class. ```APIDOC ## PolygonInterface Class Methods ### at Gets the point at a specific index. ### boundingRectPolygon Gets the bounding rectangle of the polygon. ### clear Clears the polygon. ### empty Checks if the polygon is empty. ### id Gets the ID of the polygon. ### offsetBoundingBox Offsets the bounding box of the polygon. ### offsetPolygon Offsets the polygon. ### size Gets the number of points in the polygon. ``` -------------------------------- ### Obstacle Class Methods Source: https://github.com/aksem/libavoid-js/blob/master/api_docs_build/LineRep.html Documentation for methods within the Obstacle class. ```APIDOC ## Obstacle Class Methods ### id Gets the ID of the obstacle. ### polygon Gets the polygon representing the obstacle. ### position Gets the position of the obstacle. ### router Gets the router associated with the obstacle. ### setNewPoly Sets a new polygon for the obstacle. ``` -------------------------------- ### Get Polygon Interface Size Source: https://github.com/aksem/libavoid-js/blob/master/api_docs_build/glue.js.html Returns the number of points in the PolygonInterface. This method is part of the PolygonInterface class and returns an unsigned long. ```javascript PolygonInterface.prototype['size'] = PolygonInterface.prototype.size = function() { var self = this.ptr; return _emscripten_bind_PolygonInterface_size_0(self); };; ``` -------------------------------- ### ShapeConnectionPin Class Methods Source: https://github.com/aksem/libavoid-js/blob/master/api_docs_build/LineRep.html Documentation for methods within the ShapeConnectionPin class. ```APIDOC ## ShapeConnectionPin Class Methods ### directions Gets the connection directions for the pin. ### isExclusive Checks if the pin is exclusive. ### position Gets the position of the connection pin. ### setConnectionCost Sets the connection cost for the pin. ### setExclusive Sets whether the pin is exclusive. ### updatePosition Updates the position of the connection pin. ``` -------------------------------- ### Box Class Source: https://github.com/aksem/libavoid-js/blob/master/api_docs_build/glue.js.html Represents a bounding box, likely used for spatial partitioning or geometric calculations. It provides a method to get its length. ```APIDOC ## Box ### Description Represents a geometric box, possibly for spatial indexing or collision detection. ### Methods #### `length(dimension)` - **Description**: Calculates the length of the box along a specified dimension. - **Parameters**: - **dimension** (UnsignedLong) - Required - The dimension for which to calculate the length. - **Method**: N/A (internal) - **Endpoint**: N/A ### Request Example ```json // const box = new Box(); // const length = box.length(0); // Get length along dimension 0 ``` ### Response #### Success Response (Double) - Returns the length of the box as a double-precision floating-point number. #### Response Example ```json // Example response for length(0): // 10.5 ``` ``` -------------------------------- ### Polygon ps Property Source: https://github.com/aksem/libavoid-js/blob/master/api_docs_build/glue.js.html Accessor for getting and setting points within the polygon. Use with caution, ensuring correct indices and point objects. ```javascript Object.defineProperty(Polygon.prototype, 'ps', { get: Polygon.prototype.get_ps, set: Polygon.prototype.set_ps }); ``` -------------------------------- ### Point Class Methods Source: https://github.com/aksem/libavoid-js/blob/master/api_docs_build/LineRep.html Documentation for methods within the Point class. ```APIDOC ## Point Class Methods ### equal Checks if two points are equal. ``` -------------------------------- ### Get Box Maximum Point Source: https://github.com/aksem/libavoid-js/blob/master/api_docs_build/glue.js.html Retrieves the maximum point of a Box object. This method is part of the Box class and returns a Point wrapper. ```javascript Box.prototype['get_max'] = Box.prototype.get_max = function() { var self = this.ptr; return wrapPointer(_emscripten_bind_Box_get_max_0(self), Point); }; ``` -------------------------------- ### HyperedgeImprover Class Source: https://github.com/aksem/libavoid-js/blob/master/api_docs_build/HyperedgeImprover.html Documentation for the HyperedgeImprover class, including its constructor and methods. ```APIDOC ## HyperedgeImprover ### Description Represents a HyperedgeImprover object. ### Methods #### new HyperedgeImprover() Constructor for the HyperedgeImprover class. #### clear() Clears the HyperedgeImprover. #### setRouter(router) Sets the router for the HyperedgeImprover. * **router** - The router object to set. ``` -------------------------------- ### Class Methods Source: https://github.com/aksem/libavoid-js/blob/master/api_docs_build/global.html Details on methods related to class instantiation and manipulation. ```APIDOC ## getClass() ### Description Retrieves the class of the current object. ### Method GET ### Endpoint N/A (Method within a class) ### Parameters None ### Response #### Success Response (200) - **class** (string) - The class name of the object. #### Response Example ```json { "class": "WrapperObject" } ``` ``` ```APIDOC ## getPointer() ### Description Retrieves the pointer associated with the object. ### Method GET ### Endpoint N/A (Method within a class) ### Parameters None ### Response #### Success Response (200) - **pointer** (any) - The pointer value. #### Response Example ```json { "pointer": "0x12345678" } ``` ``` ```APIDOC ## WrapperObject() ### Description Constructor for the WrapperObject. ### Method CONSTRUCTOR ### Endpoint N/A ### Parameters #### Request Body - **__class__** (object) - Optional. Represents the class to be wrapped. ### Request Example ```json { "__class__": { /* class definition */ } } ``` ### Response #### Success Response (200) - **WrapperObject** (object) - An instance of WrapperObject. #### Response Example ```json { "instance": "WrapperObject" } ``` ``` ```APIDOC ## wrapPointer(__class_opt) ### Description Wraps a pointer with an optional class. ### Method POST ### Endpoint N/A (Method within a class) ### Parameters #### Request Body - **__class__** (object) - Optional. The class to wrap the pointer with. ### Request Example ```json { "__class__": { /* class definition */ } } ``` ### Response #### Success Response (200) - **wrappedPointer** (object) - The pointer wrapped with the specified class. #### Response Example ```json { "wrappedPointer": "..." } ``` ``` -------------------------------- ### Get Box Minimum Point Source: https://github.com/aksem/libavoid-js/blob/master/api_docs_build/glue.js.html Retrieves the minimum point of a Box object. This method is part of the Box class and returns a Point wrapper. ```javascript Box.prototype['get_min'] = Box.prototype.get_min = function() { var self = this.ptr; return wrapPointer(_emscripten_bind_Box_get_min_0(self), Point); }; ``` -------------------------------- ### Get Cache for Wrapper Objects Source: https://github.com/aksem/libavoid-js/blob/master/api_docs_build/glue.js.html Retrieves the cache associated with a specific WrapperObject class or the default WrapperObject. Used for managing cached instances. ```javascript function getCache(__class__) { return (__class__ || WrapperObject).__cache__; } Module['getCache'] = getCache; ```