Skip to content

Commit

Permalink
Merge pull request #17 from juliangiebel/2024.06.01-fix-tiling-roundi…
Browse files Browse the repository at this point in the history
…ng-issues

Fix tiling rounding issues
  • Loading branch information
juliangiebel authored Jun 1, 2024
2 parents 28f846e + 54361d4 commit ee024bd
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
6 changes: 3 additions & 3 deletions SS14.MapServer.Tests/ImageProcessingServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace SS14.MapServer.Tests;

public class ImageProcessingServiceTests
{
private const string ResourcePath = "resources/tiling_test_source.png";
private const string ResourcePath = "resources/saltern.webp";
private const string OutputPath = "test";

private ImageProcessingService? _processingService;
Expand All @@ -33,11 +33,11 @@ public void Setup()
[Test]
public async Task ImageTilingTest()
{
var tiles = await _processingService!.TileImage(Guid.NewGuid(), 0, _sourcePath!, _targetPath!, 512);
var tiles = await _processingService!.TileImage(Guid.NewGuid(), 0, _sourcePath!, _targetPath!, 256);

Assert.Multiple(() =>
{
Assert.That(tiles, Has.Count.EqualTo(60));
Assert.That(tiles, Has.Count.EqualTo(198));
Assert.That(File.Exists(tiles[0].Path), Is.True);
});
}
Expand Down
Binary file added SS14.MapServer.Tests/resources/saltern.webp
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ public async Task<List<Tile>> TileImage(Guid mapGuid, int gridId, string sourceP
using var image = await Image.LoadAsync(file);

var bounds = image.Bounds;
var heightSteps = bounds.Height / tileSize;
var widthSteps = bounds.Width / tileSize;
var heightSteps = Math.Ceiling((double)bounds.Height / tileSize);
var widthSteps = Math.Ceiling((double)bounds.Width / tileSize);

var tiles = new List<Tile>();
var extension = Path.GetExtension(sourcePath);
Expand All @@ -46,6 +46,8 @@ public async Task<List<Tile>> TileImage(Guid mapGuid, int gridId, string sourceP
for (var x = 0; x < widthSteps; x++)
{
var rectangle = new Rectangle(tileSize * x, tileSize * y, tileSize, tileSize);
rectangle.Intersect(bounds);

var tile = image.Clone(img => img.Crop(rectangle));
var preview = tile.Clone(img => img.Pixelate(8));

Expand Down
2 changes: 1 addition & 1 deletion SS14.MapServer/SS14.MapServer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<Version>1.1.6</Version>
<Version>1.1.7</Version>
</PropertyGroup>

<ItemGroup>
Expand Down

0 comments on commit ee024bd

Please sign in to comment.