Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,24 @@ Every quantity is a vector. Dimensionality of the *direction space* is part of t
| `IVector3<TSelf, T>` | 3D directional | Per-component | `Velocity3D`, `Force3D`, `Position3D` |
| `IVector4<TSelf, T>` | 4D directional | Per-component | (reserved for relativistic / spacetime) |

`IVectorN.Magnitude()` (for N >= 1) returns the corresponding `IVector0`.
`IVectorN.Magnitude()` (for N >= 1) returns the corresponding `IVector0`, and `DistanceTo(other)`
answers with the same type. Both are emitted onto every vector form, overloads included, and both
return the `vector0` **base** rather than one of its overloads — `Velocity3D.Magnitude()` is a
`Speed`, `Position3D.Magnitude()` is a `Length` and not a `Distance` — because the base is what
every overload widens from. A caller who wants the overload narrows explicitly.

The return type is written fully qualified in the generated source, which looks like noise and is
not: every vector form has a `Length()` method, so inside `Displacement3D`, whose magnitude form is
*called* `Length`, an unqualified `Length<T>` return type puts a method group and a generic type
under one identifier. It parses, because the type argument list disambiguates it — which is the
problem, since it compiles and then misleads the next reader.

`Length()` and `LengthSquared()` keep answering with a bare `T`, and the squared one has no typed
counterpart on purpose: the square of a dimension usually has no declared name, and where it has one
it is not unique, so there would be nothing to return. `Magnitude()` and `DistanceTo()` build with
`Create` rather than a `From{Unit}` factory, bypassing `Vector0Guards` — correct, because a value
that came out of a square root is non-negative by construction, and it keeps the guard off a call
that belongs in a hot loop.

All generated types are generic over a numeric storage type: `where T : struct, INumber<T>`.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,12 @@ namespace ktsu.Semantics.Quantities;
/// <summary>Gets the unit vector for the Y-axis.</summary>
public static Acceleration2D<T> UnitY => new() { X = T.Zero, Y = T.One };

/// <summary>Gets the magnitude as a <see cref="AccelerationMagnitude{T}"/>.</summary>
public AccelerationMagnitude<T> Magnitude() => AccelerationMagnitude<T>.Create(Length());
/// <summary>Gets the magnitude of this vector as a <see cref="global::ktsu.Semantics.Quantities.AccelerationMagnitude{T}"/>.</summary>
public global::ktsu.Semantics.Quantities.AccelerationMagnitude<T> Magnitude() => global::ktsu.Semantics.Quantities.AccelerationMagnitude<T>.Create(Length());

/// <summary>Gets the distance to another vector as a <see cref="global::ktsu.Semantics.Quantities.AccelerationMagnitude{T}"/>.</summary>
/// <param name="other">The vector to measure the distance to.</param>
public global::ktsu.Semantics.Quantities.AccelerationMagnitude<T> DistanceTo(Acceleration2D<T> other) => global::ktsu.Semantics.Quantities.AccelerationMagnitude<T>.Create(Distance(other));

/// <summary>Calculates the length of the vector.</summary>
public T Length()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,12 @@ namespace ktsu.Semantics.Quantities;
/// <summary>Gets the unit vector for the Z-axis.</summary>
public static Acceleration3D<T> UnitZ => new() { X = T.Zero, Y = T.Zero, Z = T.One };

/// <summary>Gets the magnitude as a <see cref="AccelerationMagnitude{T}"/>.</summary>
public AccelerationMagnitude<T> Magnitude() => AccelerationMagnitude<T>.Create(Length());
/// <summary>Gets the magnitude of this vector as a <see cref="global::ktsu.Semantics.Quantities.AccelerationMagnitude{T}"/>.</summary>
public global::ktsu.Semantics.Quantities.AccelerationMagnitude<T> Magnitude() => global::ktsu.Semantics.Quantities.AccelerationMagnitude<T>.Create(Length());

/// <summary>Gets the distance to another vector as a <see cref="global::ktsu.Semantics.Quantities.AccelerationMagnitude{T}"/>.</summary>
/// <param name="other">The vector to measure the distance to.</param>
public global::ktsu.Semantics.Quantities.AccelerationMagnitude<T> DistanceTo(Acceleration3D<T> other) => global::ktsu.Semantics.Quantities.AccelerationMagnitude<T>.Create(Distance(other));

