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
5 changes: 3 additions & 2 deletions MEOS.NET.Tests/ValueClassTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ public void ATemporalGeoIsRestrictedByAGeometry()
// The trip leaves the square at (2,2), halfway along, so what the
// restriction answers ends there rather than at the trip's own end.
Assert.IsNotNull(inside);
StringAssert.Contains(inside!.ToString(), "2024-12-07");
Assert.IsFalse(inside.ToString().Contains("2024-12-08"));
string text = inside!.ToString() ?? string.Empty;
StringAssert.Contains(text, "2024-12-07");
Assert.IsFalse(text.Contains("2024-12-08"));
}
}
}
77 changes: 77 additions & 0 deletions MEOS.NET.Tests/ValueStructTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
using MEOS.NET.Structures;
using MEOS.NET.Types;

namespace MEOS.NET.Tests
{
/// <summary>
/// A MEOS struct whose layout is all scalars and that no class stands for is
/// carried as a value: the method takes and answers the value itself rather
/// than an address into MEOS.
/// </summary>
[TestClass]
public class ValueStructTests : MeosTest
{
[TestMethod]
public void ASpanAnswersItsDurationAsAnInterval()
{
TsTzSpan span = (TsTzSpan)TsTzSpan.In("[2024-12-06, 2024-12-08]")!;

Interval? duration = span.Duration();

Assert.IsNotNull(duration);
Assert.AreEqual(2, duration!.Value.day);
Assert.AreEqual(0, duration!.Value.month);
Assert.AreEqual("2 days", duration.ToString());
}

[TestMethod]
public void AnIntervalReadsAndWritesTheTextMeosDoes()
{
Interval? day = Interval.In("1 day");

Assert.IsNotNull(day);
Assert.AreEqual(1, day!.Value.day);
Assert.AreEqual(0, day!.Value.time);
Assert.AreEqual("1 day", day.ToString());
Assert.ThrowsException<MEOS.NET.Exceptions.MEOSInternalErrorException>(
() => Interval.In("not an interval"));
}

[TestMethod]
public void ASpanIsShiftedByAnIntervalItIsGivenAsAValue()
{
TsTzSpan span = (TsTzSpan)TsTzSpan.In("[2024-12-06, 2024-12-08]")!;

Span? shifted = span.ShiftScale(Interval.In("1 day")!.Value,
Interval.In("4 days")!.Value);

Assert.IsNotNull(shifted);
Assert.AreEqual("[2024-12-07 00:00:00+00, 2024-12-11 00:00:00+00]",
shifted!.ToString());
}

[TestMethod]
public void AFrechetPathComesBackAsTheMatchesThemselves()
{
Temporal trip = TFloat.In("[1@2024-12-06, 3@2024-12-08]")!;
Temporal other = TFloat.In("[2@2024-12-06, 4@2024-12-08]")!;

Match[] path = trip.FrechetPath(other);

// A match pairs an instant of one value with an instant of the
// other, and MEOS walks the distance matrix back from the last pair
// to the first, so the path arrives in that order.
Assert.IsTrue(path.Length > 0);
foreach (Match match in path)
{
Assert.IsTrue(match.i >= 0 && match.i < 2, $"i={match.i}");
Assert.IsTrue(match.j >= 0 && match.j < 2, $"j={match.j}");
}

Assert.AreEqual(1, path[0].i);
Assert.AreEqual(1, path[0].j);
Assert.AreEqual(0, path[path.Length - 1].i);
Assert.AreEqual(0, path[path.Length - 1].j);
}
}
}
6 changes: 6 additions & 0 deletions MEOS.NET/Functions/Meos.Native.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10455,6 +10455,12 @@ private static partial class Native
[LibraryImport(DllPath, EntryPoint = "pcpatch_npoints", StringMarshalling = StringMarshalling.Utf8)]
internal static partial uint PcpatchNpoints(IntPtr pa);

[LibraryImport(DllPath, EntryPoint = "pcpatch_point_n", StringMarshalling = StringMarshalling.Utf8)]
internal static partial IntPtr PcpatchPointN(IntPtr pa, int n);

[LibraryImport(DllPath, EntryPoint = "pcpatch_points", StringMarshalling = StringMarshalling.Utf8)]
internal static partial IntPtr PcpatchPoints(IntPtr pa, IntPtr count);

