diff --git a/MapToolkit.Drawing.Topographic/MapToolkit.Drawing.Topographic.csproj b/MapToolkit.Drawing.Topographic/MapToolkit.Drawing.Topographic.csproj index 10085b4..27edfb9 100644 --- a/MapToolkit.Drawing.Topographic/MapToolkit.Drawing.Topographic.csproj +++ b/MapToolkit.Drawing.Topographic/MapToolkit.Drawing.Topographic.csproj @@ -4,6 +4,7 @@ net8.0 enable enable + true diff --git a/MapToolkit.Drawing/ImageRender/ImageStyle.cs b/MapToolkit.Drawing/ImageRender/ImageStyle.cs index c97f530..976e516 100644 --- a/MapToolkit.Drawing/ImageRender/ImageStyle.cs +++ b/MapToolkit.Drawing/ImageRender/ImageStyle.cs @@ -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; } diff --git a/MapToolkit.Drawing/ImageTiler.cs b/MapToolkit.Drawing/ImageTiler.cs index ecf4255..c8d1e74 100644 --- a/MapToolkit.Drawing/ImageTiler.cs +++ b/MapToolkit.Drawing/ImageTiler.cs @@ -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); } } diff --git a/MapToolkit.Drawing/MapToolkit.Drawing.csproj b/MapToolkit.Drawing/MapToolkit.Drawing.csproj index 1038651..26370d2 100644 --- a/MapToolkit.Drawing/MapToolkit.Drawing.csproj +++ b/MapToolkit.Drawing/MapToolkit.Drawing.csproj @@ -4,6 +4,7 @@ net8.0 enable enable + true diff --git a/MapToolkit.Drawing/Pen.cs b/MapToolkit.Drawing/Pen.cs index 7cc4194..5b37cfe 100644 --- a/MapToolkit.Drawing/Pen.cs +++ b/MapToolkit.Drawing/Pen.cs @@ -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); } diff --git a/MapToolkit.Drawing/Render.cs b/MapToolkit.Drawing/Render.cs index a3676d7..de9ee29 100644 --- a/MapToolkit.Drawing/Render.cs +++ b/MapToolkit.Drawing/Render.cs @@ -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 => { diff --git a/MapToolkit.Drawing/SolidColorBrush.cs b/MapToolkit.Drawing/SolidColorBrush.cs index a77a57d..2d7a933 100644 --- a/MapToolkit.Drawing/SolidColorBrush.cs +++ b/MapToolkit.Drawing/SolidColorBrush.cs @@ -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); } diff --git a/MapToolkit.Drawing/SvgRender/SvgSurface.cs b/MapToolkit.Drawing/SvgRender/SvgSurface.cs index bc52473..0dbdec2 100644 --- a/MapToolkit.Drawing/SvgRender/SvgSurface.cs +++ b/MapToolkit.Drawing/SvgRender/SvgSurface.cs @@ -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(); diff --git a/MapToolkit.Drawing/VectorBrush.cs b/MapToolkit.Drawing/VectorBrush.cs index 6abeda4..c7d9b60 100644 --- a/MapToolkit.Drawing/VectorBrush.cs +++ b/MapToolkit.Drawing/VectorBrush.cs @@ -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); } diff --git a/MapToolkit/DataCells/PixelFormats/Int16Pixel.cs b/MapToolkit/DataCells/PixelFormats/Int16Pixel.cs index 1eefdac..2b27115 100644 --- a/MapToolkit/DataCells/PixelFormats/Int16Pixel.cs +++ b/MapToolkit/DataCells/PixelFormats/Int16Pixel.cs @@ -10,7 +10,7 @@ internal sealed class Int16Pixel : DemPixel public override short Average(IEnumerable value) { - return (short)value.Cast().Average(); + return (short)value.Select(v => (int)v).Average(); } public override bool IsNoValue(short value) diff --git a/MapToolkit/DataCells/PixelFormats/UInt16Pixel.cs b/MapToolkit/DataCells/PixelFormats/UInt16Pixel.cs index 6fa3bb3..3cf9d29 100644 --- a/MapToolkit/DataCells/PixelFormats/UInt16Pixel.cs +++ b/MapToolkit/DataCells/PixelFormats/UInt16Pixel.cs @@ -10,7 +10,7 @@ internal sealed class UInt16Pixel : DemPixel public override ushort Average(IEnumerable value) { - return (ushort) value.Cast().Average(); + return (ushort) value.Select(v => (int)v).Average(); } public override bool IsNoValue(ushort value) diff --git a/MapToolkit/Databases/DemDatabaseIndexContext.cs b/MapToolkit/Databases/DemDatabaseIndexContext.cs new file mode 100644 index 0000000..ee89de6 --- /dev/null +++ b/MapToolkit/Databases/DemDatabaseIndexContext.cs @@ -0,0 +1,9 @@ +using System.Text.Json.Serialization; + +namespace MapToolkit.Databases +{ + [JsonSerializable(typeof(DemDatabaseIndex))] + internal partial class DemDatabaseIndexContext : JsonSerializerContext + { + } +} diff --git a/MapToolkit/Databases/DemFileSystemStorage.cs b/MapToolkit/Databases/DemFileSystemStorage.cs index 570d70f..eb61f83 100644 --- a/MapToolkit/Databases/DemFileSystemStorage.cs +++ b/MapToolkit/Databases/DemFileSystemStorage.cs @@ -24,7 +24,7 @@ public async Task ReadIndex() { using (var input = File.OpenRead(indexFile)) { - return (await JsonSerializer.DeserializeAsync(input).ConfigureAwait(false))!; + return (await JsonSerializer.DeserializeAsync(input, DemDatabaseIndexContext.Default.DemDatabaseIndex).ConfigureAwait(false))!; } } return BuildIndex(); diff --git a/MapToolkit/Databases/DemHttpStorage.cs b/MapToolkit/Databases/DemHttpStorage.cs index a2fb6cc..7cba0bf 100644 --- a/MapToolkit/Databases/DemHttpStorage.cs +++ b/MapToolkit/Databases/DemHttpStorage.cs @@ -32,11 +32,11 @@ public DemHttpStorage(Uri baseAddress) public async Task 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)) @@ -54,7 +54,7 @@ public async Task ReadIndex() { using (var input = await client.GetStreamAsync("index.json").ConfigureAwait(false)) { - return (await JsonSerializer.DeserializeAsync(input).ConfigureAwait(false))!; + return (await JsonSerializer.DeserializeAsync(input, DemDatabaseIndexContext.Default.DemDatabaseIndex).ConfigureAwait(false))!; } } } diff --git a/MapToolkit/MapToolkit.csproj b/MapToolkit/MapToolkit.csproj index ff7ab34..1a6fb58 100644 --- a/MapToolkit/MapToolkit.csproj +++ b/MapToolkit/MapToolkit.csproj @@ -7,6 +7,7 @@ https://github.com/jetelain/mapkit MIT 1.0.0-alpha1 + true diff --git a/MapToolkit/Utils/clipper.cs b/MapToolkit/Utils/clipper.cs index a9f334e..89fe9cb 100644 --- a/MapToolkit/Utils/clipper.cs +++ b/MapToolkit/Utils/clipper.cs @@ -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; @@ -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) @@ -492,9 +492,9 @@ public class IntersectNode public class MyIntersectNodeSort : IComparer { - 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;