Skip to content

Commit 0729000

Browse files
Merge pull request #32 from estebanzimanyi/feat/values-the-wrapper-states
Hand on whatever the wrapper already states as a value
2 parents 970c35e + 32e0d0d commit 0729000

11 files changed

Lines changed: 195 additions & 12 deletions

File tree

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
using MEOS.NET.Enums;
2+
using MEOS.NET.Structures;
3+
using MEOS.NET.Types;
4+
5+
namespace MEOS.NET.Tests
6+
{
7+
/// <summary>
8+
/// Whatever the wrapper already states as a C# value — an enum the catalog
9+
/// names, a scalar behind a MEOS typedef, a struct carried by value — the
10+
/// object layer hands on as that value.
11+
/// </summary>
12+
[TestClass]
13+
public class CatalogValueTypeTests : MeosTest
14+
{
15+
[TestMethod]
16+
public void AnEnumArgumentIsTheEnumTheCatalogNames()
17+
{
18+
TJsonb temp = (TJsonb)TJsonb.In(
19+
"[{\"a\": [1, 2]}@2024-12-06, {\"a\": [1, 2]}@2024-12-08]")!;
20+
21+
Temporal? first = temp.ArrayElement(0, true, NullHandleType.NullJsonNull);
22+
23+
Assert.IsNotNull(first);
24+
}
25+
26+
[TestMethod]
27+
public void AScalarBehindATypedefComesBackAsThatScalar()
28+
{
29+
Geo point = Geo.FromText("POINT(1 1)", 4326)!;
30+
31+
ulong cell = point.ToS2cellCell(10);
32+
33+
Assert.AreNotEqual(0UL, cell);
34+
}
35+
36+
[TestMethod]
37+
public void AStructReturnedByValueComesBackAsTheStruct()
38+
{
39+
TPoint trip = (TPoint)TGeomPoint.In(
40+
"[POINT(0 0)@2024-12-06, POINT(2 2)@2024-12-08]")!;
41+
STBox bounds = STBox.In("STBOX X((-1,-1),(3,3))")!;
42+
43+
MvtGeom mvt = trip.AsMvtgeom(bounds, 4096, 0, true);
44+
45+
Assert.AreNotEqual(IntPtr.Zero, mvt.geom);
46+
Assert.IsTrue(mvt.count > 0);
47+
}
48+
}
49+
}

MEOS.NET/Functions/Meos.Native.g.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9213,6 +9213,24 @@ private static partial class Native
92139213
[LibraryImport(DllPath, EntryPoint = "geo_edge_ctx_make", StringMarshalling = StringMarshalling.Utf8)]
92149214
internal static partial IntPtr GeoEdgeCtxMake(IntPtr gs);
92159215

9216+
[LibraryImport(DllPath, EntryPoint = "geo_is_planar_linear", StringMarshalling = StringMarshalling.Utf8)]
9217+
[return: MarshalAs(UnmanagedType.U1)]
9218+
internal static partial bool GeoIsPlanarLinear(IntPtr gs);
9219+
9220+
[LibraryImport(DllPath, EntryPoint = "geo_is_point_set", StringMarshalling = StringMarshalling.Utf8)]
9221+
[return: MarshalAs(UnmanagedType.U1)]
9222+
internal static partial bool GeoIsPointSet(IntPtr gs);
9223+
9224+
[LibraryImport(DllPath, EntryPoint = "geo_meos_supported", StringMarshalling = StringMarshalling.Utf8)]
9225+
[return: MarshalAs(UnmanagedType.U1)]
9226+
internal static partial bool GeoMeosSupported(IntPtr gs);
9227+
9228+
[LibraryImport(DllPath, EntryPoint = "geo_points_covered", StringMarshalling = StringMarshalling.Utf8)]
9229+
internal static partial IntPtr GeoPointsCovered(IntPtr pts, IntPtr gs, [MarshalAs(UnmanagedType.U1)] bool covered);
9230+
9231+
[LibraryImport(DllPath, EntryPoint = "geo_clip_linear_geom", StringMarshalling = StringMarshalling.Utf8)]
9232+
internal static partial IntPtr GeoClipLinearGeom(IntPtr line, IntPtr gs, [MarshalAs(UnmanagedType.U1)] bool inside);
9233+
92169234
[LibraryImport(DllPath, EntryPoint = "geo_edge_ctx_free", StringMarshalling = StringMarshalling.Utf8)]
92179235
internal static partial void GeoEdgeCtxFree(IntPtr ctx);
92189236

