Add canonical System.Text.Json converters for every CultMath value type
CultMathJson is the JSON twin of CultMathResolver: vectors, quaternion and
Color32 are objects keyed by field name, matrices are arrays of row objects,
rect is {min,max}. Consumers add them with AddCultMathConverters(); CultLib owns
no JSON options. CultCircle and CultSphere serialize and deserialize through
them, with [JsonConstructor] so the struct constructor is used. The Caching
README documents each MessagePack and JSON shape in one table.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
parent
77602d5c0e
commit
20c30224fd
6 changed files with 290 additions and 0 deletions
|
|
@ -47,6 +47,22 @@ namespace GameCult.Geometry.Tests
|
|||
sphere.XyCircle.Bounds.Should().Be(new rect(-4f, -3f, 6f, 7f));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GeometryPrimitives_JsonOmitsComputedConvenienceProperties()
|
||||
{
|
||||
var options = new JsonSerializerOptions().AddCultMathConverters();
|
||||
var sphere = new CultSphere(new float3(1f, 2f, 3f), 5f);
|
||||
var circle = new CultCircle(new float2(1f, 2f), 3f);
|
||||
|
||||
var sphereJson = JsonSerializer.Serialize(sphere, options);
|
||||
var circleJson = JsonSerializer.Serialize(circle, options);
|
||||
|
||||
sphereJson.Should().Be("""{"Center":{"x":1,"y":2,"z":3},"Radius":5}""");
|
||||
circleJson.Should().Be("""{"Center":{"x":1,"y":2},"Radius":3}""");
|
||||
JsonSerializer.Deserialize<CultSphere>(sphereJson, options).Should().Be(sphere);
|
||||
JsonSerializer.Deserialize<CultCircle>(circleJson, options).Should().Be(circle);
|
||||
}
|
||||
|
||||
// The bytes CultCircle and CultSphere produced when they held CultVec2/CultVec3 (probed at 65311c9).
|
||||
[Test]
|
||||
public void GeometryPrimitives_KeepTheirPreCollapseBytes()
|
||||
|
|
|
|||
Loading…
Reference in a new issue