Repository navigation
Expand file tree
/
Copy pathTestDrawing.java
More file actions
90 lines (73 loc) · 2.64 KB
/
Copy pathTestDrawing.java
File metadata and controls
90 lines (73 loc) · 2.64 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import org.junit.*;
import static org.junit.Assert.*;
public class TestDrawing {
private Drawing draw;
@Before
public void setUp() {
}
@After
public void tearDown() {
}
@Test
// tests to see if barycentric coordinates work
public void testBarycentricCoordinates() {
this.draw = new Drawing();
int x = 5;
int y = 5;
// creates a triangle out of points
int[] xPoints = {0, 10, 0};
int[] yPoints = {0, 0, 10};
// checks and stores the weights of each coordinate
double[] bary = this.draw.getBarycentricCoordinates(x, y, xPoints, yPoints);
assertEquals(0, bary[0], 0.000001);
assertEquals(0.5, bary[1], 0.000001);
assertEquals(0.5, bary[2], 0.000001);
}
@Test
// tests to see if barycentric coordinates work
public void testBarycentricCoordinatesOutsideTriangle() {
this.draw = new Drawing();
int x = 10;
int y = 10;
// creates a triangle out of points
int[] xPoints = {0, 10, 0};
int[] yPoints = {0, 0, 10};
// checks and stores the weights of each coordinate
double[] bary = this.draw.getBarycentricCoordinates(x, y, xPoints, yPoints);
assertEquals(-1, bary[0], 0.000001);
assertEquals(1, bary[1], 0.000001);
assertEquals(1, bary[2], 0.000001);
}
@Test
// tests to see if 4 barycentric coordinates work
public void testBarycentric4Coordinates() {
this.draw = new Drawing();
int x = 5;
int y = 5;
// creates a triangle out of points
int[] xPoints = {0, 10, 10, 0};
int[] yPoints = {0, 0, 10, 10};
// checks and stores the weights of each coordinate
double[] bary = this.draw.getBarycentricCoordinates4Vertices(x, y, xPoints, yPoints);
assertEquals(0.5, bary[0], 0.000001);
assertEquals(0, bary[1], 0.000001);
assertEquals(0.5, bary[2], 0.000001);
assertEquals(0, bary[3], 0.000001);
}
@Test
// tests to see if 4 barycentric coordinates work
public void testBarycentric4CoordinatesOutsideQuad() {
this.draw = new Drawing();
int x = 20;
int y = 20;
// creates a triangle out of points
int[] xPoints = {0, 10, 10, 0};
int[] yPoints = {0, 0, 10, 10};
// checks and stores the weights of each coordinate
double[] bary = this.draw.getBarycentricCoordinates4Vertices(x, y, xPoints, yPoints);
assertEquals(-1, bary[0], 0.000001);
assertEquals(0, bary[1], 0.000001);
assertEquals(2, bary[2], 0.000001);
assertEquals(0, bary[3], 0.000001);
}
}