MEOS.NET/Functions/Meos.meos_internal_geo.g.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,21 @@ public static IntPtr TgeoseqsetRestrictStbox(IntPtr ss, IntPtr box, bool border_
252252
public static IntPtr GeoEdgeCtxMake(IntPtr gs)
253253
=> SafeExecution<IntPtr>(() => Native.GeoEdgeCtxMake(gs));
254254

255+
public static bool GeoIsPlanarLinear(IntPtr gs)
256+
=> SafeExecution<bool>(() => Native.GeoIsPlanarLinear(gs));
257+
258+
public static bool GeoIsPointSet(IntPtr gs)
259+
=> SafeExecution<bool>(() => Native.GeoIsPointSet(gs));
260+
261+
public static bool GeoMeosSupported(IntPtr gs)
262+
=> SafeExecution<bool>(() => Native.GeoMeosSupported(gs));
263+
264+
public static IntPtr GeoPointsCovered(IntPtr pts, IntPtr gs, bool covered)
265+
=> SafeExecution<IntPtr>(() => Native.GeoPointsCovered(pts, gs, covered));
266+
267+
public static IntPtr GeoClipLinearGeom(IntPtr line, IntPtr gs, bool inside)
268+
=> SafeExecution<IntPtr>(() => Native.GeoClipLinearGeom(line, gs, inside));
269+
255270
public static void GeoEdgeCtxFree(IntPtr ctx)
256271
=> SafeExecution(() => Native.GeoEdgeCtxFree(ctx));
257272

MEOS.NET/Types/Geo.g.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ public ulong ToH3indexCell(int resolution)
9696
public ulong ToQuadbinCell(int resolution)
9797
=> Meos.GeoToQuadbinCell(this.Ptr, resolution);
9898

99+
public ulong ToS2cellCell(int level)
100+
=> Meos.GeoToS2cellCell(this.Ptr, level);
101+
99102
public Set? ToSet()
100103
=> MEOSFactory.WrapSet(Meos.GeoToSet(this.Ptr));
101104

MEOS.NET/Types/Jsonb.g.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,12 @@ public bool ToBool()
233233
public string ToCstring()
234234
=> Meos.JsonbToCstring(this.Ptr);
235235

236+
public float ToFloat4()
237+
=> Meos.JsonbToFloat4(this.Ptr);
238+
239+
public double ToFloat8()
240+
=> Meos.JsonbToFloat8(this.Ptr);
241+
236242
public short ToInt16()
237243
=> Meos.JsonbToInt16(this.Ptr);
238244

MEOS.NET/Types/Raquet.g.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,25 @@ public int Width()
143143
public static Raquet? In(string str)
144144
=> MEOSFactory.WrapRaquet(Meos.RaquetIn(str));
145145

146+
public static Raquet? Make(ulong quadbin, int width, int height, MeosPixType pixtype, double nodata, bool has_nodata, byte[] pixels)
147+
{
148+
GCHandle _pixels = GCHandle.Alloc(pixels, GCHandleType.Pinned);
149+
try
150+
{
151+
return MEOSFactory.WrapRaquet(Meos.RaquetMake(quadbin, width, height, (int) pixtype, nodata, has_nodata, _pixels.AddrOfPinnedObject(), (ulong) pixels.Length));
152+
}
153+
finally
154+
{
155+
_pixels.Free();
156+
}
157+
}
158+
159+
public static MeosPixType PixtypeFromString(string str)
160+
=> (MeosPixType) Meos.RaquetPixtypeFromString(str);
161+
162+
public static ulong PixtypeSize(MeosPixType pixtype)
163+
=> Meos.RaquetPixtypeSize((int) pixtype);
164+
146165
public static Raquet? Read(string path, ulong quadbin)
147166
=> MEOSFactory.WrapRaquet(Meos.RaquetRead(path, quadbin));
148167

MEOS.NET/Types/TGeo.g.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ internal TGeo(IntPtr ptr) : base(ptr) { }
6161
public STBox?[] SpaceBoxes(double xsize, double ysize, double zsize, Geo sorigin, bool bitmatrix, bool border_inc)
6262
=> MEOSFactory.WrapSTBoxArray(Meos.TgeoSpaceBoxes(this.Ptr, xsize, ysize, zsize, sorigin.Ptr, bitmatrix, border_inc));
6363

64+
public SpaceSplit SpaceSplit(double xsize, double ysize, double zsize, Geo sorigin, bool bitmatrix, bool border_inc)
65+
=> Meos.TgeoSpaceSplit(this.Ptr, xsize, ysize, zsize, sorigin.Ptr, bitmatrix, border_inc);
66+
6467
public STBox?[] SpaceTimeBoxes(double xsize, double ysize, double zsize, Interval duration, Geo sorigin, DateTime torigin, bool bitmatrix, bool border_inc)
6568
{
6669
IntPtr _duration = Marshal.AllocHGlobal(Marshal.SizeOf<Interval>());
@@ -75,6 +78,20 @@ internal TGeo(IntPtr ptr) : base(ptr) { }
7578
}
7679
}
7780

