-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[dlatikay 20210418] #44 levelbeschreibungssprache vereinfachungen und…
… erweiterungen
- Loading branch information
1 parent
4886965
commit 7b97d31
Showing
8 changed files
with
104 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Drawing; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace ScorchGore.Klassen | ||
{ | ||
/// <summary> | ||
/// Eine Implementierung des Bresenham Linienalgorithmus | ||
/// basierend auf einer Idee von https://stackoverflow.com/a/11683720/1132334 | ||
/// </summary> | ||
internal class LinienFolger | ||
{ | ||
public IEnumerable<Point> Bresenham(int startX, int startY, int endX, int endY) | ||
{ | ||
var w = endX - startX; | ||
var h = endY - startY; | ||
var dx1 = Math.Sign(w); | ||
var dy1 = Math.Sign(h); | ||
var dx2 = dx1; | ||
var dy2 = 0; | ||
var longest = Math.Abs(w); | ||
var shortest = Math.Abs(h); | ||
if (longest <= shortest) | ||
{ | ||
longest = Math.Abs(h); | ||
shortest = Math.Abs(w); | ||
dx2 = 0; | ||
dy2 = Math.Sign(h); | ||
} | ||
|
||
var numerator = longest >> 1; | ||
for (var i = 0; i <= longest; ++i) | ||
{ | ||
yield return new Point(startX, startY); | ||
numerator += shortest; | ||
if (numerator < longest) | ||
{ | ||
startX += dx2; | ||
startY += dy2; | ||
} | ||
else | ||
{ | ||
numerator -= longest; | ||
startX += dx1; | ||
startY += dy1; | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters