Collapse CultVec2, CultVec3 and CultRect into CultMath float2, float3 and rect
GameCult.Geometry no longer carries vector or rectangle values. CultCircle and CultSphere hold float2/float3, the isosurface and surface-nets extractors take float3 origin, and the per-call conversion to float3 is gone. Their MessagePack bytes are unchanged (pinned against the pre-collapse encodings), now produced by CultMathResolver through the default CultCache options. This is a breaking change to the GameCult.Geometry public API. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
parent
14621b3893
commit
20ac3b0b6c
8 changed files with 95 additions and 298 deletions
|
|
@ -9,6 +9,7 @@ format for the attribute-first `GameCult.Caching` stack.
|
|||
- `CultDocumentMessagePackSerialization`
|
||||
- `CultDocumentResolver`
|
||||
- `CultRecordRefFormatter<T>`
|
||||
- `CultMathResolver`: the canonical component-array encoding of every public CultMath value type, part of the default resolver chain
|
||||
|
||||
Cult document payloads serialize through `MessagePackSerializer` with the
|
||||
options of the document's assembly (`CultDocumentMessagePackSerialization.OptionsFor`),
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ namespace GameCult.Geometry
|
|||
public static CultGeometryTriangleMesh Extract(
|
||||
float[,,] samples,
|
||||
float isoValue = 0f,
|
||||
CultVec3 origin = default,
|
||||
float3 origin = default,
|
||||
float cellSize = 1f)
|
||||
{
|
||||
if (samples == null) throw new ArgumentNullException(nameof(samples));
|
||||
|
|
@ -56,7 +56,6 @@ namespace GameCult.Geometry
|
|||
var positions = new List<float>();
|
||||
var normals = new List<float>();
|
||||
var indices = new List<uint>();
|
||||
var originValue = new float3(origin.X, origin.Y, origin.Z);
|
||||
var cornerPositions = new float3[8];
|
||||
var cornerValues = new float[8];
|
||||
var tetraPositions = new float3[4];
|
||||
|
|
@ -66,7 +65,7 @@ namespace GameCult.Geometry
|
|||
for (var y = 0; y < samples.GetLength(1) - 1; y++)
|
||||
for (var z = 0; z < samples.GetLength(2) - 1; z++)
|
||||
{
|
||||
var cubeOrigin = originValue + new float3(x, y, z) * cellSize;
|
||||
var cubeOrigin = origin + new float3(x, y, z) * cellSize;
|
||||
for (var corner = 0; corner < CubeCorners.Length; corner++)
|
||||
{
|
||||
var offset = CubeCorners[corner];
|
||||
|
|
|
|||
|
|
@ -1,197 +1,10 @@
|
|||
using System;
|
||||
using System.Text.Json.Serialization;
|
||||
using CultMath;
|
||||
using MessagePack;
|
||||
|
||||
namespace GameCult.Geometry
|
||||
{
|
||||
/// <summary>
|
||||
/// Deterministic two-dimensional float vector for cross-runtime geometry and query contracts.
|
||||
/// </summary>
|
||||
[MessagePackObject]
|
||||
public readonly struct CultVec2 : IEquatable<CultVec2>
|
||||
{
|
||||
/// <summary>Creates a two-dimensional vector.</summary>
|
||||
public CultVec2(float x, float y)
|
||||
{
|
||||
X = x;
|
||||
Y = y;
|
||||
}
|
||||
|
||||
/// <summary>Gets the x component.</summary>
|
||||
[Key(0)]
|
||||
public float X { get; }
|
||||
|
||||
/// <summary>Gets the y component.</summary>
|
||||
[Key(1)]
|
||||
public float Y { get; }
|
||||
|
||||
/// <summary>Gets the zero vector.</summary>
|
||||
[IgnoreMember]
|
||||
[JsonIgnore]
|
||||
public static CultVec2 Zero => new(0f, 0f);
|
||||
|
||||
/// <summary>Gets the squared vector length.</summary>
|
||||
[IgnoreMember]
|
||||
[JsonIgnore]
|
||||
public float LengthSquared => (X * X) + (Y * Y);
|
||||
|
||||
/// <summary>Returns whether this vector is equal to another vector.</summary>
|
||||
public bool Equals(CultVec2 other) => X.Equals(other.X) && Y.Equals(other.Y);
|
||||
|
||||
/// <inheritdoc />
|
||||
public override bool Equals(object? obj) => obj is CultVec2 other && Equals(other);
|
||||
|
||||
/// <inheritdoc />
|
||||
public override int GetHashCode() => HashCode.Combine(X, Y);
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string ToString() => $"({X}, {Y})";
|
||||
|
||||
public static CultVec2 operator +(CultVec2 left, CultVec2 right) => new(left.X + right.X, left.Y + right.Y);
|
||||
public static CultVec2 operator -(CultVec2 left, CultVec2 right) => new(left.X - right.X, left.Y - right.Y);
|
||||
public static CultVec2 operator *(CultVec2 value, float scalar) => new(value.X * scalar, value.Y * scalar);
|
||||
public static CultVec2 operator /(CultVec2 value, float scalar) => new(value.X / scalar, value.Y / scalar);
|
||||
public static bool operator ==(CultVec2 left, CultVec2 right) => left.Equals(right);
|
||||
public static bool operator !=(CultVec2 left, CultVec2 right) => !left.Equals(right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deterministic three-dimensional float vector for cross-runtime geometry and query contracts.
|
||||
/// </summary>
|
||||
[MessagePackObject]
|
||||
public readonly struct CultVec3 : IEquatable<CultVec3>
|
||||
{
|
||||
/// <summary>Creates a three-dimensional vector.</summary>
|
||||
public CultVec3(float x, float y, float z)
|
||||
{
|
||||
X = x;
|
||||
Y = y;
|
||||
Z = z;
|
||||
}
|
||||
|
||||
/// <summary>Gets the x component.</summary>
|
||||
[Key(0)]
|
||||
public float X { get; }
|
||||
|
||||
/// <summary>Gets the y component.</summary>
|
||||
[Key(1)]
|
||||
public float Y { get; }
|
||||
|
||||
/// <summary>Gets the z component.</summary>
|
||||
[Key(2)]
|
||||
public float Z { get; }
|
||||
|
||||
/// <summary>Gets the zero vector.</summary>
|
||||
[IgnoreMember]
|
||||
[JsonIgnore]
|
||||
public static CultVec3 Zero => new(0f, 0f, 0f);
|
||||
|
||||
/// <summary>Gets the XY plane projection.</summary>
|
||||
[IgnoreMember]
|
||||
[JsonIgnore]
|
||||
public CultVec2 Xy => new(X, Y);
|
||||
|
||||
/// <summary>Gets the XZ plane projection for Unity compatibility adapters.</summary>
|
||||
[IgnoreMember]
|
||||
[JsonIgnore]
|
||||
public CultVec2 Xz => new(X, Z);
|
||||
|
||||
/// <summary>Gets the squared vector length.</summary>
|
||||
[IgnoreMember]
|
||||
[JsonIgnore]
|
||||
public float LengthSquared => (X * X) + (Y * Y) + (Z * Z);
|
||||
|
||||
/// <summary>Returns whether this vector is equal to another vector.</summary>
|
||||
public bool Equals(CultVec3 other) => X.Equals(other.X) && Y.Equals(other.Y) && Z.Equals(other.Z);
|
||||
|
||||
/// <inheritdoc />
|
||||
public override bool Equals(object? obj) => obj is CultVec3 other && Equals(other);
|
||||
|
||||
/// <inheritdoc />
|
||||
public override int GetHashCode() => HashCode.Combine(X, Y, Z);
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string ToString() => $"({X}, {Y}, {Z})";
|
||||
|
||||
public static CultVec3 operator +(CultVec3 left, CultVec3 right) => new(left.X + right.X, left.Y + right.Y, left.Z + right.Z);
|
||||
public static CultVec3 operator -(CultVec3 left, CultVec3 right) => new(left.X - right.X, left.Y - right.Y, left.Z - right.Z);
|
||||
public static CultVec3 operator *(CultVec3 value, float scalar) => new(value.X * scalar, value.Y * scalar, value.Z * scalar);
|
||||
public static CultVec3 operator /(CultVec3 value, float scalar) => new(value.X / scalar, value.Y / scalar, value.Z / scalar);
|
||||
public static bool operator ==(CultVec3 left, CultVec3 right) => left.Equals(right);
|
||||
public static bool operator !=(CultVec3 left, CultVec3 right) => !left.Equals(right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Axis-aligned two-dimensional rectangle represented by canonical min and max corners.
|
||||
/// </summary>
|
||||
[MessagePackObject]
|
||||
public readonly struct CultRect : IEquatable<CultRect>
|
||||
{
|
||||
/// <summary>Creates a rectangle and canonicalizes min/max corners.</summary>
|
||||
public CultRect(CultVec2 min, CultVec2 max)
|
||||
{
|
||||
Min = new CultVec2(Math.Min(min.X, max.X), Math.Min(min.Y, max.Y));
|
||||
Max = new CultVec2(Math.Max(min.X, max.X), Math.Max(min.Y, max.Y));
|
||||
}
|
||||
|
||||
/// <summary>Creates a rectangle and canonicalizes min/max corners.</summary>
|
||||
public CultRect(float minX, float minY, float maxX, float maxY)
|
||||
: this(new CultVec2(minX, minY), new CultVec2(maxX, maxY))
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>Gets the canonical minimum corner.</summary>
|
||||
[Key(0)]
|
||||
public CultVec2 Min { get; }
|
||||
|
||||
/// <summary>Gets the canonical maximum corner.</summary>
|
||||
[Key(1)]
|
||||
public CultVec2 Max { get; }
|
||||
|
||||
/// <summary>Gets the rectangle size.</summary>
|
||||
[IgnoreMember]
|
||||
[JsonIgnore]
|
||||
public CultVec2 Size => Max - Min;
|
||||
|
||||
/// <summary>Gets the rectangle center.</summary>
|
||||
[IgnoreMember]
|
||||
[JsonIgnore]
|
||||
public CultVec2 Center => (Min + Max) * 0.5f;
|
||||
|
||||
/// <summary>Returns whether the point lies inside or on the rectangle edge.</summary>
|
||||
public bool Contains(CultVec2 point)
|
||||
{
|
||||
return point.X >= Min.X &&
|
||||
point.X <= Max.X &&
|
||||
point.Y >= Min.Y &&
|
||||
point.Y <= Max.Y;
|
||||
}
|
||||
|
||||
/// <summary>Returns whether this rectangle intersects another rectangle.</summary>
|
||||
public bool Intersects(CultRect other)
|
||||
{
|
||||
return Min.X <= other.Max.X &&
|
||||
Max.X >= other.Min.X &&
|
||||
Min.Y <= other.Max.Y &&
|
||||
Max.Y >= other.Min.Y;
|
||||
}
|
||||
|
||||
/// <summary>Returns whether this rectangle is equal to another rectangle.</summary>
|
||||
public bool Equals(CultRect other) => Min == other.Min && Max == other.Max;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override bool Equals(object? obj) => obj is CultRect other && Equals(other);
|
||||
|
||||
/// <inheritdoc />
|
||||
public override int GetHashCode() => HashCode.Combine(Min, Max);
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string ToString() => $"[{Min}..{Max}]";
|
||||
|
||||
public static bool operator ==(CultRect left, CultRect right) => left.Equals(right);
|
||||
public static bool operator !=(CultRect left, CultRect right) => !left.Equals(right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Two-dimensional circle for spatial queries.
|
||||
/// </summary>
|
||||
|
|
@ -199,7 +12,7 @@ namespace GameCult.Geometry
|
|||
public readonly struct CultCircle : IEquatable<CultCircle>
|
||||
{
|
||||
/// <summary>Creates a circle.</summary>
|
||||
public CultCircle(CultVec2 center, float radius)
|
||||
public CultCircle(float2 center, float radius)
|
||||
{
|
||||
if (radius < 0f)
|
||||
{
|
||||
|
|
@ -212,7 +25,7 @@ namespace GameCult.Geometry
|
|||
|
||||
/// <summary>Gets the circle center.</summary>
|
||||
[Key(0)]
|
||||
public CultVec2 Center { get; }
|
||||
public float2 Center { get; }
|
||||
|
||||
/// <summary>Gets the circle radius.</summary>
|
||||
[Key(1)]
|
||||
|
|
@ -221,29 +34,29 @@ namespace GameCult.Geometry
|
|||
/// <summary>Gets the circle bounds.</summary>
|
||||
[IgnoreMember]
|
||||
[JsonIgnore]
|
||||
public CultRect Bounds => new(
|
||||
Center.X - Radius,
|
||||
Center.Y - Radius,
|
||||
Center.X + Radius,
|
||||
Center.Y + Radius);
|
||||
public rect Bounds => new(
|
||||
Center.x - Radius,
|
||||
Center.y - Radius,
|
||||
Center.x + Radius,
|
||||
Center.y + Radius);
|
||||
|
||||
/// <summary>Returns whether the point lies inside or on the circle edge.</summary>
|
||||
public bool Contains(CultVec2 point)
|
||||
public bool Contains(float2 point)
|
||||
{
|
||||
var delta = point - Center;
|
||||
return delta.LengthSquared <= Radius * Radius;
|
||||
return math.lengthsq(delta) <= Radius * Radius;
|
||||
}
|
||||
|
||||
/// <summary>Returns whether this circle intersects a rectangle.</summary>
|
||||
public bool Intersects(CultRect rect)
|
||||
public bool Intersects(rect rect)
|
||||
{
|
||||
var clampedX = Math.Max(rect.Min.X, Math.Min(Center.X, rect.Max.X));
|
||||
var clampedY = Math.Max(rect.Min.Y, Math.Min(Center.Y, rect.Max.Y));
|
||||
return Contains(new CultVec2(clampedX, clampedY));
|
||||
var clampedX = Math.Max(rect.min.x, Math.Min(Center.x, rect.max.x));
|
||||
var clampedY = Math.Max(rect.min.y, Math.Min(Center.y, rect.max.y));
|
||||
return Contains(new float2(clampedX, clampedY));
|
||||
}
|
||||
|
||||
/// <summary>Returns whether this circle is equal to another circle.</summary>
|
||||
public bool Equals(CultCircle other) => Center == other.Center && Radius.Equals(other.Radius);
|
||||
public bool Equals(CultCircle other) => Center.Equals(other.Center) && Radius.Equals(other.Radius);
|
||||
|
||||
/// <inheritdoc />
|
||||
public override bool Equals(object? obj) => obj is CultCircle other && Equals(other);
|
||||
|
|
@ -262,7 +75,7 @@ namespace GameCult.Geometry
|
|||
public readonly struct CultSphere : IEquatable<CultSphere>
|
||||
{
|
||||
/// <summary>Creates a sphere.</summary>
|
||||
public CultSphere(CultVec3 center, float radius)
|
||||
public CultSphere(float3 center, float radius)
|
||||
{
|
||||
if (radius < 0f)
|
||||
{
|
||||
|
|
@ -275,7 +88,7 @@ namespace GameCult.Geometry
|
|||
|
||||
/// <summary>Gets the sphere center.</summary>
|
||||
[Key(0)]
|
||||
public CultVec3 Center { get; }
|
||||
public float3 Center { get; }
|
||||
|
||||
/// <summary>Gets the sphere radius.</summary>
|
||||
[Key(1)]
|
||||
|
|
@ -284,17 +97,17 @@ namespace GameCult.Geometry
|
|||
/// <summary>Gets the XY circle projection.</summary>
|
||||
[IgnoreMember]
|
||||
[JsonIgnore]
|
||||
public CultCircle XyCircle => new(Center.Xy, Radius);
|
||||
public CultCircle XyCircle => new(Center.xy, Radius);
|
||||
|
||||
/// <summary>Returns whether the point lies inside or on the sphere surface.</summary>
|
||||
public bool Contains(CultVec3 point)
|
||||
public bool Contains(float3 point)
|
||||
{
|
||||
var delta = point - Center;
|
||||
return delta.LengthSquared <= Radius * Radius;
|
||||
return math.lengthsq(delta) <= Radius * Radius;
|
||||
}
|
||||
|
||||
/// <summary>Returns whether this sphere is equal to another sphere.</summary>
|
||||
public bool Equals(CultSphere other) => Center == other.Center && Radius.Equals(other.Radius);
|
||||
public bool Equals(CultSphere other) => Center.Equals(other.Center) && Radius.Equals(other.Radius);
|
||||
|
||||
/// <inheritdoc />
|
||||
public override bool Equals(object? obj) => obj is CultSphere other && Equals(other);
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ namespace GameCult.Geometry
|
|||
public static CultGeometryQuadMesh Extract(
|
||||
float[,,] samples,
|
||||
float isoValue = 0f,
|
||||
CultVec3 origin = default,
|
||||
float3 origin = default,
|
||||
float cellSize = 1f)
|
||||
{
|
||||
if (samples == null) throw new ArgumentNullException(nameof(samples));
|
||||
|
|
@ -66,7 +66,7 @@ namespace GameCult.Geometry
|
|||
throw new ArgumentException("The isovalue must be finite.", nameof(isoValue));
|
||||
}
|
||||
|
||||
if (!float.IsFinite(origin.X) || !float.IsFinite(origin.Y) || !float.IsFinite(origin.Z))
|
||||
if (!float.IsFinite(origin.x) || !float.IsFinite(origin.y) || !float.IsFinite(origin.z))
|
||||
{
|
||||
throw new ArgumentException("The origin must be finite.", nameof(origin));
|
||||
}
|
||||
|
|
@ -80,7 +80,6 @@ namespace GameCult.Geometry
|
|||
var sizeY = samples.GetLength(1);
|
||||
var sizeZ = samples.GetLength(2);
|
||||
var cellCounts = new[] { sizeX - 1, sizeY - 1, sizeZ - 1 };
|
||||
var originValue = new float3(origin.X, origin.Y, origin.Z);
|
||||
|
||||
var vertexIndex = new Dictionary<(int, int, int), uint>();
|
||||
var positions = new List<float>();
|
||||
|
|
@ -90,7 +89,7 @@ namespace GameCult.Geometry
|
|||
for (var cz = 0; cz < cellCounts[2]; cz++)
|
||||
{
|
||||
var cellCoord = new[] { cx, cy, cz };
|
||||
var vertex = CellVertex(samples, cellCoord, isoValue, originValue, cellSize);
|
||||
var vertex = CellVertex(samples, cellCoord, isoValue, origin, cellSize);
|
||||
if (vertex == null) continue;
|
||||
|
||||
vertexIndex[(cx, cy, cz)] = (uint)(positions.Count / 3);
|
||||
|
|
|
|||
|
|
@ -31,12 +31,9 @@ The package is deliberately substrate-shaped:
|
|||
## Value Primitives
|
||||
|
||||
The small value layer is for cross-runtime query contracts, physics probes,
|
||||
native slices, and UI surfaces:
|
||||
native slices, and UI surfaces. Vectors and rectangles are CultMath's `float2`,
|
||||
`float3` and `rect`, and `GameCult.Caching.MessagePack` serializes them.
|
||||
|
||||
- `CultVec2` and `CultVec3`: whole-vector values for positions, velocities,
|
||||
accelerations, and query inputs. SoA layouts may store them efficiently, but
|
||||
the semantic API does not force callers to split x/y/z into unrelated fields.
|
||||
- `CultRect`: canonical XY viewport/query rectangle stored as min/max corners.
|
||||
- `CultCircle`: 2D influence/query brush with rect intersection helpers.
|
||||
- `CultSphere`: 3D query primitive with whole-vector center and XY projection.
|
||||
|
||||
|
|
@ -85,8 +82,8 @@ cache miss; that is split-brain geometry.
|
|||
|
||||
## Documents
|
||||
|
||||
- `CultVec2`, `CultVec3`, `CultRect`, `CultCircle`, `CultSphere`: shared value
|
||||
primitives for query and view contracts.
|
||||
- `CultCircle`, `CultSphere`: shared value primitives for query and view
|
||||
contracts.
|
||||
- `CultGeometryDomainDocument`: one hierarchical domain tree, suitable for
|
||||
Ragnarok/Fensalir-style feature DSL output.
|
||||
- `CultGeometryBuildRequest`: one LOD/frustum/budget request for workers.
|
||||
|
|
|
|||
Loading…
Reference in a new issue