forked from nibsbin/fractional-line-algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFractionalLineAlgorithmTest.cs
More file actions
66 lines (56 loc) · 2.24 KB
/
Copy pathFractionalLineAlgorithmTest.cs
File metadata and controls
66 lines (56 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
using UnityEngine;
using System.Collections;
using System;
using System.Collections.Generic;
namespace PanLineAlgorithm.Test
{
public class FractionalLineAlgorithmTest : MonoBehaviour
{
const int size = 64;
bool[,] Outlined = new bool[size, size];
public Transform start;
public Transform end;
void OnDrawGizmos()
{
Array.Clear(Outlined, 0, Outlined.Length);
int offset = Outlined.GetLength(0) / 2;
double startX = (double)start.position.x;
double startY = (double)start.position.z;
double endX = (double)end.position.x;
double endY = (double)end.position.z;
//irony lolz
HashSet<FractionalLineAlgorithm.Coordinate> redundancyChecker = new HashSet<FractionalLineAlgorithm.Coordinate>();
foreach (FractionalLineAlgorithm.Coordinate coor in (FractionalLineAlgorithm.Trace (startX,startY,endX,endY)))
{
if (!redundancyChecker.Add(coor))
{
Debug.LogErrorFormat("Redundancy detected for {0}", coor);
}
Outlined [coor.X + offset, coor.Y + offset] = true;
}
Vector3 size = new Vector3(1, .1f, 1);
Vector3 fillSize = new Vector3(.9f, .1f, .9f);
float posOffset = 0f;
for (int i = 0; i < Outlined.GetLength(0); i++)
{
for (int j = 0; j < Outlined.GetLength(1); j++)
{
Vector3 drawPos = new Vector3(i - offset + posOffset, 0, j - offset + posOffset);
if (Outlined [i, j])
{
Gizmos.color = Color.red;
} else
{
Gizmos.color = Color.green;
}
Gizmos.DrawCube(drawPos, fillSize);
Gizmos.color = Color.black;
Gizmos.DrawWireCube(drawPos, size);
}
}
float lineHeight = 0f;
Gizmos.color = Color.white;
Gizmos.DrawLine(new Vector3((float)startX, lineHeight, (float)startY), new Vector3((float)endX, lineHeight, (float)endY));
}
}
}