/// <summary>Calculates the length of the vector.</summary>
public T Length()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,12 @@ namespace ktsu.Semantics.Quantities;
/// <summary>Gets the unit vector for the W-axis.</summary>
public static Acceleration4D<T> UnitW => new() { X = T.Zero, Y = T.Zero, Z = T.Zero, W = T.One };

/// <summary>Gets the magnitude as a <see cref="AccelerationMagnitude{T}"/>.</summary>
public AccelerationMagnitude<T> Magnitude() => AccelerationMagnitude<T>.Create(Length());
/// <summary>Gets the magnitude of this vector as a <see cref="global::ktsu.Semantics.Quantities.AccelerationMagnitude{T}"/>.</summary>
public global::ktsu.Semantics.Quantities.AccelerationMagnitude<T> Magnitude() => global::ktsu.Semantics.Quantities.AccelerationMagnitude<T>.Create(Length());

/// <summary>Gets the distance to another vector as a <see cref="global::ktsu.Semantics.Quantities.AccelerationMagnitude{T}"/>.</summary>
/// <param name="other">The vector to measure the distance to.</param>
public global::ktsu.Semantics.Quantities.AccelerationMagnitude<T> DistanceTo(Acceleration4D<T> other) => global::ktsu.Semantics.Quantities.AccelerationMagnitude<T>.Create(Distance(other));

/// <summary>Calculates the length of the vector.</summary>
public T Length()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,12 @@ namespace ktsu.Semantics.Quantities;
/// <summary>Gets the unit vector for the Z-axis.</summary>
public static AngularAcceleration3D<T> UnitZ => new() { X = T.Zero, Y = T.Zero, Z = T.One };

/// <summary>Gets the magnitude as a <see cref="AngularAccelerationMagnitude{T}"/>.</summary>
public AngularAccelerationMagnitude<T> Magnitude() => AngularAccelerationMagnitude<T>.Create(Length());
/// <summary>Gets the magnitude of this vector as a <see cref="global::ktsu.Semantics.Quantities.AngularAccelerationMagnitude{T}"/>.</summary>
public global::ktsu.Semantics.Quantities.AngularAccelerationMagnitude<T> Magnitude() => global::ktsu.Semantics.Quantities.AngularAccelerationMagnitude<T>.Create(Length());

/// <summary>Gets the distance to another vector as a <see cref="global::ktsu.Semantics.Quantities.AngularAccelerationMagnitude{T}"/>.</summary>
/// <param name="other">The vector to measure the distance to.</param>
public global::ktsu.Semantics.Quantities.AngularAccelerationMagnitude<T> DistanceTo(AngularAcceleration3D<T> other) => global::ktsu.Semantics.Quantities.AngularAccelerationMagnitude<T>.Create(Distance(other));

/// <summary>Calculates the length of the vector.</summary>
public T Length()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,12 @@ namespace ktsu.Semantics.Quantities;
/// <summary>Gets the unit vector for the Z-axis.</summary>
public static AngularDisplacement3D<T> UnitZ => new() { X = T.Zero, Y = T.Zero, Z = T.One };

/// <summary>Gets the magnitude as a <see cref="Angle{T}"/>.</summary>
public Angle<T> Magnitude() => Angle<T>.Create(Length());
/// <summary>Gets the magnitude of this vector as a <see cref="global::ktsu.Semantics.Quantities.Angle{T}"/>.</summary>
public global::ktsu.Semantics.Quantities.Angle<T> Magnitude() => global::ktsu.Semantics.Quantities.Angle<T>.Create(Length());

/// <summary>Gets the distance to another vector as a <see cref="global::ktsu.Semantics.Quantities.Angle{T}"/>.</summary>
/// <param name="other">The vector to measure the distance to.</param>
public global::ktsu.Semantics.Quantities.Angle<T> DistanceTo(AngularDisplacement3D<T> other) => global::ktsu.Semantics.Quantities.Angle<T>.Create(Distance(other));

/// <summary>Calculates the length of the vector.</summary>
public T Length()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,12 @@ namespace ktsu.Semantics.Quantities;
/// <summary>Gets the unit vector for the Z-axis.</summary>
public static AngularJerk3D<T> UnitZ => new() { X = T.Zero, Y = T.Zero, Z = T.One };

/// <summary>Gets the magnitude as a <see cref="AngularJerkMagnitude{T}"/>.</summary>
public AngularJerkMagnitude<T> Magnitude() => AngularJerkMagnitude<T>.Create(Length());
/// <summary>Gets the magnitude of this vector as a <see cref="global::ktsu.Semantics.Quantities.AngularJerkMagnitude{T}"/>.</summary>
public global::ktsu.Semantics.Quantities.AngularJerkMagnitude<T> Magnitude() => global::ktsu.Semantics.Quantities.AngularJerkMagnitude<T>.Create(Length());

/// <summary>Gets the distance to another vector as a <see cref="global::ktsu.Semantics.Quantities.AngularJerkMagnitude{T}"/>.</summary>
/// <param name="other">The vector to measure the distance to.</param>
public global::ktsu.Semantics.Quantities.AngularJerkMagnitude<T> DistanceTo(AngularJerk3D<T> other) => global::ktsu.Semantics.Quantities.AngularJerkMagnitude<T>.Create(Distance(other));

/// <summary>Calculates the length of the vector.</summary>
public T Length()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,12 @@ namespace ktsu.Semantics.Quantities;
/// <summary>Gets the unit vector for the Z-axis.</summary>
public static AngularMomentum3D<T> UnitZ => new() { X = T.Zero, Y = T.Zero, Z = T.One };

/// <summary>Gets the magnitude as a <see cref="AngularMomentumMagnitude{T}"/>.</summary>
public AngularMomentumMagnitude<T> Magnitude() => AngularMomentumMagnitude<T>.Create(Length());
/// <summary>Gets the magnitude of this vector as a <see cref="global::ktsu.Semantics.Quantities.AngularMomentumMagnitude{T}"/>.</summary>
public global::ktsu.Semantics.Quantities.AngularMomentumMagnitude<T> Magnitude() => global::ktsu.Semantics.Quantities.AngularMomentumMagnitude<T>.Create(Length());

/// <summary>Gets the distance to another vector as a <see cref="global::ktsu.Semantics.Quantities.AngularMomentumMagnitude{T}"/>.</summary>
/// <param name="other">The vector to measure the distance to.</param>
public global::ktsu.Semantics.Quantities.AngularMomentumMagnitude<T> DistanceTo(AngularMomentum3D<T> other) => global::ktsu.Semantics.Quantities.AngularMomentumMagnitude<T>.Create(Distance(other));

/// <summary>Calculates the length of the vector.</summary>
public T Length()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,12 @@ namespace ktsu.Semantics.Quantities;
/// <summary>Gets the unit vector for the Z-axis.</summary>
public static AngularVelocity3D<T> UnitZ => new() { X = T.Zero, Y = T.Zero, Z = T.One };

/// <summary>Gets the magnitude as a <see cref="AngularSpeed{T}"/>.</summary>
public AngularSpeed<T> Magnitude() => AngularSpeed<T>.Create(Length());
/// <summary>Gets the magnitude of this vector as a <see cref="global::ktsu.Semantics.Quantities.AngularSpeed{T}"/>.</summary>
public global::ktsu.Semantics.Quantities.AngularSpeed<T> Magnitude() => global::ktsu.Semantics.Quantities.AngularSpeed<T>.Create(Length());

/// <summary>Gets the distance to another vector as a <see cref="global::ktsu.Semantics.Quantities.AngularSpeed{T}"/>.</summary>
/// <param name="other">The vector to measure the distance to.</param>
public global::ktsu.Semantics.Quantities.AngularSpeed<T> DistanceTo(AngularVelocity3D<T> other) => global::ktsu.Semantics.Quantities.AngularSpeed<T>.Create(Distance(other));

/// <summary>Calculates the length of the vector.</summary>
public T Length()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,12 @@ namespace ktsu.Semantics.Quantities;
/// <summary>Gets the unit vector for the Z-axis.</summary>
public static Current3D<T> UnitZ => new() { X = T.Zero, Y = T.Zero, Z = T.One };

/// <summary>Gets the magnitude as a <see cref="CurrentMagnitude{T}"/>.</summary>
public CurrentMagnitude<T> Magnitude() => CurrentMagnitude<T>.Create(Length());
/// <summary>Gets the magnitude of this vector as a <see cref="global::ktsu.Semantics.Quantities.CurrentMagnitude{T}"/>.</summary>
public global::ktsu.Semantics.Quantities.CurrentMagnitude<T> Magnitude() => global::ktsu.Semantics.Quantities.CurrentMagnitude<T>.Create(Length());

/// <summary>Gets the distance to another vector as a <see cref="global::ktsu.Semantics.Quantities.CurrentMagnitude{T}"/>.</summary>
/// <param name="other">The vector to measure the distance to.</param>
public global::ktsu.Semantics.Quantities.CurrentMagnitude<T> DistanceTo(Current3D<T> other) => global::ktsu.Semantics.Quantities.CurrentMagnitude<T>.Create(Distance(other));

