DarianFlorianVoda / BioShapes

Bachelor Thesis R Package
0 stars 0 forks source link

Arrows.Tests: Add the actual Test #40

Closed discoleo closed 2 years ago

discoleo commented 2 years ago

Arrow.Tests

Add the actual test:

Helper Test Function

#### Tests ####

Dsquare = function(xy, x0, y0) {
    sum((xy$x - x0)^2, (xy$y - y0)^2)
}

The Visual & Actual Tests:

#### Diagonal, H & V Tests ####

##### Simple  ArrowHead ####

### Test 1
x = c(0, 6); y = c(1, 6);
d = -1;
plot.base()
a1 = arrowSimpleH(x, y, d=d, lwd=2);
a2 = arrowSimpleH(c(x[1], 5), c(y[1], y[1]), d=d, lwd=2);
a3 = arrowSimpleH(c(x[1], x[1]), c(y[1], 5), d=d, lwd=2);
# Head
h1 = a1$Head[[1]]
# - visual aids:
lines(h1$x[c(1,3)], h1$y[c(1,3)], col="green")
stopifnot(round(Dsquare(h1, h1$x[2], h1$y[2]) - 2*d^2 - 2*d^2, 8) == 0)
# TODO: a2, a3;

### Test 2
plot.base()
x = c(0, 6); y = c(1, 6) + 1;
d=-1.5; d.head = c(-0.5, 0.5);
a1 = arrowSimpleH(x, y, d=d, d.head=d.head, lwd=2);
a2 = arrowSimpleH(c(x[1], 5), c(y[1], y[1]), d=d, d.head=d.head, lwd=2);
a3 = arrowSimpleH(c(x[1], x[1]), c(y[1], 5), d=d, d.head=d.head, lwd=2);
# Head
h1 = a1$Head[[1]]
# - visual aids:
lines(h1$x[c(1,3)], h1$y[c(1,3)], col="green")
stopifnot(round(Dsquare(h1, h1$x[2], h1$y[2]) - 2*d^2 - sum(d.head^2), 8) == 0)
# TODO: a2, a3;
DarianFlorianVoda commented 2 years ago

Added.