81+
public SpaceTimeSplit SpaceTimeSplit(double xsize, double ysize, double zsize, Interval duration, Geo sorigin, DateTime torigin, bool bitmatrix, bool border_inc)
82+
{
83+
IntPtr _duration = Marshal.AllocHGlobal(Marshal.SizeOf<Interval>());
84+
try
85+
{
86+
Marshal.StructureToPtr(duration, _duration, false);
87+
return Meos.TgeoSpaceTimeSplit(this.Ptr, xsize, ysize, zsize, _duration, sorigin.Ptr, MEOSConvert.ToTimestampTz(torigin), bitmatrix, border_inc);
88+
}
89+
finally
90+
{
91+
Marshal.FreeHGlobal(_duration);
92+
}
93+
}
94+
7895
public STBox?[] SplitEachNStboxes(int elem_count)
7996
=> MEOSFactory.WrapSTBoxArray(Meos.TgeoSplitEachNStboxes(this.Ptr, elem_count));
8097

MEOS.NET/Types/TJsonb.g.cs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ internal TJsonb(IntPtr ptr) : base(ptr) { }
1818
public override string ToString()
1919
=> this.Out();
2020

21+
public Temporal? ArrayElement(int idx, bool astext, NullHandleType null_handle)
22+
=> MEOSFactory.WrapTemporal(Meos.TjsonbArrayElement(this.Ptr, idx, astext, (int) null_handle));
23+
2124
public Temporal? ArrayLength()
2225
=> MEOSFactory.WrapTemporal(Meos.TjsonbArrayLength(this.Ptr));
2326

@@ -131,6 +134,25 @@ public override string ToString()
131134
}
132135
}
133136