[LibraryImport(DllPath, EntryPoint = "pcpatch_hash", StringMarshalling = StringMarshalling.Utf8)]
internal static partial uint PcpatchHash(IntPtr pa);

Expand Down
18 changes: 18 additions & 0 deletions MEOS.NET/Functions/Meos.meos_pointcloud.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,24 @@ public static uint PcpatchGetPcid(IntPtr pa)
public static uint PcpatchNpoints(IntPtr pa)
=> SafeExecution<uint>(() => Native.PcpatchNpoints(pa));

public static IntPtr PcpatchPointN(IntPtr pa, int n)
=> SafeExecution<IntPtr>(() => Native.PcpatchPointN(pa, n));

public static IntPtr[] PcpatchPoints(IntPtr pa)
{
IntPtr _cnt = Marshal.AllocHGlobal(sizeof(int));
try
{
IntPtr _p = SafeExecution<IntPtr>(() => Native.PcpatchPoints(pa, _cnt));
int _n = Marshal.ReadInt32(_cnt);
IntPtr[] _out = new IntPtr[_n];
for (int _i = 0; _i < _n; _i++)
{ _out[_i] = Marshal.ReadIntPtr(_p, _i * IntPtr.Size); }
return _out;
}
finally { Marshal.FreeHGlobal(_cnt); }
}

public static uint PcpatchHash(IntPtr pa)
=> SafeExecution<uint>(() => Native.PcpatchHash(pa));

Expand Down
129 changes: 129 additions & 0 deletions MEOS.NET/Structures/MeosStructs.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,106 @@
using System.CodeDom.Compiler;
using System.Runtime.InteropServices;

using MEOS.NET.Functions;

namespace MEOS.NET.Structures
{
/// <summary>The MEOS <c>AFFINE</c> struct, as MEOS returns it.</summary>
[GeneratedCode("MEOS.NET.Codegen", "0.1.0")]
[StructLayout(LayoutKind.Sequential)]
public struct AFFINE
{
public double afac;
public double bfac;
public double cfac;
public double dfac;
public double efac;
public double ffac;
public double gfac;
public double hfac;
public double ifac;
public double xoff;
public double yoff;
public double zoff;
}

/// <summary>The MEOS <c>BOX3D</c> struct, as MEOS returns it.</summary>
[GeneratedCode("MEOS.NET.Codegen", "0.1.0")]
[StructLayout(LayoutKind.Sequential)]
public struct BOX3D
{
public double xmin;
public double ymin;
public double zmin;
public double xmax;
public double ymax;
public double zmax;
public int srid;

/// <summary>The <c>BOX3D</c> MEOS reads from this text.</summary>
public static BOX3D? In(string str)
{
IntPtr ptr = Meos.Box3dIn(str);
return ptr == IntPtr.Zero ? null : Marshal.PtrToStructure<BOX3D>(ptr);
}

/// <summary>The text MEOS writes this value as.</summary>
public override string ToString()
{
IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf<BOX3D>());
try
{
Marshal.StructureToPtr(this, ptr, false);
return Meos.Box3dOut(ptr, 15);
}
finally
{
Marshal.FreeHGlobal(ptr);
}
}
}

/// <summary>The MEOS <c>Interval</c> struct, as MEOS returns it.</summary>
[GeneratedCode("MEOS.NET.Codegen", "0.1.0")]
[StructLayout(LayoutKind.Sequential)]
public struct Interval
{
public long time;
public int day;
public int month;

/// <summary>The <c>Interval</c> MEOS reads from this text.</summary>
public static Interval? In(string str)
{
IntPtr ptr = Meos.IntervalIn(str, -1);
return ptr == IntPtr.Zero ? null : Marshal.PtrToStructure<Interval>(ptr);
}

/// <summary>The text MEOS writes this value as.</summary>
public override string ToString()
{
IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf<Interval>());
try
{
Marshal.StructureToPtr(this, ptr, false);
return Meos.IntervalOut(ptr);
}
finally
{
Marshal.FreeHGlobal(ptr);
}
}
}

/// <summary>The MEOS <c>Match</c> struct, as MEOS returns it.</summary>
[GeneratedCode("MEOS.NET.Codegen", "0.1.0")]
[StructLayout(LayoutKind.Sequential)]
public struct Match
{
public int i;
public int j;
}