/// <summary>Calculates the length of the vector.</summary>
public T Length()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,12 @@ namespace ktsu.Semantics.Quantities;
/// <summary>Gets the unit vector for the Y-axis.</summary>
public static Displacement2D<T> UnitY => new() { X = T.Zero, Y = T.One };

/// <summary>Gets the magnitude as a <see cref="Length{T}"/>.</summary>
public Length<T> Magnitude() => Length<T>.Create(Length());
/// <summary>Gets the magnitude of this vector as a <see cref="global::ktsu.Semantics.Quantities.Length{T}"/>.</summary>
public global::ktsu.Semantics.Quantities.Length<T> Magnitude() => global::ktsu.Semantics.Quantities.Length<T>.Create(Length());

/// <summary>Gets the distance to another vector as a <see cref="global::ktsu.Semantics.Quantities.Length{T}"/>.</summary>
/// <param name="other">The vector to measure the distance to.</param>
public global::ktsu.Semantics.Quantities.Length<T> DistanceTo(Displacement2D<T> other) => global::ktsu.Semantics.Quantities.Length<T>.Create(Distance(other));

/// <summary>Calculates the length of the vector.</summary>
public T Length()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,12 @@ namespace ktsu.Semantics.Quantities;
/// <summary>Gets the unit vector for the Z-axis.</summary>
public static Displacement3D<T> UnitZ => new() { X = T.Zero, Y = T.Zero, Z = T.One };

/// <summary>Gets the magnitude as a <see cref="Length{T}"/>.</summary>
public Length<T> Magnitude() => Length<T>.Create(Length());
/// <summary>Gets the magnitude of this vector as a <see cref="global::ktsu.Semantics.Quantities.Length{T}"/>.</summary>
public global::ktsu.Semantics.Quantities.Length<T> Magnitude() => global::ktsu.Semantics.Quantities.Length<T>.Create(Length());

/// <summary>Gets the distance to another vector as a <see cref="global::ktsu.Semantics.Quantities.Length{T}"/>.</summary>
/// <param name="other">The vector to measure the distance to.</param>
public global::ktsu.Semantics.Quantities.Length<T> DistanceTo(Displacement3D<T> other) => global::ktsu.Semantics.Quantities.Length<T>.Create(Distance(other));

/// <summary>Calculates the length of the vector.</summary>
public T Length()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,12 @@ namespace ktsu.Semantics.Quantities;
/// <summary>Gets the unit vector for the W-axis.</summary>
public static Displacement4D<T> UnitW => new() { X = T.Zero, Y = T.Zero, Z = T.Zero, W = T.One };

/// <summary>Gets the magnitude as a <see cref="Length{T}"/>.</summary>
public Length<T> Magnitude() => Length<T>.Create(Length());
/// <summary>Gets the magnitude of this vector as a <see cref="global::ktsu.Semantics.Quantities.Length{T}"/>.</summary>
public global::ktsu.Semantics.Quantities.Length<T> Magnitude() => global::ktsu.Semantics.Quantities.Length<T>.Create(Length());

/// <summary>Gets the distance to another vector as a <see cref="global::ktsu.Semantics.Quantities.Length{T}"/>.</summary>
/// <param name="other">The vector to measure the distance to.</param>
public global::ktsu.Semantics.Quantities.Length<T> DistanceTo(Displacement4D<T> other) => global::ktsu.Semantics.Quantities.Length<T>.Create(Distance(other));

/// <summary>Calculates the length of the vector.</summary>
public T Length()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,12 @@ namespace ktsu.Semantics.Quantities;
/// <summary>Gets the unit vector for the Y-axis.</summary>
public static ElectricField2D<T> UnitY => new() { X = T.Zero, Y = T.One };

/// <summary>Gets the magnitude as a <see cref="ElectricFieldMagnitude{T}"/>.</summary>
public ElectricFieldMagnitude<T> Magnitude() => ElectricFieldMagnitude<T>.Create(Length());
/// <summary>Gets the magnitude of this vector as a <see cref="global::ktsu.Semantics.Quantities.ElectricFieldMagnitude{T}"/>.</summary>
public global::ktsu.Semantics.Quantities.ElectricFieldMagnitude<T> Magnitude() => global::ktsu.Semantics.Quantities.ElectricFieldMagnitude<T>.Create(Length());

