284 lines
7.1 KiB
C#
284 lines
7.1 KiB
C#
using Microsoft.Xna.Framework;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using Xunit;
|
|
|
|
namespace SemiColinGames.Tests {
|
|
public class LineTests {
|
|
[Fact]
|
|
public void TestRasterizeSinglePoint() {
|
|
var p1 = new Point(10, 10);
|
|
var expected = new Point[] { p1 };
|
|
var result = new List<Point>();
|
|
Line.Rasterize(p1, p1, result);
|
|
Assert.Equal(expected, result);
|
|
}
|
|
|
|
[Fact]
|
|
public void TestRasterizeHorizontal() {
|
|
var p1 = new Point(10, 10);
|
|
var p2 = new Point(15, 10);
|
|
var expected = new Point[] {
|
|
new Point(10, 10),
|
|
new Point(11, 10),
|
|
new Point(12, 10),
|
|
new Point(13, 10),
|
|
new Point(14, 10),
|
|
new Point(15, 10)
|
|
};
|
|
var result = new List<Point>();
|
|
Line.Rasterize(p1, p2, result);
|
|
Assert.Equal(expected, result);
|
|
}
|
|
|
|
[Fact]
|
|
public void TestRasterizeHorizontalReverse() {
|
|
var p1 = new Point(15, 10);
|
|
var p2 = new Point(10, 10);
|
|
var expected = new Point[] {
|
|
new Point(15, 10),
|
|
new Point(14, 10),
|
|
new Point(13, 10),
|
|
new Point(12, 10),
|
|
new Point(11, 10),
|
|
new Point(10, 10)
|
|
};
|
|
var result = new List<Point>();
|
|
Line.Rasterize(p1, p2, result);
|
|
Assert.Equal(expected, result);
|
|
}
|
|
|
|
[Fact]
|
|
public void TestRasterizeVertical() {
|
|
var p1 = new Point(10, 10);
|
|
var p2 = new Point(10, 15);
|
|
var expected = new Point[] {
|
|
new Point(10, 10),
|
|
new Point(10, 11),
|
|
new Point(10, 12),
|
|
new Point(10, 13),
|
|
new Point(10, 14),
|
|
new Point(10, 15)
|
|
};
|
|
var result = new List<Point>();
|
|
Line.Rasterize(p1, p2, result);
|
|
Assert.Equal(expected, result);
|
|
}
|
|
|
|
[Fact]
|
|
public void TestRasterizeVerticalReverse() {
|
|
var p1 = new Point(10, 15);
|
|
var p2 = new Point(10, 10);
|
|
var expected = new Point[] {
|
|
new Point(10, 15),
|
|
new Point(10, 14),
|
|
new Point(10, 13),
|
|
new Point(10, 12),
|
|
new Point(10, 11),
|
|
new Point(10, 10)
|
|
};
|
|
var result = new List<Point>();
|
|
Line.Rasterize(p1, p2, result);
|
|
Assert.Equal(expected, result);
|
|
}
|
|
|
|
[Fact]
|
|
public void TestRasterizeDiagonalPosPos() {
|
|
var p1 = new Point(0, 0);
|
|
var p2 = new Point(5, 5);
|
|
var expected = new Point[] {
|
|
new Point(0, 0),
|
|
new Point(1, 1),
|
|
new Point(2, 2),
|
|
new Point(3, 3),
|
|
new Point(4, 4),
|
|
new Point(5, 5)
|
|
};
|
|
var result = new List<Point>();
|
|
Line.Rasterize(p1, p2, result);
|
|
Assert.Equal(expected, result);
|
|
}
|
|
|
|
[Fact]
|
|
public void TestRasterizeDiagonalPosNeg() {
|
|
var p1 = new Point(0, 5);
|
|
var p2 = new Point(5, 0);
|
|
var expected = new Point[] {
|
|
new Point(0, 5),
|
|
new Point(1, 4),
|
|
new Point(2, 3),
|
|
new Point(3, 2),
|
|
new Point(4, 1),
|
|
new Point(5, 0)
|
|
};
|
|
var result = new List<Point>();
|
|
Line.Rasterize(p1, p2, result);
|
|
Assert.Equal(expected, result);
|
|
}
|
|
|
|
[Fact]
|
|
public void TestRasterizeDiagonalNegPos() {
|
|
var p1 = new Point(5, 0);
|
|
var p2 = new Point(0, 5);
|
|
var expected = new Point[] {
|
|
new Point(5, 0),
|
|
new Point(4, 1),
|
|
new Point(3, 2),
|
|
new Point(2, 3),
|
|
new Point(1, 4),
|
|
new Point(0, 5)
|
|
};
|
|
var result = new List<Point>();
|
|
Line.Rasterize(p1, p2, result);
|
|
Assert.Equal(expected, result);
|
|
}
|
|
|
|
[Fact]
|
|
public void TestRasterizeDiagonalNegNeg() {
|
|
var p1 = new Point(5, 5);
|
|
var p2 = new Point(0, 0);
|
|
var expected = new Point[] {
|
|
new Point(5, 5),
|
|
new Point(4, 4),
|
|
new Point(3, 3),
|
|
new Point(2, 2),
|
|
new Point(1, 1),
|
|
new Point(0, 0)
|
|
};
|
|
var result = new List<Point>();
|
|
Line.Rasterize(p1, p2, result);
|
|
Assert.Equal(expected, result);
|
|
}
|
|
|
|
[Fact]
|
|
public void TestRasterizeDoubleSlope() {
|
|
var p1 = new Point(0, 0);
|
|
var p2 = new Point(4, 9);
|
|
var expected = new Point[] {
|
|
new Point(0, 0),
|
|
new Point(0, 1),
|
|
new Point(1, 2),
|
|
new Point(1, 3),
|
|
new Point(2, 4),
|
|
new Point(2, 5),
|
|
new Point(3, 6),
|
|
new Point(3, 7),
|
|
new Point(4, 8),
|
|
new Point(4, 9)
|
|
};
|
|
var result = new List<Point>();
|
|
Line.Rasterize(p1, p2, result);
|
|
Assert.Equal(expected, result);
|
|
}
|
|
|
|
[Fact]
|
|
public void TestRasterizeDoubleSlopePlusOne() {
|
|
var p1 = new Point(0, 0);
|
|
var p2 = new Point(5, 10);
|
|
var expected = new Point[] {
|
|
new Point(0, 0),
|
|
new Point(1, 1),
|
|
new Point(1, 2),
|
|
new Point(2, 3),
|
|
new Point(2, 4),
|
|
new Point(3, 5),
|
|
new Point(3, 6),
|
|
new Point(4, 7),
|
|
new Point(4, 8),
|
|
new Point(5, 9),
|
|
new Point(5, 10)
|
|
};
|
|
var result = new List<Point>();
|
|
Line.Rasterize(p1, p2, result);
|
|
Assert.Equal(expected, result);
|
|
}
|
|
|
|
[Fact]
|
|
public void TestRasterizeDoubleSlopePlusOneReverse() {
|
|
var p1 = new Point(5, 10);
|
|
var p2 = new Point(0, 0);
|
|
var expected = new Point[] {
|
|
new Point(5, 10),
|
|
new Point(4, 9),
|
|
new Point(4, 8),
|
|
new Point(3, 7),
|
|
new Point(3, 6),
|
|
new Point(2, 5),
|
|
new Point(2, 4),
|
|
new Point(1, 3),
|
|
new Point(1, 2),
|
|
new Point(0, 1),
|
|
new Point(0, 0)
|
|
};
|
|
var result = new List<Point>();
|
|
Line.Rasterize(p1, p2, result);
|
|
Assert.Equal(expected, result);
|
|
}
|
|
|
|
[Fact]
|
|
public void TestRasterizeHalfSlope() {
|
|
var p1 = new Point(0, 0);
|
|
var p2 = new Point(9, 4);
|
|
var expected = new Point[] {
|
|
new Point(0, 0),
|
|
new Point(1, 0),
|
|
new Point(2, 1),
|
|
new Point(3, 1),
|
|
new Point(4, 2),
|
|
new Point(5, 2),
|
|
new Point(6, 3),
|
|
new Point(7, 3),
|
|
new Point(8, 4),
|
|
new Point(9, 4)
|
|
};
|
|
var result = new List<Point>();
|
|
Line.Rasterize(p1, p2, result);
|
|
Assert.Equal(expected, result);
|
|
}
|
|
|
|
[Fact]
|
|
public void TestRasterizeHalfSlopePlusOne() {
|
|
var p1 = new Point(0, 0);
|
|
var p2 = new Point(10, 5);
|
|
var expected = new Point[] {
|
|
new Point(0, 0),
|
|
new Point(1, 1),
|
|
new Point(2, 1),
|
|
new Point(3, 2),
|
|
new Point(4, 2),
|
|
new Point(5, 3),
|
|
new Point(6, 3),
|
|
new Point(7, 4),
|
|
new Point(8, 4),
|
|
new Point(9, 5),
|
|
new Point(10, 5)
|
|
};
|
|
var result = new List<Point>();
|
|
Line.Rasterize(p1, p2, result);
|
|
Assert.Equal(expected, result);
|
|
}
|
|
|
|
[Fact]
|
|
public void TestRasterizeHalfSlopePlusOneReverse() {
|
|
var p1 = new Point(10, 5);
|
|
var p2 = new Point(0, 0);
|
|
var expected = new Point[] {
|
|
new Point(10, 5),
|
|
new Point(9, 4),
|
|
new Point(8, 4),
|
|
new Point(7, 3),
|
|
new Point(6, 3),
|
|
new Point(5, 2),
|
|
new Point(4, 2),
|
|
new Point(3, 1),
|
|
new Point(2, 1),
|
|
new Point(1, 0),
|
|
new Point(0, 0)
|
|
};
|
|
var result = new List<Point>();
|
|
Line.Rasterize(p1, p2, result);
|
|
Assert.Equal(expected, result);
|
|
}
|
|
}
|
|
}
|