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
65 changes: 65 additions & 0 deletions MEOS.NET.Tests/ByValueStructTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
using System.Runtime.InteropServices;

using MEOS.NET.Functions;
using MEOS.NET.Structures;
using MEOS.NET.Types;

namespace MEOS.NET.Tests
{
/// <summary>
/// The three MEOS functions that hand a struct back by value. A struct return
/// is not a pointer — the ABI passes it in registers or through a hidden
/// pointer the caller supplies — so a field read out of one is only the field
/// MEOS filled when the return is declared as the struct it is.
/// </summary>
[TestClass]
public class ByValueStructTests : MeosTest
{
private const string Trip =
"[POINT(1 1)@2000-01-01, POINT(2 2)@2000-01-02, POINT(3 3)@2000-01-03]";

[TestMethod]
public void EveryFieldOfAnMvtGeomIsTheOneMeosFilled()
{
Temporal trip = TGeomPoint.In(Trip)!;
STBox bounds = STBox.In("STBOX XT(((0,0),(10,10)),[2000-01-01, 2000-01-04])")!;

MvtGeom mvt = Meos.TpointAsMvtgeom(trip.Ptr, bounds.Ptr, 4096, 0, true);

// The geometry field is a GSERIALIZED the geometry functions read.
StringAssert.StartsWith(Meos.GeoAsText(mvt.geom, 6), "LINESTRING");

// The times field is an array of exactly count timestamps, in order.
Assert.IsTrue(mvt.count > 0, $"count was {mvt.count}");
long previous = long.MinValue;
for (int i = 0; i < mvt.count; i++)
{
long moment = Marshal.ReadInt64(mvt.times, i * sizeof(long));
Assert.IsTrue(moment > previous, $"timestamp {i} is out of order");
previous = moment;
}
}

[TestMethod]
public void EveryFieldOfASpaceSplitIsTheOneMeosFilled()
{
Temporal trip = TGeomPoint.In(Trip)!;
IntPtr origin = Meos.GeomIn("POINT(0 0)", -1);

SpaceSplit split = Meos.TgeoSpaceSplit(
trip.Ptr, 2.0, 2.0, 2.0, origin, false, true);

Assert.IsTrue(split.count > 0, $"count was {split.count}");
for (int i = 0; i < split.count; i++)
{
IntPtr fragment = Marshal.ReadIntPtr(split.fragments, i * IntPtr.Size);
IntPtr bin = Marshal.ReadIntPtr(split.bins, i * IntPtr.Size);

// Each fragment is a temporal point and each bin the geometry it
// falls in, so both read back through their own MEOS functions.
StringAssert.Contains(Meos.TspatialAsText(fragment, 6), "POINT");
StringAssert.StartsWith(Meos.GeoAsText(bin, 6), "POINT");
}
}
}
}
8 changes: 5 additions & 3 deletions MEOS.NET/Functions/Meos.Native.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
using System.CodeDom.Compiler;
using System.Runtime.InteropServices;

using MEOS.NET.Structures;

