Skip to content

Commit

Permalink
[Bot] Automated ReSharper CLT update
Browse files Browse the repository at this point in the history
  • Loading branch information
kreghek committed Apr 30, 2021
1 parent 1eb0daf commit 26319fd
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
29 changes: 22 additions & 7 deletions Zilon.Core/Zilon.Core.Tests/Common/TestCases/HexHelperTestCases.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections;
using System;
using System.Collections;

using NUnit.Framework;

Expand All @@ -10,16 +11,28 @@ public static IEnumerable TestCases
{
get
{
static float sqrt(float a) => (float)System.Math.Sqrt(a);
static float sqrt(float a)
{
return (float)Math.Sqrt(a);
}

static int round(float a) => (int)System.Math.Round(a, System.MidpointRounding.ToEven);
static int round(float a)
{
return (int)Math.Round(a, MidpointRounding.ToEven);
}

// Step left is pointy top hex width on x-axis.
// Step depends on hex size (radius of covered round).
static int stepLeft(float size) => round(size * sqrt(3));
static int stepLeft(float size)
{
return round(size * sqrt(3));
}

// Step top is vertical spacing between hex.
static int stepTop(float size) => round(size * 2 * 3f / 4f);
static int stepTop(float size)
{
return round(size * 2 * 3f / 4f);
}

// Params:
// world x coordinate
Expand All @@ -31,8 +44,10 @@ public static IEnumerable TestCases
yield return new TestCaseData(stepLeft(50), 0, 50).Returns(new OffsetCoords(1, 0));

yield return new TestCaseData(stepLeft(50) / 2, stepTop(50), 50).Returns(new OffsetCoords(0, 1));
yield return new TestCaseData(stepLeft(50) + stepLeft(50) / 2, stepTop(50), 50).Returns(new OffsetCoords(1, 1));
yield return new TestCaseData(3 * stepLeft(50) + stepLeft(50) / 2, stepTop(50), 50).Returns(new OffsetCoords(3, 1));
yield return new TestCaseData(stepLeft(50) + stepLeft(50) / 2, stepTop(50), 50).Returns(
new OffsetCoords(1, 1));
yield return new TestCaseData(3 * stepLeft(50) + stepLeft(50) / 2, stepTop(50), 50).Returns(
new OffsetCoords(3, 1));

yield return new TestCaseData(0, 2 * stepTop(50), 50).Returns(new OffsetCoords(0, 2));

Expand Down
6 changes: 5 additions & 1 deletion Zilon.Core/Zilon.Core/Common/HexHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@ public static AxialCoords ConvertWorldToAxial(int worldX, int worldY, int size)
{
// see https://habr.com/ru/post/319644/

static float sqrt(float a) => (float)Math.Sqrt(a);
static float sqrt(float a)
{
return (float)Math.Sqrt(a);
}

var q = (sqrt(3) / 3f * worldX - worldY / 3f) / size;
var r = (2f / 3f * worldY) / size;
var axialCoords = new AxialCoords(q, r);
Expand Down

0 comments on commit 26319fd

Please # to comment.