DarianFlorianVoda / BioShapes

Bachelor Thesis R Package
0 stars 0 forks source link

[Arrows.R] arrowT: improvement + join #68

Closed discoleo closed 2 years ago

discoleo commented 2 years ago

arrowT: Improved functionality + Join

arrowT

#### Arrow T ####
#' @export
arrowT = function(x, y, d=0.2, lwd=1, d.head=c(d, -d), d.lines=0, h.lwd=lwd,
    col="red", scale=1, join=0) {
  slope = compute_slope(x, y);
  ### Head
  if(is.list(d.head)) {
    ahead = lapply(seq(length(d.head)), function(id) {
          arrowHeadT(x[2], y[2], slope=slope, dV=d.head[[id]], scale=scale)
        });
    ahead$lwd = h.lwd;
  } else {
    ahead = list(arrowHeadT(x[2], y[2], slope=slope, dV=d.head, scale=scale),
      lwd = h.lwd);
  }
  ### ArrowTail
  arrow = arrowTail(x, y, d.lines=d.lines, lwd=lwd, slope=slope);
  ### Full Arrow
  lst = list(Arrow=arrow, Head=ahead);
  class(lst) = c("arrow", "list");
  # Plot lines:
  lines(lst, col=col);
  invisible(lst);
}

Tests

##### T Shape ArrowHead #####
x = c(0, 6); y = c(1, 6);
plot.base()
arrowT(x, y, d=-1, lwd=2);
arrowT(c(x[1], 5), c(y[1], y[1]), d=-1, lwd=2);
arrowT(c(x[1], x[1]), c(y[1], 5), d=-1, lwd=2);

### Discontinuous T
x = c(0, 6); y = c(1, 6);
d.head = list(c(0.2, 0.7), c(-0.2, -0.7))
plot.base()
arrowT(x, y, d.head=d.head, lwd=2);
arrowT(c(x[1], 5), c(y[1], y[1]), d.head=d.head, lwd=2);
arrowT(c(x[1], x[1]), c(y[1], 5), d.head=d.head, lwd=2);
DarianFlorianVoda commented 2 years ago

Implemented