137+
public Temporal? ExtractPath(Text[] path_elems, bool astext, NullHandleType null_handle)
138+
{
139+
IntPtr[] _path_elemsValues = new IntPtr[path_elems.Length];
140+
for (int i = 0; i < path_elems.Length; i++)
141+
{
142+
_path_elemsValues[i] = path_elems[i].Ptr;
143+
}
144+
145+
GCHandle _path_elems = GCHandle.Alloc(_path_elemsValues, GCHandleType.Pinned);
146+
try
147+
{
148+
return MEOSFactory.WrapTemporal(Meos.TjsonbExtractPath(this.Ptr, _path_elems.AddrOfPinnedObject(), path_elems.Length, astext, (int) null_handle));
149+
}
150+
finally
151+
{
152+
_path_elems.Free();
153+
}
154+
}
155+
134156
public Temporal? Insert(Text[] keys, Jsonb newjb, bool after)
135157
{
136158
IntPtr[] _keysValues = new IntPtr[keys.Length];
@@ -153,6 +175,9 @@ public override string ToString()
153175
public Temporal? MinusValue(Jsonb jsb)
154176
=> MEOSFactory.WrapTemporal(Meos.TjsonbMinusValue(this.Ptr, jsb.Ptr));
155177

178+
public Temporal? ObjectField(Text key, bool astext, NullHandleType null_handle)
179+
=> MEOSFactory.WrapTemporal(Meos.TjsonbObjectField(this.Ptr, key.Ptr, astext, (int) null_handle));
180+
156181
public string Out()
157182
=> Meos.TjsonbOut(this.Ptr);
158183

@@ -184,9 +209,21 @@ public string Out()
184209
public Temporal? StripNulls(bool strip_in_arrays)
185210
=> MEOSFactory.WrapTemporal(Meos.TjsonbStripNulls(this.Ptr, strip_in_arrays));
186211

212+
public Temporal? ToTbool(string key, NullHandleType null_handle)
213+
=> MEOSFactory.WrapTemporal(Meos.TjsonbToTbool(this.Ptr, key, (int) null_handle));
214+
215+
public Temporal? ToTfloat(string key, InterpType interp, NullHandleType null_handle)
216+
=> MEOSFactory.WrapTemporal(Meos.TjsonbToTfloat(this.Ptr, key, (int) interp, (int) null_handle));
217+
218+
public Temporal? ToTint(string key, NullHandleType null_handle)
219+
=> MEOSFactory.WrapTemporal(Meos.TjsonbToTint(this.Ptr, key, (int) null_handle));
220+
187221
public Temporal? ToTtext()
188222
=> MEOSFactory.WrapTemporal(Meos.TjsonbToTtext(this.Ptr));
189223

224+
public Temporal? ToTtextKey(string key, NullHandleType null_handle)
225+
=> MEOSFactory.WrapTemporal(Meos.TjsonbToTtextKey(this.Ptr, key, (int) null_handle));
226+
190227
public Jsonb? ValueAtTimestamptz(DateTime t, bool strict)
191228
{
192229
IntPtr _value = Marshal.AllocHGlobal(8);

MEOS.NET/Types/TPoint.g.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ internal TPoint(IntPtr ptr) : base(ptr) { }
1717
public Temporal? AngularDifference()
1818
=> MEOSFactory.WrapTemporal(Meos.TpointAngularDifference(this.Ptr));
1919

20+
public MvtGeom AsMvtgeom(STBox bounds, int extent, int buffer, bool clip_geom)
21+
=> Meos.TpointAsMvtgeom(this.Ptr, bounds.Ptr, extent, buffer, clip_geom);
22+
2023
public Temporal? AtElevation(Span s)
2124
=> MEOSFactory.WrapTemporal(Meos.TpointAtElevation(this.Ptr, s.Ptr));
2225

MEOS.NET/Types/Text.g.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ internal Text(IntPtr ptr) : base(ptr) { }
1818
public override string ToString()
1919
=> this.Out();
2020

21+
public uint Hash(uint collid)
22+
=> Meos.TextHash(this.Ptr, collid);
23+
24+
public ulong HashExtended(ulong seed, uint collid)
25+
=> Meos.TextHashExtended(this.Ptr, seed, collid);
26+
2127
public Text? Initcap()
2228
=> MEOSFactory.WrapText(Meos.TextInitcap(this.Ptr));
2329

0 commit comments

Comments
 (0)