# Migrating From v0.7 to `main`

This file contains migration guides for breaking changes that have happened on the `main` branch
since the latest release. These guides are evolving and may not be polished yet.

See [migration-guides/README.md](./README.md) and existing entries for information about Avian's
migration guide process and what to put here.

## Double-Precision (`f64`)

Past versions of Avian switched almost all internals and APIs to double-precision
when the `f64` feature is enabled. **Avian 0.8** reworks the double-precision mode
to only use `f64` types for world-space coordinates (rigid body and collider positions,
ray and shape cast origins, world-space points, etc.) while internals remain in single-precision.
This improves performance and simplifies internals, while still supporting distances
far from the origin.

Additionally:

- The `f32` feature has been removed; it is now the default unless `f64` is enabled
- `Scalar` has been renamed to `Real`
- `Vector` has been renamed to `RVector`
- `Vector2`, `Vector3`, `Matrix2`, and `Matrix3` have been renamed to `RVec2`, `RVec3`, `RMat2`, and `RMat3`
- `Matrix`, `SymmetricMatrix`, `SymmetricMatrix2`, `SymmetricMatrix3`, and `Quaternion` have been removed
- `AdjustPrecision` has been renamed to `ToRealPrecision`
- `AsF32` has been renamed to `ToF32Precision`

## Continuous Collision Detection (CCD)

**Avian 0.8** overhauls the Continuous Collision Detection (CCD) algorithm.
This involves some breaking changes.

### Swept CCD

Sweep-based CCD is now enabled by default for fast-moving dynamic bodies,
but only against static and kinematic bodies. It can be configured using
the `SweptCcd` component.

`SweptCcd::include_dynamic` has been replaced by `SweptCcd::filter` bitflags.
The `linear_threshold` and `angular_threshold` properties have also been
replaced by a single `threshold`, which is now the fraction of a body's
minimum "CCD thickness" that it may safely travel in a timestep before
being treated as a fast-moving body.

`new_with_mode` has also been removed in favor of `new` and `with_mode`,
`with_velocity_threshold` has been removed in favor of `with_threshold`,
and `include_dynamic` has been removed in favor of `with_filter`.

The `SweptCcdSystem` system set has been replaced by `SolverSystems::ContinuousCollision`.

### Speculative CCD

Pure speculative collision is no longer enabled by default.
It can be opted into using the `SpeculativeCcd` component
(previously `SpeculativeMargin`).

`NarrowPhaseConfig::default_speculative_margin` has been removed.

### Plugins

A new `BodySizeMetricsPlugin<C: AnyCollider>` plugin has been added.
It is included in `PhysicsPlugins` for the default `Collider` type,
but apps using a custom collider type may want to add it manually.

## Collider Context

Collider context types have undergone some renames:

- `AabbContext` → `ColliderContext`
    - `entity` → `collider`
    - `fake()` → `NO_CONTEXT`
- `ContactManifoldContext` → `ColliderPairContext`
    - `entity1` → `collider1`
    - `entity2` → `collider2`
    - `fake()` → `NO_CONTEXT`

## Collision Detection and Solver Decoupling

Avian's collision detection and solver have been refactored to be significantly less coupled.
This involved some breaking changes:

- `dynamics::solver::joint_graph` is now `dynamics::joints::joint_graph`
- `ContactEdge::constraint_handles` has been moved to a `ConstraintGraph::contact_handles` list
- `ContactEdge::island` has been moved to a `PhysicsIslands::contact_nodes` list
- `JointGraphEdge::island` has been moved to a `PhysicsIslands::joint_nodes` list
- `NarrowPhasePlugin::new` no longer has a `generate_constraints` argument

Additionally, the constraint graph and islands are no longer updated immediately
after despawning colliders or bodies. If they must be made consistent instantly,
consider using the `FlushContactStatusChangesQueue` command.

## Solver

Each `SolverBody` and `SolverBodyInertia` associated with awake dynamic and kinematic bodies
is now stored in a `SolverBodies` resource instead of a component on the entity. The index
of the solver body associated with a given entity is stored in the `SolverBodyIndex` component.

## Collider Tree Optimization

`ColliderTreeOptimization::use_async_tasks` has been renamed to `ColliderTreeOptimization::use_compute_task`,
as tree optimization is now run as a single task on the `ComputeTaskPool`.
