diff --git a/MEOS.NET.Tests/ValueArrayTests.cs b/MEOS.NET.Tests/ValueArrayTests.cs new file mode 100644 index 0000000..29c51ae --- /dev/null +++ b/MEOS.NET.Tests/ValueArrayTests.cs @@ -0,0 +1,52 @@ +using MEOS.NET.Types; + +namespace MEOS.NET.Tests +{ + /// + /// A method that answers many MEOS values answers them as the classes their + /// own headers name, whether MEOS returns an array of pointers or an array of + /// the values themselves walked at the struct's stride. + /// + [TestClass] + public class ValueArrayTests : MeosTest + { + [TestMethod] + public void TheSpansOfASpanSetComeBackAsSpans() + { + SpanSet spanset = FloatSpanSet.In("{[8, 10], [11, 12]}")!; + + Span?[] spans = spanset.Spans(); + + Assert.AreEqual(2, spans.Length); + Assert.IsInstanceOfType(spans[0], typeof(FloatSpan)); + Assert.AreEqual("[8, 10]", spans[0]!.ToString()); + Assert.AreEqual("[11, 12]", spans[1]!.ToString()); + } + + [TestMethod] + public void TheQuadrantsOfABoxComeBackAsBoxes() + { + STBox box = STBox.In("STBOX X((0,0),(4,4))")!; + + STBox?[] quadrants = box.QuadSplit(); + + Assert.AreEqual(4, quadrants.Length); + foreach (STBox? quadrant in quadrants) + { + StringAssert.StartsWith(quadrant!.ToString(), "STBOX X("); + } + } + + [TestMethod] + public void TheInstantsOfASequenceComeBackAsTemporalValues() + { + Temporal temp = TFloat.In("[25.0@2024-12-06, 27.0@2024-12-07]")!; + + Temporal?[] instants = temp.Instants(); + + Assert.AreEqual(2, instants.Length); + Assert.IsInstanceOfType(instants[0], typeof(TFloatInst)); + Assert.AreEqual("25@2024-12-06 00:00:00+00", instants[0]!.ToString()); + } + } +} diff --git a/MEOS.NET/Types/BigIntSpan.g.cs b/MEOS.NET/Types/BigIntSpan.g.cs index 7360c3d..16bf168 100644 --- a/MEOS.NET/Types/BigIntSpan.g.cs +++ b/MEOS.NET/Types/BigIntSpan.g.cs @@ -15,6 +15,9 @@ internal BigIntSpan(IntPtr ptr) : base(ptr) { } public override string ToString() => this.Out(); + public Span?[] Bins(long vsize, long vorigin) + => MEOSFactory.WrapSpanArray(Meos.BigintspanBins(this.Ptr, vsize, vorigin)); + public Span? Expand(long value) => MEOSFactory.WrapSpan(Meos.BigintspanExpand(this.Ptr, value)); diff --git a/MEOS.NET/Types/BigIntSpanSet.g.cs b/MEOS.NET/Types/BigIntSpanSet.g.cs index e99a8fa..50aa718 100644 --- a/MEOS.NET/Types/BigIntSpanSet.g.cs +++ b/MEOS.NET/Types/BigIntSpanSet.g.cs @@ -15,6 +15,9 @@ internal BigIntSpanSet(IntPtr ptr) : base(ptr) { } public override string ToString() => this.Out(); + public Span?[] Bins(long vsize, long vorigin) + => MEOSFactory.WrapSpanArray(Meos.BigintspansetBins(this.Ptr, vsize, vorigin)); + public long Lower() => Meos.BigintspansetLower(this.Ptr); diff --git a/MEOS.NET/Types/FloatSpan.g.cs b/MEOS.NET/Types/FloatSpan.g.cs index 44eac3f..75fcf5a 100644 --- a/MEOS.NET/Types/FloatSpan.g.cs +++ b/MEOS.NET/Types/FloatSpan.g.cs @@ -15,6 +15,9 @@ internal FloatSpan(IntPtr ptr) : base(ptr) { } public override string ToString() => this.Out(15); + public Span?[] Bins(double vsize, double vorigin) + => MEOSFactory.WrapSpanArray(Meos.FloatspanBins(this.Ptr, vsize, vorigin)); + public Span? Ceil() => MEOSFactory.WrapSpan(Meos.FloatspanCeil(this.Ptr)); diff --git a/MEOS.NET/Types/FloatSpanSet.g.cs b/MEOS.NET/Types/FloatSpanSet.g.cs index 2e7ed4a..528ef1f 100644 --- a/MEOS.NET/Types/FloatSpanSet.g.cs +++ b/MEOS.NET/Types/FloatSpanSet.g.cs @@ -15,6 +15,9 @@ internal FloatSpanSet(IntPtr ptr) : base(ptr) { } public override string ToString() => this.Out(15); + public Span?[] Bins(double vsize, double vorigin) + => MEOSFactory.WrapSpanArray(Meos.FloatspansetBins(this.Ptr, vsize, vorigin)); + public SpanSet? Ceil() => MEOSFactory.WrapSpanSet(Meos.FloatspansetCeil(this.Ptr)); diff --git a/MEOS.NET/Types/IntSpan.g.cs b/MEOS.NET/Types/IntSpan.g.cs index ae68f62..d5682c2 100644 --- a/MEOS.NET/Types/IntSpan.g.cs +++ b/MEOS.NET/Types/IntSpan.g.cs @@ -15,6 +15,9 @@ internal IntSpan(IntPtr ptr) : base(ptr) { } public override string ToString() => this.Out(); + public Span?[] Bins(int vsize, int vorigin) + => MEOSFactory.WrapSpanArray(Meos.IntspanBins(this.Ptr, vsize, vorigin)); + public Span? Expand(int value) => MEOSFactory.WrapSpan(Meos.IntspanExpand(this.Ptr, value)); diff --git a/MEOS.NET/Types/IntSpanSet.g.cs b/MEOS.NET/Types/IntSpanSet.g.cs index 4772fbc..25421a4 100644 --- a/MEOS.NET/Types/IntSpanSet.g.cs +++ b/MEOS.NET/Types/IntSpanSet.g.cs @@ -15,6 +15,9 @@ internal IntSpanSet(IntPtr ptr) : base(ptr) { } public override string ToString() => this.Out(); + public Span?[] Bins(int vsize, int vorigin) + => MEOSFactory.WrapSpanArray(Meos.IntspansetBins(this.Ptr, vsize, vorigin)); + public int Lower() => Meos.IntspansetLower(this.Ptr); diff --git a/MEOS.NET/Types/STBox.g.cs b/MEOS.NET/Types/STBox.g.cs index 9848e21..1364163 100644 --- a/MEOS.NET/Types/STBox.g.cs +++ b/MEOS.NET/Types/STBox.g.cs @@ -72,6 +72,9 @@ public string Out(int maxdd) public double Perimeter(bool spheroid) => Meos.StboxPerimeter(this.Ptr, spheroid); + public STBox?[] QuadSplit() + => MEOSFactory.WrapSTBoxArray(Meos.StboxQuadSplit(this.Ptr)); + public STBox? Round(int maxdd) => MEOSFactory.WrapSTBox(Meos.StboxRound(this.Ptr, maxdd)); diff --git a/MEOS.NET/Types/Set.g.cs b/MEOS.NET/Types/Set.g.cs index cba7a51..4591a62 100644 --- a/MEOS.NET/Types/Set.g.cs +++ b/MEOS.NET/Types/Set.g.cs @@ -47,6 +47,15 @@ public int NumValues() public Set? Round(int maxdd) => MEOSFactory.WrapSet(Meos.SetRound(this.Ptr, maxdd)); + public Span?[] Spans() + => MEOSFactory.WrapSpanArray(Meos.SetSpans(this.Ptr)); + + public Span?[] SplitEachNSpans(int elems_per_span) + => MEOSFactory.WrapSpanArray(Meos.SetSplitEachNSpans(this.Ptr, elems_per_span)); + + public Span?[] SplitNSpans(int span_count) + => MEOSFactory.WrapSpanArray(Meos.SetSplitNSpans(this.Ptr, span_count)); + public Span? ToSpan() => MEOSFactory.WrapSpan(Meos.SetToSpan(this.Ptr)); diff --git a/MEOS.NET/Types/SpanSet.g.cs b/MEOS.NET/Types/SpanSet.g.cs index a0c1502..0223c92 100644 --- a/MEOS.NET/Types/SpanSet.g.cs +++ b/MEOS.NET/Types/SpanSet.g.cs @@ -59,6 +59,15 @@ public int NumSpans() public Span?[] Spanarr() => MEOSFactory.WrapSpanArray(Meos.SpansetSpanarr(this.Ptr)); + public Span?[] Spans() + => MEOSFactory.WrapSpanArray(Meos.SpansetSpans(this.Ptr)); + + public Span?[] SplitEachNSpans(int elems_per_span) + => MEOSFactory.WrapSpanArray(Meos.SpansetSplitEachNSpans(this.Ptr, elems_per_span)); + + public Span?[] SplitNSpans(int span_count) + => MEOSFactory.WrapSpanArray(Meos.SpansetSplitNSpans(this.Ptr, span_count)); + public Span? StartSpan() => MEOSFactory.WrapSpan(Meos.SpansetStartSpan(this.Ptr)); diff --git a/MEOS.NET/Types/TFloat.g.cs b/MEOS.NET/Types/TFloat.g.cs index f1a4452..cf10297 100644 --- a/MEOS.NET/Types/TFloat.g.cs +++ b/MEOS.NET/Types/TFloat.g.cs @@ -81,6 +81,12 @@ public double StartValue() public Temporal? ToTint() => MEOSFactory.WrapTemporal(Meos.TfloatToTint(this.Ptr)); + public Span?[] ValueBins(double vsize, double vorigin) + => MEOSFactory.WrapSpanArray(Meos.TfloatValueBins(this.Ptr, vsize, vorigin)); + + public TBox?[] ValueBoxes(double vsize, double vorigin) + => MEOSFactory.WrapTBoxArray(Meos.TfloatValueBoxes(this.Ptr, vsize, vorigin)); + public double[] Values() => Meos.TfloatValues(this.Ptr); diff --git a/MEOS.NET/Types/TGeo.g.cs b/MEOS.NET/Types/TGeo.g.cs index 5a547e8..be2ce7a 100644 --- a/MEOS.NET/Types/TGeo.g.cs +++ b/MEOS.NET/Types/TGeo.g.cs @@ -20,5 +20,14 @@ internal TGeo(IntPtr ptr) : base(ptr) { } public Temporal? MinusStbox(STBox box, bool border_inc) => MEOSFactory.WrapTemporal(Meos.TgeoMinusStbox(this.Ptr, box.Ptr, border_inc)); + public STBox?[] SplitEachNStboxes(int elem_count) + => MEOSFactory.WrapSTBoxArray(Meos.TgeoSplitEachNStboxes(this.Ptr, elem_count)); + + public STBox?[] SplitNStboxes(int box_count) + => MEOSFactory.WrapSTBoxArray(Meos.TgeoSplitNStboxes(this.Ptr, box_count)); + + public STBox?[] Stboxes() + => MEOSFactory.WrapSTBoxArray(Meos.TgeoStboxes(this.Ptr)); + } } diff --git a/MEOS.NET/Types/TInt.g.cs b/MEOS.NET/Types/TInt.g.cs index 368f8d5..a78e0ed 100644 --- a/MEOS.NET/Types/TInt.g.cs +++ b/MEOS.NET/Types/TInt.g.cs @@ -51,6 +51,12 @@ public int StartValue() public Temporal? ToTfloat() => MEOSFactory.WrapTemporal(Meos.TintToTfloat(this.Ptr)); + public Span?[] ValueBins(int vsize, int vorigin) + => MEOSFactory.WrapSpanArray(Meos.TintValueBins(this.Ptr, vsize, vorigin)); + + public TBox?[] ValueBoxes(int vsize, int vorigin) + => MEOSFactory.WrapTBoxArray(Meos.TintValueBoxes(this.Ptr, vsize, vorigin)); + public int[] Values() => Meos.TintValues(this.Ptr); diff --git a/MEOS.NET/Types/TNumber.g.cs b/MEOS.NET/Types/TNumber.g.cs index 68ff44f..29f83b1 100644 --- a/MEOS.NET/Types/TNumber.g.cs +++ b/MEOS.NET/Types/TNumber.g.cs @@ -41,6 +41,15 @@ public double Integral() public Temporal? MinusTbox(TBox box) => MEOSFactory.WrapTemporal(Meos.TnumberMinusTbox(this.Ptr, box.Ptr)); + public TBox?[] SplitEachNTboxes(int elem_count) + => MEOSFactory.WrapTBoxArray(Meos.TnumberSplitEachNTboxes(this.Ptr, elem_count)); + + public TBox?[] SplitNTboxes(int box_count) + => MEOSFactory.WrapTBoxArray(Meos.TnumberSplitNTboxes(this.Ptr, box_count)); + + public TBox?[] Tboxes() + => MEOSFactory.WrapTBoxArray(Meos.TnumberTboxes(this.Ptr)); + public Span? ToSpan() => MEOSFactory.WrapSpan(Meos.TnumberToSpan(this.Ptr)); diff --git a/MEOS.NET/Types/TRGeometry.g.cs b/MEOS.NET/Types/TRGeometry.g.cs index 1a67206..0eaa6f5 100644 --- a/MEOS.NET/Types/TRGeometry.g.cs +++ b/MEOS.NET/Types/TRGeometry.g.cs @@ -159,12 +159,21 @@ public string Out() public Temporal? Speed() => MEOSFactory.WrapTemporal(Meos.TrgeometrySpeed(this.Ptr)); + public STBox?[] SplitEachNStboxes(int elem_count) + => MEOSFactory.WrapSTBoxArray(Meos.TrgeometrySplitEachNStboxes(this.Ptr, elem_count)); + + public STBox?[] SplitNStboxes(int box_count) + => MEOSFactory.WrapSTBoxArray(Meos.TrgeometrySplitNStboxes(this.Ptr, box_count)); + public new Temporal? StartInstant() => MEOSFactory.WrapTemporal(Meos.TrgeometryStartInstant(this.Ptr)); public new Temporal? StartSequence() => MEOSFactory.WrapTemporal(Meos.TrgeometryStartSequence(this.Ptr)); + public STBox?[] Stboxes() + => MEOSFactory.WrapSTBoxArray(Meos.TrgeometryStboxes(this.Ptr)); + public Temporal? ToTgeometry() => MEOSFactory.WrapTemporal(Meos.TrgeometryToTgeometry(this.Ptr)); diff --git a/MEOS.NET/Types/Temporal.g.cs b/MEOS.NET/Types/Temporal.g.cs index c6329ef..0c6e8da 100644 --- a/MEOS.NET/Types/Temporal.g.cs +++ b/MEOS.NET/Types/Temporal.g.cs @@ -206,6 +206,15 @@ public int NumTimestamps() public Temporal? SimplifyMinDist(double dist) => MEOSFactory.WrapTemporal(Meos.TemporalSimplifyMinDist(this.Ptr, dist)); + public Span?[] Spans() + => MEOSFactory.WrapSpanArray(Meos.TemporalSpans(this.Ptr)); + + public Span?[] SplitEachNSpans(int elem_count) + => MEOSFactory.WrapSpanArray(Meos.TemporalSplitEachNSpans(this.Ptr, elem_count)); + + public Span?[] SplitNSpans(int span_count) + => MEOSFactory.WrapSpanArray(Meos.TemporalSplitNSpans(this.Ptr, span_count)); + public Temporal? StartInstant() => MEOSFactory.WrapTemporal(Meos.TemporalStartInstant(this.Ptr)); diff --git a/tools/objectgen.py b/tools/objectgen.py index 2a0e4b8..9f4ef40 100644 --- a/tools/objectgen.py +++ b/tools/objectgen.py @@ -269,8 +269,12 @@ def map_return(self, f: dict, wrapper_ret: str) -> tuple[str, str] | None: cls = self.m.class_for_ctype(c) if cls and wrapper_ret == "IntPtr": return (f"{cls}?", f"MEOSFactory.Wrap{ROOT_CTYPE[cls]}($)") - if c.endswith(" **") and wrapper_ret == "IntPtr[]": - elem = self.m.class_for_ctype(c[:-1]) + if wrapper_ret == "IntPtr[]": + # An array of MEOS values reaches the wrapper as an array of pointers, + # whether MEOS returns pointers (`T **`) or the values themselves + # (`T *`, walked at the struct's own stride), so both wrap element by + # element into the class each value's header names. + elem = self.m.class_for_ctype(c[:-1] if c.endswith(" **") else c) if elem: return (f"{elem}?[]", f"MEOSFactory.Wrap{ROOT_CTYPE[elem]}Array($)") if wrapper_ret in ("long[]", "int[]", "double[]", "byte[]"):