/// <summary>The MEOS <c>MvtGeom</c> struct, as MEOS returns it.</summary>
[GeneratedCode("MEOS.NET.Codegen", "0.1.0")]
[StructLayout(LayoutKind.Sequential)]
Expand Down Expand Up @@ -36,4 +134,35 @@ public struct SpaceTimeSplit
public int count;
}

/// <summary>The MEOS <c>TimeTzADT</c> struct, as MEOS returns it.</summary>
[GeneratedCode("MEOS.NET.Codegen", "0.1.0")]
[StructLayout(LayoutKind.Sequential)]
public struct TimeTzADT
{
public long time;
public int zone;

/// <summary>The <c>TimeTzADT</c> MEOS reads from this text.</summary>
public static TimeTzADT? In(string str)
{
IntPtr ptr = Meos.PgTimetzIn(str, -1);
return ptr == IntPtr.Zero ? null : Marshal.PtrToStructure<TimeTzADT>(ptr);
}

/// <summary>The text MEOS writes this value as.</summary>
public override string ToString()
{
IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf<TimeTzADT>());
try
{
Marshal.StructureToPtr(this, ptr, false);
return Meos.PgTimetzOut(ptr);
}
finally
{
Marshal.FreeHGlobal(ptr);
}
}
}

}
1 change: 1 addition & 0 deletions MEOS.NET/Types/BigIntSet.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

using MEOS.NET.Enums;
using MEOS.NET.Functions;
using MEOS.NET.Structures;

namespace MEOS.NET.Types
{
Expand Down
1 change: 1 addition & 0 deletions MEOS.NET/Types/BigIntSpan.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

using MEOS.NET.Enums;
using MEOS.NET.Functions;
using MEOS.NET.Structures;

namespace MEOS.NET.Types
{
Expand Down
1 change: 1 addition & 0 deletions MEOS.NET/Types/BigIntSpanSet.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

using MEOS.NET.Enums;
using MEOS.NET.Functions;
using MEOS.NET.Structures;

namespace MEOS.NET.Types
{
Expand Down
1 change: 1 addition & 0 deletions MEOS.NET/Types/Box.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

using MEOS.NET.Enums;
using MEOS.NET.Functions;
using MEOS.NET.Structures;

namespace MEOS.NET.Types
{
Expand Down
1 change: 1 addition & 0 deletions MEOS.NET/Types/Cbuffer.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

using MEOS.NET.Enums;
using MEOS.NET.Functions;
using MEOS.NET.Structures;

namespace MEOS.NET.Types
{
Expand Down
1 change: 1 addition & 0 deletions MEOS.NET/Types/CbufferSet.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

using MEOS.NET.Enums;
using MEOS.NET.Functions;
using MEOS.NET.Structures;

namespace MEOS.NET.Types
{
Expand Down
1 change: 1 addition & 0 deletions MEOS.NET/Types/Collection.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

using MEOS.NET.Enums;
using MEOS.NET.Functions;
using MEOS.NET.Structures;

namespace MEOS.NET.Types
{
Expand Down
1 change: 1 addition & 0 deletions MEOS.NET/Types/DateSet.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

using MEOS.NET.Enums;
using MEOS.NET.Functions;
using MEOS.NET.Structures;

namespace MEOS.NET.Types
{
Expand Down
18 changes: 18 additions & 0 deletions MEOS.NET/Types/DateSpan.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

using MEOS.NET.Enums;
using MEOS.NET.Functions;
using MEOS.NET.Structures;

namespace MEOS.NET.Types
{
Expand All @@ -17,6 +18,23 @@ internal DateSpan(IntPtr ptr) : base(ptr) { }
public override string ToString()
=> this.Out();

public Span?[] Bins(Interval duration, DateOnly torigin)
{
IntPtr _duration = Marshal.AllocHGlobal(Marshal.SizeOf<Interval>());
try
{
Marshal.StructureToPtr(duration, _duration, false);
return MEOSFactory.WrapSpanArray(Meos.DatespanBins(this.Ptr, _duration, MEOSConvert.ToDateADT(torigin)));
}
finally
{
Marshal.FreeHGlobal(_duration);
}
}

public Interval? Duration()
=> MEOSConvert.ToStruct<Interval>(Meos.DatespanDuration(this.Ptr));

public DateOnly Lower()
=> MEOSConvert.ToDateOnly(Meos.DatespanLower(this.Ptr));

Expand Down
Loading
Loading