namespace MEOS.NET.Functions
{
public static partial class Meos
Expand Down Expand Up @@ -5746,7 +5748,7 @@ private static partial class Native
internal static partial IntPtr TgeompointToTgeometry(IntPtr temp);

[LibraryImport(DllPath, EntryPoint = "tpoint_as_mvtgeom", StringMarshalling = StringMarshalling.Utf8)]
internal static partial IntPtr TpointAsMvtgeom(IntPtr temp, IntPtr bounds, int extent, int buffer, [MarshalAs(UnmanagedType.U1)] bool clip_geom);
internal static partial MvtGeom TpointAsMvtgeom(IntPtr temp, IntPtr bounds, int extent, int buffer, [MarshalAs(UnmanagedType.U1)] bool clip_geom);

[LibraryImport(DllPath, EntryPoint = "tpoint_tfloat_to_geomeas", StringMarshalling = StringMarshalling.Utf8)]
[return: MarshalAs(UnmanagedType.U1)]
Expand Down Expand Up @@ -6481,10 +6483,10 @@ private static partial class Native
internal static partial IntPtr StboxTimeTiles(IntPtr bounds, IntPtr duration, long torigin, [MarshalAs(UnmanagedType.U1)] bool border_inc, IntPtr count);

[LibraryImport(DllPath, EntryPoint = "tgeo_space_split", StringMarshalling = StringMarshalling.Utf8)]
internal static partial IntPtr TgeoSpaceSplit(IntPtr temp, double xsize, double ysize, double zsize, IntPtr sorigin, [MarshalAs(UnmanagedType.U1)] bool bitmatrix, [MarshalAs(UnmanagedType.U1)] bool border_inc);
internal static partial SpaceSplit TgeoSpaceSplit(IntPtr temp, double xsize, double ysize, double zsize, IntPtr sorigin, [MarshalAs(UnmanagedType.U1)] bool bitmatrix, [MarshalAs(UnmanagedType.U1)] bool border_inc);

[LibraryImport(DllPath, EntryPoint = "tgeo_space_time_split", StringMarshalling = StringMarshalling.Utf8)]
internal static partial IntPtr TgeoSpaceTimeSplit(IntPtr temp, double xsize, double ysize, double zsize, IntPtr duration, IntPtr sorigin, long torigin, [MarshalAs(UnmanagedType.U1)] bool bitmatrix, [MarshalAs(UnmanagedType.U1)] bool border_inc);
internal static partial SpaceTimeSplit TgeoSpaceTimeSplit(IntPtr temp, double xsize, double ysize, double zsize, IntPtr duration, IntPtr sorigin, long torigin, [MarshalAs(UnmanagedType.U1)] bool bitmatrix, [MarshalAs(UnmanagedType.U1)] bool border_inc);

[LibraryImport(DllPath, EntryPoint = "geo_cluster_kmeans", StringMarshalling = StringMarshalling.Utf8)]
internal static partial IntPtr GeoClusterKmeans(IntPtr geoms, uint ngeoms, uint k, IntPtr count);
Expand Down
2 changes: 2 additions & 0 deletions MEOS.NET/Functions/Meos.hashtable.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

using System.Runtime.InteropServices;

using MEOS.NET.Structures;

namespace MEOS.NET.Functions
{
/// <summary>The MEOS functions <c>hashtable.h</c> declares.</summary>
Expand Down
2 changes: 2 additions & 0 deletions MEOS.NET/Functions/Meos.meos.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

using System.Runtime.InteropServices;

using MEOS.NET.Structures;

namespace MEOS.NET.Functions
{
/// <summary>The MEOS functions <c>meos.h</c> declares.</summary>
Expand Down
2 changes: 2 additions & 0 deletions MEOS.NET/Functions/Meos.meos_catalog.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

using System.Runtime.InteropServices;

using MEOS.NET.Structures;

namespace MEOS.NET.Functions
{
/// <summary>The MEOS functions <c>meos_catalog.h</c> declares.</summary>
Expand Down
2 changes: 2 additions & 0 deletions MEOS.NET/Functions/Meos.meos_cbuffer.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

using System.Runtime.InteropServices;

using MEOS.NET.Structures;

namespace MEOS.NET.Functions
{
/// <summary>The MEOS functions <c>meos_cbuffer.h</c> declares.</summary>
Expand Down
2 changes: 2 additions & 0 deletions MEOS.NET/Functions/Meos.meos_cellindex.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

using System.Runtime.InteropServices;

using MEOS.NET.Structures;

namespace MEOS.NET.Functions
{
/// <summary>The MEOS functions <c>meos_cellindex.h</c> declares.</summary>
Expand Down
14 changes: 8 additions & 6 deletions MEOS.NET/Functions/Meos.meos_geo.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

using System.Runtime.InteropServices;

using MEOS.NET.Structures;

namespace MEOS.NET.Functions
{
/// <summary>The MEOS functions <c>meos_geo.h</c> declares.</summary>
Expand Down Expand Up @@ -760,8 +762,8 @@ public static IntPtr TgeometryToTgeompoint(IntPtr temp)
public static IntPtr TgeompointToTgeometry(IntPtr temp)
=> SafeExecution<IntPtr>(() => Native.TgeompointToTgeometry(temp));

public static IntPtr TpointAsMvtgeom(IntPtr temp, IntPtr bounds, int extent, int buffer, bool clip_geom)
=> SafeExecution<IntPtr>(() => Native.TpointAsMvtgeom(temp, bounds, extent, buffer, clip_geom));
public static MvtGeom TpointAsMvtgeom(IntPtr temp, IntPtr bounds, int extent, int buffer, bool clip_geom)
=> SafeExecution<MvtGeom>(() => Native.TpointAsMvtgeom(temp, bounds, extent, buffer, clip_geom));

public static bool TpointTfloatToGeomeas(IntPtr tpoint, IntPtr measure, bool segmentize, IntPtr result)
=> SafeExecution<bool>(() => Native.TpointTfloatToGeomeas(tpoint, measure, segmentize, result));
Expand Down Expand Up @@ -1714,11 +1716,11 @@ public static IntPtr[] StboxTimeTiles(IntPtr bounds, IntPtr duration, long torig
finally { Marshal.FreeHGlobal(_cnt); }
}

public static IntPtr TgeoSpaceSplit(IntPtr temp, double xsize, double ysize, double zsize, IntPtr sorigin, bool bitmatrix, bool border_inc)
=> SafeExecution<IntPtr>(() => Native.TgeoSpaceSplit(temp, xsize, ysize, zsize, sorigin, bitmatrix, border_inc));
public static SpaceSplit TgeoSpaceSplit(IntPtr temp, double xsize, double ysize, double zsize, IntPtr sorigin, bool bitmatrix, bool border_inc)
=> SafeExecution<SpaceSplit>(() => Native.TgeoSpaceSplit(temp, xsize, ysize, zsize, sorigin, bitmatrix, border_inc));

public static IntPtr TgeoSpaceTimeSplit(IntPtr temp, double xsize, double ysize, double zsize, IntPtr duration, IntPtr sorigin, long torigin, bool bitmatrix, bool border_inc)
=> SafeExecution<IntPtr>(() => Native.TgeoSpaceTimeSplit(temp, xsize, ysize, zsize, duration, sorigin, torigin, bitmatrix, border_inc));
public static SpaceTimeSplit TgeoSpaceTimeSplit(IntPtr temp, double xsize, double ysize, double zsize, IntPtr duration, IntPtr sorigin, long torigin, bool bitmatrix, bool border_inc)
=> SafeExecution<SpaceTimeSplit>(() => Native.TgeoSpaceTimeSplit(temp, xsize, ysize, zsize, duration, sorigin, torigin, bitmatrix, border_inc));

public static int[] GeoClusterKmeans(IntPtr geoms, uint ngeoms, uint k)
{
Expand Down
2 changes: 2 additions & 0 deletions MEOS.NET/Functions/Meos.meos_h3.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

using System.Runtime.InteropServices;

using MEOS.NET.Structures;

namespace MEOS.NET.Functions
{
/// <summary>The MEOS functions <c>meos_h3.h</c> declares.</summary>
Expand Down
2 changes: 2 additions & 0 deletions MEOS.NET/Functions/Meos.meos_internal.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

using System.Runtime.InteropServices;

using MEOS.NET.Structures;

namespace MEOS.NET.Functions
{
/// <summary>The MEOS functions <c>meos_internal.h</c> declares.</summary>
Expand Down
2 changes: 2 additions & 0 deletions MEOS.NET/Functions/Meos.meos_internal_geo.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

using System.Runtime.InteropServices;

using MEOS.NET.Structures;

namespace MEOS.NET.Functions
{
/// <summary>The MEOS functions <c>meos_internal_geo.h</c> declares.</summary>
Expand Down
2 changes: 2 additions & 0 deletions MEOS.NET/Functions/Meos.meos_json.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

using System.Runtime.InteropServices;

using MEOS.NET.Structures;

namespace MEOS.NET.Functions
{
/// <summary>The MEOS functions <c>meos_json.h</c> declares.</summary>
Expand Down
2 changes: 2 additions & 0 deletions MEOS.NET/Functions/Meos.meos_npoint.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

using System.Runtime.InteropServices;

using MEOS.NET.Structures;

namespace MEOS.NET.Functions
{
/// <summary>The MEOS functions <c>meos_npoint.h</c> declares.</summary>
Expand Down
2 changes: 2 additions & 0 deletions MEOS.NET/Functions/Meos.meos_pointcloud.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

using System.Runtime.InteropServices;

using MEOS.NET.Structures;

namespace MEOS.NET.Functions
{
/// <summary>The MEOS functions <c>meos_pointcloud.h</c> declares.</summary>
Expand Down
2 changes: 2 additions & 0 deletions MEOS.NET/Functions/Meos.meos_pose.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

using System.Runtime.InteropServices;

using MEOS.NET.Structures;

namespace MEOS.NET.Functions
{
/// <summary>The MEOS functions <c>meos_pose.h</c> declares.</summary>
Expand Down
2 changes: 2 additions & 0 deletions MEOS.NET/Functions/Meos.meos_quadbin.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

using System.Runtime.InteropServices;

using MEOS.NET.Structures;

namespace MEOS.NET.Functions
{
/// <summary>The MEOS functions <c>meos_quadbin.h</c> declares.</summary>
Expand Down
2 changes: 2 additions & 0 deletions MEOS.NET/Functions/Meos.meos_raster.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

using System.Runtime.InteropServices;

using MEOS.NET.Structures;

namespace MEOS.NET.Functions
{
/// <summary>The MEOS functions <c>meos_raster.h</c> declares.</summary>
Expand Down
2 changes: 2 additions & 0 deletions MEOS.NET/Functions/Meos.meos_rgeo.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

using System.Runtime.InteropServices;

using MEOS.NET.Structures;

namespace MEOS.NET.Functions
{
/// <summary>The MEOS functions <c>meos_rgeo.h</c> declares.</summary>
Expand Down
2 changes: 2 additions & 0 deletions MEOS.NET/Functions/Meos.meos_s2cell.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

using System.Runtime.InteropServices;

using MEOS.NET.Structures;

namespace MEOS.NET.Functions
{
/// <summary>The MEOS functions <c>meos_s2cell.h</c> declares.</summary>
Expand Down
2 changes: 2 additions & 0 deletions MEOS.NET/Functions/Meos.pc_api.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

using System.Runtime.InteropServices;

using MEOS.NET.Structures;

namespace MEOS.NET.Functions
{
/// <summary>The MEOS functions <c>pc_api.h</c> declares.</summary>
Expand Down
2 changes: 2 additions & 0 deletions MEOS.NET/Functions/Meos.pg_bool.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

using System.Runtime.InteropServices;

using MEOS.NET.Structures;

namespace MEOS.NET.Functions
{
/// <summary>The MEOS functions <c>pg_bool.h</c> declares.</summary>
Expand Down
2 changes: 2 additions & 0 deletions MEOS.NET/Functions/Meos.pg_date.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

using System.Runtime.InteropServices;

using MEOS.NET.Structures;

namespace MEOS.NET.Functions
{
/// <summary>The MEOS functions <c>pg_date.h</c> declares.</summary>
Expand Down
2 changes: 2 additions & 0 deletions MEOS.NET/Functions/Meos.pg_float.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

using System.Runtime.InteropServices;

using MEOS.NET.Structures;

namespace MEOS.NET.Functions
{
/// <summary>The MEOS functions <c>pg_float.h</c> declares.</summary>
Expand Down
2 changes: 2 additions & 0 deletions MEOS.NET/Functions/Meos.pg_int.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

using System.Runtime.InteropServices;

using MEOS.NET.Structures;

namespace MEOS.NET.Functions
{
/// <summary>The MEOS functions <c>pg_int.h</c> declares.</summary>
Expand Down
2 changes: 2 additions & 0 deletions MEOS.NET/Functions/Meos.pg_interval.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

using System.Runtime.InteropServices;

using MEOS.NET.Structures;

namespace MEOS.NET.Functions
{
/// <summary>The MEOS functions <c>pg_interval.h</c> declares.</summary>
Expand Down
2 changes: 2 additions & 0 deletions MEOS.NET/Functions/Meos.pg_numeric.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

using System.Runtime.InteropServices;

using MEOS.NET.Structures;

namespace MEOS.NET.Functions
{
/// <summary>The MEOS functions <c>pg_numeric.h</c> declares.</summary>
Expand Down
2 changes: 2 additions & 0 deletions MEOS.NET/Functions/Meos.pg_text.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

using System.Runtime.InteropServices;

using MEOS.NET.Structures;

namespace MEOS.NET.Functions
{
/// <summary>The MEOS functions <c>pg_text.h</c> declares.</summary>
Expand Down
2 changes: 2 additions & 0 deletions MEOS.NET/Functions/Meos.pg_time.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

using System.Runtime.InteropServices;

using MEOS.NET.Structures;

namespace MEOS.NET.Functions
{
/// <summary>The MEOS functions <c>pg_time.h</c> declares.</summary>
Expand Down
2 changes: 2 additions & 0 deletions MEOS.NET/Functions/Meos.pg_timestamp.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

using System.Runtime.InteropServices;

using MEOS.NET.Structures;

namespace MEOS.NET.Functions
{
/// <summary>The MEOS functions <c>pg_timestamp.h</c> declares.</summary>
Expand Down
2 changes: 2 additions & 0 deletions MEOS.NET/Functions/Meos.pgsql_compat.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

using System.Runtime.InteropServices;

using MEOS.NET.Structures;

namespace MEOS.NET.Functions
{
/// <summary>The MEOS functions <c>pgsql_compat.h</c> declares.</summary>
Expand Down
2 changes: 2 additions & 0 deletions MEOS.NET/Functions/Meos.pgtypes.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

using System.Runtime.InteropServices;

using MEOS.NET.Structures;

namespace MEOS.NET.Functions
{
/// <summary>The MEOS functions <c>pgtypes.h</c> declares.</summary>
Expand Down
Loading
Loading