> ## Documentation Index
> Fetch the complete documentation index at: https://docs.ploterr.com/llms.txt
> Use this file to discover all available pages before exploring further.

# VectorNetwork

> VectorNetwork is an editable path or closed profile.

Each node has a position and optional curve handles.

## Import

```typescript theme={null}
import { VectorNetwork } from '@opengeometry/floorkit';
```

## Example

```typescript theme={null}
import { VectorNetwork } from '@opengeometry/floorkit';

const profile = new VectorNetwork(
  [
    [0, 0],
    [4, 0],
    [4, 3],
    [0, 3],
  ],
  true,
);
profile.bendSegmentTo(0, 2, -0.4);
const inserted = profile.insertNode(1, 4, 1.5);
profile.moveNode(inserted, 4.2, 1.5);
console.log(profile.toRing());
```

## Notes

* Nodes use `[x, z]` profile coordinates.
* `toRing()` changes curved edges into points.
* A closed profile needs three nodes or more.
* A network is one path. It has no branches, and it does not split where it crosses itself.

## Constructor

```typescript theme={null}
constructor(points: Array<Array<number>>, closed: boolean);
```

## Properties

<ResponseField name="nodes" type="VNNode[]" />

<ResponseField name="closed" type="boolean" />

<ResponseField name="segmentCount" type="number">
  Read-only. Number of edges: a closed loop has one per node; an open path has one fewer.
</ResponseField>

## Methods

### segmentEndpoints

```typescript theme={null}
segmentEndpoints(i: number): [
    Point,
    Point
];
```

Endpoints of edge `i` as profile points.

### segmentMidpoint

```typescript theme={null}
segmentMidpoint(i: number): Point;
```

Midpoint of edge `i` (on the curve if curved), in profile coords.

### moveNode

```typescript theme={null}
moveNode(i: number, x: number, z: number): void;
```

### endIndex

```typescript theme={null}
endIndex(i: number): number;
```

The index of the node the edge leaving `i` ends at.

### bendSegmentTo

```typescript theme={null}
bendSegmentTo(i: number, px: number, pz: number): void;
```

Bend edge `i` so its curve passes through `(px, pz)` at the midpoint.

### insertNode

```typescript theme={null}
insertNode(i: number, px: number, pz: number): number;
```

Insert a vertex on edge `i`.

### deleteNode

```typescript theme={null}
deleteNode(i: number): boolean;
```

Delete node `i` and heal the gap: the previous node's outgoing edge now spans to the next node.

### toRing

```typescript theme={null}
toRing(): Array<Array<number>>;
```

Compile to a tessellated outer ring of `[x, z]` points for the kernel.

## Types

### VNNode

```typescript theme={null}
interface VNNode {
  x: number;
  z: number;
  curved: boolean;
  c1: Point;
  c2: Point;
}
```

<ResponseField name="x" type="number" required />

<ResponseField name="z" type="number" required />

<ResponseField name="curved" type="boolean" required>
  Whether the edge leaving this node (to the next node) is a cubic Bézier.
</ResponseField>

<ResponseField name="c1" type="Point" required>
  Control point near this node (absolute profile coords). Valid when `curved`.
</ResponseField>

<ResponseField name="c2" type="Point" required>
  Control point near the next node (absolute profile coords). Valid when `curved`.
</ResponseField>

### Point

Least-squares cubic Bézier fitting — the "delete and heal" half of the profile editor (Schneider, *An Algorithm for Automatically Fitting Digitized Curves*, Graphics Gems, 1990).

The package does not export this type by name.

```typescript theme={null}
type Point = [number, number];
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.