Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AOT Compilation #11

Merged
merged 1 commit into from
Jun 19, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsAotCompatible>true</IsAotCompatible>
</PropertyGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions MapToolkit.Drawing/ImageRender/ImageStyle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ public ImageStyle(IBrush? fill, Pen? pen)
{
if (pen.Pattern != null)
{
return new SixLabors.ImageSharp.Drawing.Processing.PatternPen(ToBrush(pen.Brush), (float)pen.Width, pen.Pattern.Select(v => (float)(v/pen.Width)).ToArray());
return new SixLabors.ImageSharp.Drawing.Processing.PatternPen(ToBrush(pen.Brush) ?? throw new ArgumentException(), (float)pen.Width, pen.Pattern.Select(v => (float)(v/pen.Width)).ToArray());
}
return new SixLabors.ImageSharp.Drawing.Processing.SolidPen(ToBrush(pen.Brush), (float)pen.Width);
return new SixLabors.ImageSharp.Drawing.Processing.SolidPen(ToBrush(pen.Brush) ?? throw new ArgumentException(), (float)pen.Width);
}
return null;
}
Expand Down
2 changes: 1 addition & 1 deletion MapToolkit.Drawing/ImageTiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ private static void GenerateTilesAtZoomLevel(Image fullImage, string targetDirec
{
var tile = fullImage.Clone(i => i.Crop(new Rectangle(x, y, tileSize, tileSize)));
var file = Path.Combine(targetDirectory, FormattableString.Invariant($"{zoomLevel}/{x / tileSize}/{y / tileSize}.{ext}"));
Directory.CreateDirectory(Path.GetDirectoryName(file));
Directory.CreateDirectory(Path.GetDirectoryName(file)!);
save(tile,file);
}
}
Expand Down
1 change: 1 addition & 0 deletions MapToolkit.Drawing/MapToolkit.Drawing.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsAotCompatible>true</IsAotCompatible>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion MapToolkit.Drawing/Pen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public bool Equals(Pen? other)
return false;
}

