# an.ir.holds

Holding things: `grasp`, `place`, `release`, `handover` and `swap` (an#502, catalogue A4).

A **hold** says what carries an item over a span of a shot: a hand (any point
of a body), a socket of another body (a figurine’s hand), the ground, a point
of the stage, or nothing (it is in flight). These five action kinds change
holds, and each one moves the holder the way a hand would, so the change
reads as handled rather than teleported:

- `grasp`: the holder’s point (`by`) **reaches** the item’s grip over
  `reach` seconds, takes it at the instant it arrives (the item keeps the
  pose it has at that instant: no slide, no jump), and **retracts** to where
  the shot would have it over `retract` seconds, carrying it. The item is
  taken from whatever held it: the ground, a socket, another hand (a
  hand-over between two hands is the receiver’s `grasp`).
- `place`: the hand that holds the item brings it `onto` a target over
  `reach` seconds (its contact point onto the ground at floor height, its
  grip into a socket, aligned with the socket’s frame), lets it go there, and
  retracts empty.
- `release`: the hand lets go at `at`; the item falls under gravity with
  the velocity it had and lands on the ground at its rest angle, or is tossed
  `onto: ground@x` on an arc of height `arc`.
- `handover`: `place` into another holder’s point (`to`), or, with
  `meet` below 1, both hands reach toward each other and the receiver takes
  it where they meet.
- `swap`: a hand takes the item a holder has (`take`) and the hand
  holding another item gives it in its place (`give`), a beat later.

A reach that cannot arrive is never cheated: the body it hangs from may bend
(`lean`, degrees; the chain’s root turns about its own pivot, the way a
figure bends at the hip), and beyond that `an validate` says how far the
hand stays short and where to stand instead.

None of these makes a clip: the `solve` compile pass reads them
([`an.stage.hold`](an.stage.hold.html.md#module-an.stage.hold)) and emits the holders’ and the items’ keys.

```pycon
>>> from an.ir.compose import flatten, sequence, delay
>>> [(f.start, f.end, f.action.kind) for f in flatten(sequence(delay(1.0), grasp("paul/arm_r", "cup")))]
[(1.0, 1.75, 'grasp')]
>>> [(f.start, f.action.kind) for f in flatten(sequence(delay(2.0), release("cup", at=0.5)))]
[(2.5, 'release')]
>>> [(round(f.start, 2), f.action.kind) for f in flatten(swap("nap/hand", take="musket", give="sword", by="stu@hand_r"))]
[(0.0, 'grasp'), (0.25, 'place')]
```

These kinds are the core’s (ADR 0001’s test: a robot arm putting a box on a
shelf needs them without saying character), registered when [`an.ir`](an.ir.html.md#module-an.ir) loads.

### Module Attributes

| [`DFLT_REACH`](#an.ir.holds.DFLT_REACH)        | a deliberate reach at arm's length, about two thirds of a second there and back.                                                                                                                                     |
|--------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [`DFLT_RETRACT`](#an.ir.holds.DFLT_RETRACT)      | How long the hand takes to come back to where the shot has it (s).                                                                                                                                                   |
| [`DFLT_LEAN_DEG`](#an.ir.holds.DFLT_LEAN_DEG)     | a figure bent well over at the hip.                                                                                                                                                                                  |
| [`DFLT_TOSS_ARC`](#an.ir.holds.DFLT_TOSS_ARC)     | How high a toss rises above the higher of its two ends (scene px).                                                                                                                                                   |
| [`DFLT_SWAP_LAG`](#an.ir.holds.DFLT_SWAP_LAG)     | In a `swap`, how long after the taking hand starts the giving hand starts (s): it arrives a beat after the socket is empty.                                                                                          |
| [`GROUND`](#an.ir.holds.GROUND)            | The name of the floor in a target (`ground`, `ground@x`).                                                                                                                                                            |
| [`SURFACE`](#an.ir.holds.SURFACE)           | The point name of a body's supporting surface in a target (an#536): `crate@surface` (below the hand), `crate@surface@0.3` (that fraction of the way along it), as on the ground but on the body's top, following it. |
| [`HOLD_ACTION_KINDS`](#an.ir.holds.HOLD_ACTION_KINDS) | The kinds' names.                                                                                                                                                                                                    |
| [`GESTURE_KINDS`](#an.ir.holds.GESTURE_KINDS)     | The kinds that move a hand (a reach and a retract), as flattened leaves.                                                                                                                                             |

### Functions

| [`grasp`](#an.ir.holds.grasp)(by, item, \*[, reach, retract, lean, ...])   | `by` takes `item`.                                                                              |
|-----------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------|
| [`place`](#an.ir.holds.place)(item, onto, \*[, by, rotation, reach, ...])  | The hand holding `item` puts it `onto` a target.                                                |
| [`release`](#an.ir.holds.release)(item, \*[, at, onto, arc, rotation, ...])  | Let `item` go at `at` (a drop; `onto: ground@x` to land there; `arc` > 0 to throw it up first). |
| [`handover`](#an.ir.holds.handover)(item, to, \*[, by, meet, reach, ...])     | Give `item` to `to`.                                                                            |
| [`swap`](#an.ir.holds.swap)(holder, \*, take, give, by[, lag, ...])       | `by` takes `take` from `holder`; `give` goes there in its place.                                |

### Classes

| [`GraspAction`](#an.ir.holds.GraspAction)(\*[, name, kind, reach, retract, ...])   | `by` (a body's point: a hand) reaches `item`'s grip and takes it.                                                                                                                                                                                                                                                                                                                                                                                                                                |
|-------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [`PlaceAction`](#an.ir.holds.PlaceAction)(\*[, name, kind, by, rotation, ...])     | The hand holding `item` puts it `onto` a target and lets it go.                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| [`ReleaseAction`](#an.ir.holds.ReleaseAction)(\*[, name, kind, at, onto, ...])       | The hand holding `item` lets it go at `at`: it falls (never rising) onto the ground, `onto: ground@x` nudged to land there, or tossed up first when `arc` (px above the hand) is positive; it lands one end first, tips onto its side at `rotation` (default: the side of it it falls nearest to) and bounces a little (`bounce`: the coefficient of restitution, default [`an.stage.rigid.DFLT_BOUNCE`](an.stage.rigid.html.md#an.stage.rigid.DFLT_BOUNCE); 0 lands dead). |
| [`HandoverAction`](#an.ir.holds.HandoverAction)(\*[, name, kind, by, meet, ...])      | The hand holding `item` gives it to `to` (a hand, or a socket).                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| [`SwapAction`](#an.ir.holds.SwapAction)(\*[, name, kind, lag, rotation, ...])     | `by` takes `take` from `holder` and the hand holding `give` puts that there, `lag` seconds later: a `grasp` and a `place`.                                                                                                                                                                                                                                                                                                                                                                       |

### an.ir.holds.DFLT_LEAN_DEG *: [float](https://docs.python.org/3/builtins/functions.html#float)* *= 60.0*

a figure
bent well over at the hip. `0` never bends.

* **Type:**
  How far the body a hand hangs from may turn to reach (degrees)

### an.ir.holds.DFLT_REACH *: [float](https://docs.python.org/3/builtins/functions.html#float)* *= 0.4*

a
deliberate reach at arm’s length, about two thirds of a second there and back.

* **Type:**
  How long a hand takes to reach what it takes or where it puts it (s)

### an.ir.holds.DFLT_RETRACT *: [float](https://docs.python.org/3/builtins/functions.html#float)* *= 0.35*

How long the hand takes to come back to where the shot has it (s).

### an.ir.holds.DFLT_SWAP_LAG *: [float](https://docs.python.org/3/builtins/functions.html#float)* *= 0.25*

In a `swap`, how long after the taking hand starts the giving hand starts
(s): it arrives a beat after the socket is empty.

### an.ir.holds.DFLT_TOSS_ARC *: [float](https://docs.python.org/3/builtins/functions.html#float)* *= 0.0*

How high a toss rises above the higher of its two ends (scene px). `0`:
it is let fall, never thrown up (a let-go item does not rise; a positive
`arc` is a throw).

### an.ir.holds.GESTURE_KINDS *: [tuple](https://docs.python.org/3/builtins/stdtypes.html#tuple)[[str](https://docs.python.org/3/builtins/stdtypes.html#str), ...]* *= ('grasp', 'place', 'handover')*

The kinds that move a hand (a reach and a retract), as flattened leaves.

### an.ir.holds.GROUND *: [str](https://docs.python.org/3/builtins/stdtypes.html#str)* *= 'ground'*

The name of the floor in a target (`ground`, `ground@x`).

### *class* an.ir.holds.GraspAction(, name=None, kind='grasp', by, item, reach=0.4, retract=0.35, lean=60.0, align=True, carry=None, \*\*extra_data)

Bases: [`ExtensionAction`](an.ir.schema.html.md#an.ir.schema.ExtensionAction)

`by` (a body’s point: a hand) reaches `item`’s grip and takes it.

`item` is an entity id, with `@<point>` the grip (a bone of its rig,
or `u,v` a fraction of its drawing); unset: its `grip` bone, else its
stage point. `by` with no `@` is the far end of the body (an arm’s
hand). The item is held from `start + reach` on, and over the retract it
turns to how the hand holds things (`align`): drawn as it is, upright
along the hand’s part, the way a socket holds it; `align: false` keeps
the angle it was taken at. `carry` (degrees) turns the aligned item by
that much from how the hand holds it, about the grip, mirrored with the
hand: a long musket carried at `carry: -60` points up and clears the floor
a hand near the ground would sink it through (an#864). It needs `align`.

```pycon
>>> GraspAction(by="stu@hand_r", item="musket").reach == DFLT_REACH
True
>>> GraspAction(by="stu@hand_r", item="musket", carry=-60).carry
-60.0
```

#### model_config *: [ClassVar](https://docs.python.org/3/library/typing.html#typing.ClassVar)[ConfigDict]* *= {'extra': 'allow', 'populate_by_name': True}*

Configuration for the model, should be a dictionary conforming to [`ConfigDict`][pydantic.config.ConfigDict].

### an.ir.holds.HOLD_ACTION_KINDS *: [tuple](https://docs.python.org/3/builtins/stdtypes.html#tuple)[[str](https://docs.python.org/3/builtins/stdtypes.html#str), ...]* *= ('grasp', 'place', 'release', 'handover', 'swap')*

The kinds’ names.

### *class* an.ir.holds.HandoverAction(, name=None, kind='handover', item, to, by=None, meet=1.0, reach=0.4, retract=0.35, lean=60.0, align=True, \*\*extra_data)

Bases: [`ExtensionAction`](an.ir.schema.html.md#an.ir.schema.ExtensionAction)

The hand holding `item` gives it to `to` (a hand, or a socket).

`meet` is where the two meet, as a fraction of the way from the giver’s
hand to the receiver’s: `1` (the default) puts it into the receiver’s
point, which does not move (a figurine’s hand, a waiting hand); below 1
both hands reach and the receiver takes it where they meet (and turns it
as a `grasp` does, `align`).

```pycon
>>> HandoverAction(item="sword", to="nap/arm_r/weapon").meet
1.0
```

#### model_config *: [ClassVar](https://docs.python.org/3/library/typing.html#typing.ClassVar)[ConfigDict]* *= {'extra': 'allow', 'populate_by_name': True}*

Configuration for the model, should be a dictionary conforming to [`ConfigDict`][pydantic.config.ConfigDict].

### *class* an.ir.holds.PlaceAction(, name=None, kind='place', item, onto, by=None, rotation=None, reach=0.4, retract=0.35, lean=60.0, \*\*extra_data)

Bases: [`ExtensionAction`](an.ir.schema.html.md#an.ir.schema.ExtensionAction)

The hand holding `item` puts it `onto` a target and lets it go.

`onto` is `ground` (straight down, at floor height), `ground@x` (at
stage `x`), a body’s point (a socket: the item’s grip goes there, its
frame aligned with the socket’s), a body’s surface (`crate@surface`, or
`crate@surface@f` at that fraction along it: lying on its top as on the
ground, held by that body from then on, an#536) or `world@x,y` (hung on
a point).
`item@<point>` names the item’s point that touches the target (default:
its grip on a socket, its lowest point on the ground). `rotation`: the
item’s rotation where it rests (radians, the stage’s; on a surface, relative
to the surface, whose tilt is added; default: the angle it last rested at,
else the nearest quarter turn; in a socket, the socket’s own). In a socket
it is the angle the item comes to rest at (a musket aimed at someone, a
sabre raised), held relative to the socket
from then on, so it turns with it.

```pycon
>>> PlaceAction(item="musket", onto="nap/arm_r/weapon").by is None
True
```

#### model_config *: [ClassVar](https://docs.python.org/3/library/typing.html#typing.ClassVar)[ConfigDict]* *= {'extra': 'allow', 'populate_by_name': True}*

Configuration for the model, should be a dictionary conforming to [`ConfigDict`][pydantic.config.ConfigDict].

### *class* an.ir.holds.ReleaseAction(, name=None, kind='release', item, at=0.0, onto=None, arc=0.0, rotation=None, bounce=None, \*\*extra_data)

Bases: [`ExtensionAction`](an.ir.schema.html.md#an.ir.schema.ExtensionAction)

The hand holding `item` lets it go at `at`: it falls (never rising)
onto the ground, `onto: ground@x` nudged to land there, or tossed up
first when `arc` (px above the hand) is positive; it lands one end
first, tips onto its side at `rotation` (default: the side of it it falls nearest to) and
bounces a little (`bounce`: the coefficient of restitution, default
[`an.stage.rigid.DFLT_BOUNCE`](an.stage.rigid.html.md#an.stage.rigid.DFLT_BOUNCE); 0 lands dead).

```pycon
>>> ReleaseAction(item="cup", at=1.0).onto is None
True
```

#### model_config *: [ClassVar](https://docs.python.org/3/library/typing.html#typing.ClassVar)[ConfigDict]* *= {'extra': 'allow', 'populate_by_name': True}*

Configuration for the model, should be a dictionary conforming to [`ConfigDict`][pydantic.config.ConfigDict].

### an.ir.holds.SURFACE *: [str](https://docs.python.org/3/builtins/stdtypes.html#str)* *= 'surface'*

The point name of a body’s supporting surface in a target (an#536):
`crate@surface` (below the hand), `crate@surface@0.3` (that fraction of
the way along it), as on the ground but on the body’s top, following it.

### *class* an.ir.holds.SwapAction(, name=None, kind='swap', holder, take, give, by, lag=0.25, rotation=None, reach=0.4, retract=0.35, lean=60.0, align=True, \*\*extra_data)

Bases: [`ExtensionAction`](an.ir.schema.html.md#an.ir.schema.ExtensionAction)

`by` takes `take` from `holder` and the hand holding `give`
puts that there, `lag` seconds later: a `grasp` and a `place`.
`rotation` is the place’s: the angle `give` comes to rest at in the
holder (radians, the stage’s; default: the holder’s own).

```pycon
>>> SwapAction(holder="nap/hand", take="musket", give="sword", by="stu@hand_r").lag == DFLT_SWAP_LAG
True
```

#### model_config *: [ClassVar](https://docs.python.org/3/library/typing.html#typing.ClassVar)[ConfigDict]* *= {'extra': 'allow', 'populate_by_name': True}*

Configuration for the model, should be a dictionary conforming to [`ConfigDict`][pydantic.config.ConfigDict].

### an.ir.holds.grasp(by, item, , reach=0.4, retract=0.35, lean=60.0, align=True, carry=None)

`by` takes `item`.

```pycon
>>> grasp("stu@hand_r", "musket@grip").item
'musket@grip'
```

* **Return type:**
  [`GraspAction`](#an.ir.holds.GraspAction)

### an.ir.holds.handover(item, to, , by=None, meet=1.0, reach=0.4, retract=0.35, lean=60.0, align=True)

Give `item` to `to`.

```pycon
>>> handover("cup", "jo@hand_l", meet=0.5).meet
0.5
```

* **Return type:**
  [`HandoverAction`](#an.ir.holds.HandoverAction)

### an.ir.holds.place(item, onto, , by=None, rotation=None, reach=0.4, retract=0.35, lean=60.0)

The hand holding `item` puts it `onto` a target.

```pycon
>>> place("book", "ground@-860").onto
'ground@-860'
```

* **Return type:**
  [`PlaceAction`](#an.ir.holds.PlaceAction)

### an.ir.holds.release(item, , at=0.0, onto=None, arc=0.0, rotation=None, bounce=None)

Let `item` go at `at` (a drop; `onto: ground@x` to land there; `arc` > 0 to throw it up first).

```pycon
>>> release("musket", onto="ground@-620", arc=60).arc
60.0
>>> release("musket", onto="ground@-620").arc   # let fall: no rise
0.0
```

* **Return type:**
  [`ReleaseAction`](#an.ir.holds.ReleaseAction)

### an.ir.holds.swap(holder, , take, give, by, lag=0.25, rotation=None, reach=0.4, retract=0.35, lean=60.0, align=True)

`by` takes `take` from `holder`; `give` goes there in its place.

```pycon
>>> swap("nap/hand", take="musket", give="sword", by="stu@hand_r").give
'sword'
```

* **Return type:**
  [`SwapAction`](#an.ir.holds.SwapAction)