/// <summary>Gets the distance to another vector as a <see cref="global::ktsu.Semantics.Quantities.ElectricFieldMagnitude{T}"/>.</summary>
/// <param name="other">The vector to measure the distance to.</param>
public global::ktsu.Semantics.Quantities.ElectricFieldMagnitude<T> DistanceTo(ElectricField2D<T> other) => global::ktsu.Semantics.Quantities.ElectricFieldMagnitude<T>.Create(Distance(other));

/// <summary>Calculates the length of the vector.</summary>
public T Length()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,12 @@ namespace ktsu.Semantics.Quantities;
/// <summary>Gets the unit vector for the Z-axis.</summary>
public static ElectricField3D<T> UnitZ => new() { X = T.Zero, Y = T.Zero, Z = T.One };

/// <summary>Gets the magnitude as a <see cref="ElectricFieldMagnitude{T}"/>.</summary>
public ElectricFieldMagnitude<T> Magnitude() => ElectricFieldMagnitude<T>.Create(Length());
/// <summary>Gets the magnitude of this vector as a <see cref="global::ktsu.Semantics.Quantities.ElectricFieldMagnitude{T}"/>.</summary>
public global::ktsu.Semantics.Quantities.ElectricFieldMagnitude<T> Magnitude() => global::ktsu.Semantics.Quantities.ElectricFieldMagnitude<T>.Create(Length());

/// <summary>Gets the distance to another vector as a <see cref="global::ktsu.Semantics.Quantities.ElectricFieldMagnitude{T}"/>.</summary>
/// <param name="other">The vector to measure the distance to.</param>
public global::ktsu.Semantics.Quantities.ElectricFieldMagnitude<T> DistanceTo(ElectricField3D<T> other) => global::ktsu.Semantics.Quantities.ElectricFieldMagnitude<T>.Create(Distance(other));

/// <summary>Calculates the length of the vector.</summary>
public T Length()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,12 @@ namespace ktsu.Semantics.Quantities;
/// <summary>Gets the unit vector for the Y-axis.</summary>
public static Force2D<T> UnitY => new() { X = T.Zero, Y = T.One };

/// <summary>Gets the magnitude as a <see cref="ForceMagnitude{T}"/>.</summary>
public ForceMagnitude<T> Magnitude() => ForceMagnitude<T>.Create(Length());
/// <summary>Gets the magnitude of this vector as a <see cref="global::ktsu.Semantics.Quantities.ForceMagnitude{T}"/>.</summary>
public global::ktsu.Semantics.Quantities.ForceMagnitude<T> Magnitude() => global::ktsu.Semantics.Quantities.ForceMagnitude<T>.Create(Length());

/// <summary>Gets the distance to another vector as a <see cref="global::ktsu.Semantics.Quantities.ForceMagnitude{T}"/>.</summary>
/// <param name="other">The vector to measure the distance to.</param>
public global::ktsu.Semantics.Quantities.ForceMagnitude<T> DistanceTo(Force2D<T> other) => global::ktsu.Semantics.Quantities.ForceMagnitude<T>.Create(Distance(other));

/// <summary>Calculates the length of the vector.</summary>
public T Length()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,12 @@ namespace ktsu.Semantics.Quantities;
/// <summary>Gets the unit vector for the Z-axis.</summary>
public static Force3D<T> UnitZ => new() { X = T.Zero, Y = T.Zero, Z = T.One };

/// <summary>Gets the magnitude as a <see cref="ForceMagnitude{T}"/>.</summary>
public ForceMagnitude<T> Magnitude() => ForceMagnitude<T>.Create(Length());
/// <summary>Gets the magnitude of this vector as a <see cref="global::ktsu.Semantics.Quantities.ForceMagnitude{T}"/>.</summary>
public global::ktsu.Semantics.Quantities.ForceMagnitude<T> Magnitude() => global::ktsu.Semantics.Quantities.ForceMagnitude<T>.Create(Length());

/// <summary>Gets the distance to another vector as a <see cref="global::ktsu.Semantics.Quantities.ForceMagnitude{T}"/>.</summary>
/// <param name="other">The vector to measure the distance to.</param>
public global::ktsu.Semantics.Quantities.ForceMagnitude<T> DistanceTo(Force3D<T> other) => global::ktsu.Semantics.Quantities.ForceMagnitude<T>.Create(Distance(other));

/// <summary>Calculates the length of the vector.</summary>
public T Length()
Expand Down
Loading
Loading