public override bool Equals(object obj)
public override bool Equals(object? obj)
{
return Equals(obj as Pen);
}
Expand Down
2 changes: 1 addition & 1 deletion MapToolkit.Drawing/Render.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ private static void SvgTileLevel(string targetDirectory, int zoomLevel, MemorySu

ToSvg(file, tileSize, t => new MemDrawClipped(surface, t, pos, pos + tileSize).Draw());

if (generateWebpFallback)
if (image != null)
{
image.Mutate(p =>
{
Expand Down
2 changes: 1 addition & 1 deletion MapToolkit.Drawing/SolidColorBrush.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public bool Equals(SolidColorBrush? other)
return other != null && Color.Equals(other.Color);
}

public override bool Equals(object obj)
public override bool Equals(object? obj)
{
return Equals(obj as SolidColorBrush);
}
Expand Down
1 change: 0 additions & 1 deletion MapToolkit.Drawing/SvgRender/SvgSurface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ internal sealed class SvgSurface : IDrawSurface, IDisposable
private int nextPathId = 0;
private int nextStyleId = 0;
private int nextBrushId = 0;
private int nextImageId = 0;
private readonly int rounding = 1;
private bool isWrittingStyle = false;
private readonly StringBuilder styles = new StringBuilder();
Expand Down
2 changes: 1 addition & 1 deletion MapToolkit.Drawing/VectorBrush.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public bool Equals(IBrush? other)
return other == this;
}

public override bool Equals(object obj)
public override bool Equals(object? obj)
{
return Equals(obj as VectorBrush);
}
Expand Down
2 changes: 1 addition & 1 deletion MapToolkit/DataCells/PixelFormats/Int16Pixel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ internal sealed class Int16Pixel : DemPixel<short>

public override short Average(IEnumerable<short> value)
{
return (short)value.Cast<int>().Average();
return (short)value.Select(v => (int)v).Average();
}

public override bool IsNoValue(short value)
Expand Down
2 changes: 1 addition & 1 deletion MapToolkit/DataCells/PixelFormats/UInt16Pixel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ internal sealed class UInt16Pixel : DemPixel<ushort>

public override ushort Average(IEnumerable<ushort> value)
{
return (ushort) value.Cast<int>().Average();
return (ushort) value.Select(v => (int)v).Average();
}

public override bool IsNoValue(ushort value)
Expand Down
9 changes: 9 additions & 0 deletions MapToolkit/Databases/DemDatabaseIndexContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System.Text.Json.Serialization;

namespace MapToolkit.Databases
{
[JsonSerializable(typeof(DemDatabaseIndex))]
internal partial class DemDatabaseIndexContext : JsonSerializerContext
{
}
}
2 changes: 1 addition & 1 deletion MapToolkit/Databases/DemFileSystemStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public async Task<DemDatabaseIndex> ReadIndex()
{
using (var input = File.OpenRead(indexFile))
{
return (await JsonSerializer.DeserializeAsync<DemDatabaseIndex>(input).ConfigureAwait(false))!;
return (await JsonSerializer.DeserializeAsync<DemDatabaseIndex>(input, DemDatabaseIndexContext.Default.DemDatabaseIndex).ConfigureAwait(false))!;
}
}
return BuildIndex();
Expand Down
6 changes: 3 additions & 3 deletions MapToolkit/Databases/DemHttpStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ public DemHttpStorage(Uri baseAddress)

public async Task<IDemDataCell> Load(string path)
{
var uri = new Uri(client.BaseAddress, path);
var uri = new Uri(client.BaseAddress!, path);
var cacheFile = Path.Combine(localCache, uri.DnsSafeHost, uri.AbsolutePath.Substring(1).Replace('/', Path.DirectorySeparatorChar));
if(!File.Exists(cacheFile))
{
Directory.CreateDirectory(Path.GetDirectoryName(cacheFile));
Directory.CreateDirectory(Path.GetDirectoryName(cacheFile)!);
// XXX: Limit cache size ?
// XXX: Cache invalidation ?
using (var input = await client.GetStreamAsync(path).ConfigureAwait(false))
Expand All @@ -54,7 +54,7 @@ public async Task<DemDatabaseIndex> ReadIndex()
{
using (var input = await client.GetStreamAsync("index.json").ConfigureAwait(false))
{
return (await JsonSerializer.DeserializeAsync<DemDatabaseIndex>(input).ConfigureAwait(false))!;
return (await JsonSerializer.DeserializeAsync<DemDatabaseIndex>(input, DemDatabaseIndexContext.Default.DemDatabaseIndex).ConfigureAwait(false))!;
}
}
}
Expand Down
1 change: 1 addition & 0 deletions MapToolkit/MapToolkit.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<RepositoryUrl>https://github.com/jetelain/mapkit</RepositoryUrl>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<Version>1.0.0-alpha1</Version>
<IsAotCompatible>true</IsAotCompatible>
</PropertyGroup>
<ItemGroup>
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">
Expand Down
8 changes: 4 additions & 4 deletions MapToolkit/Utils/clipper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ public bool IsNegative()
return !(val1 == val2);
}

public override bool Equals(System.Object obj)
public override bool Equals(System.Object? obj)
{
if (obj == null || !(obj is Int128))
return false;
Expand Down Expand Up @@ -409,7 +409,7 @@ public IntPoint(IntPoint pt)
return a.X != b.X || a.Y != b.Y;
}

public override bool Equals(object obj)
public override bool Equals(object? obj)
{
if (obj == null) return false;
if (obj is IntPoint)
Expand Down Expand Up @@ -492,9 +492,9 @@ public class IntersectNode

public class MyIntersectNodeSort : IComparer<IntersectNode>
{
public int Compare(IntersectNode node1, IntersectNode node2)
public int Compare(IntersectNode? node1, IntersectNode? node2)
{
cInt i = node2.Pt.Y - node1.Pt.Y;
cInt i = node2!.Pt.Y - node1!.Pt.Y;
if (i > 0) return 1;
else if (i < 0) return -1;
else return 0;
Expand Down
Loading