Skip to content

Commit

Permalink
Fix CodeFactor Issues - [SA1407]
Browse files Browse the repository at this point in the history
  • Loading branch information
kreghek committed May 1, 2021
1 parent 1eb0daf commit e2cdd75
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ 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
7 changes: 5 additions & 2 deletions Zilon.Core/Zilon.Core/Common/HexHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,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);
var q = (sqrt(3) / 3f * worldX - worldY / 3f) / size;
var r = (2f / 3f * worldY) / size;

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

return axialCoords;
Expand Down

0 comments on commit e2cdd75

Please # to comment.