# gizai/figure

what each part of a made figure is (its head, ears, arms, legs, tail, wings, trunk), so its rig puts each joint in the part it moves and gives each vertex only its own part's joints. The figure is drawn from VIEWS sides as its colors and turns show it; SAM 3 finds each part's words in every view, and each vertex takes the part the views it faces most squarely see it in. A vertex no view sees takes its neighbours' part along the surface.

```gizlang
import * as Figure from "gizai/figure";
```

## Types

### `Finder`

```gizlang
type Finder = (picture: Img.Image, texts: Vec<string>) => Vec<bytes> throws string
```

What SAM 3 finds in a picture: each text's pixels (255 where it finds it, else 0), a mask a text.

### `Rig`

```gizlang
type Rig = { names: Vec<string>; parents: Vec<i64>; heads: Vec<f64>; joints: Vec<i64>; weights: Vec<f32>; }
```

A rig as a model makes it: its joints' names, parents and places at rest (x, y, z each, as the mesh's), and each
vertex's 4 joints and their weights.

- `names`: `Vec<string>`
- `parents`: `Vec<i64>`
- `heads`: `Vec<f64>`
- `joints`: `Vec<i64>`
- `weights`: `Vec<f32>`

## Functions

### `partsOf`

```gizlang
function partsOf(positions: Vec<f32>, triangles: Vec<i64>, colors: Vec<f32>, find: Finder): bytes throws string
```

Each vertex's part (HEAD ... TRUNK, 0: none) of the figure of POSITIONS (x, y, z; y up) and TRIANGLES, its
vertices' COLORS (r, g, b, 0..1), by SAM 3 (FIND) in its views.

Effects: fail, read, write, console, io, alloc.

### `constrained`

```gizlang
function constrained(r: Rig, positions: Vec<f32>, parts: bytes): Rig
```

R on the figure of POSITIONS whose vertices are PARTS (partsOf): each vertex's weights only from joints of the
segments its part may take (MAY), and none from a limb whose joints lie mostly in another part: a toy's long
ears, which its learned rig gave the arms (their joints in them), move with its head; a joint it may not take gives
its weight to its nearest ancestor it may. Its
joints stay where they are (laid anew along a part, the vertices still bound to them swung about the new places and
tore). A rig that is no humanoid's stays.

Effects: fail, read, write, console, io, alloc.

### `limbAstray`

```gizlang
function limbAstray(names: Vec<string>, parents: Vec<i64>, heads: Vec<f64>, positions: Vec<f32>, parts: bytes): bool
```

Whether the humanoid skeleton NAMES, PARENTS at HEADS (3 a joint, the figure's frame) has a limb that lies in
another part of the figure of POSITIONS and PARTS than its own (a toy's arms in its long ears): a body fitted to it
(MHR's) would carry that part with the limb. No for a skeleton that is no humanoid's.

Effects: fail, read, write, console, io, alloc.

## Constants

### `HEAD`

```gizlang
const HEAD: u64 = 1u
```

The head: the first of the parts, each a number in a mask of parts (0: none found).

### `EAR`

```gizlang
const EAR: u64 = 2u
```

An ear.

### `ARM`

```gizlang
const ARM: u64 = 3u
```

An arm.

### `LEG`

```gizlang
const LEG: u64 = 4u
```

A leg.

### `TAIL`

```gizlang
const TAIL: u64 = 5u
```

The tail.

### `WING`

```gizlang
const WING: u64 = 6u
```

A wing.

### `TRUNK`

```gizlang
const TRUNK: u64 = 7u
```

The trunk.

