DarianFlorianVoda / BioShapes

Bachelor Thesis R Package
0 stars 0 forks source link

[Arrows.R] Arrows that do NOT contain join parameter #66

Closed DarianFlorianVoda closed 2 years ago

DarianFlorianVoda commented 2 years ago
discoleo commented 2 years ago

arrowDoubleInverted

I will send you an improved version of the code.

Arrows.R: Code for arrowDoubleInverted

### Double Lined Inverted Head
# dH = abs(d) ensures always inverted!
#' @export
arrowDoubleInverted = function(x, y, d=-0.25, lwd=1, dH=abs(d), d.head=c(-d, d), d.lines=0,
        h.lwd=lwd, col="red", scale=1, join=0) {
  if(join > 2) stop("Unsupported value for join!");
  slope = compute_slope(x, y);
  ### Head
  arrHead = arrowHeadDoubleInverted(x[2], y[2], slope=slope, d=d, dH=dH, dV=d.head, scale=scale);
  midpoint = attr(arrHead, "Mid")
  arrHead$lwd = h.lwd;
  ### ArrowTail
  if(join <= 1) {
    midpoint = midpoint[[2]];
  } else {
    midpoint = midpoint[[1]];
  }
  x[2] = midpoint[1]
  y[2] = midpoint[2]
  arrow = arrowTail(x, y, d.lines=d.lines, lwd=lwd, slope=slope);
  ### Full Arrow
  lst = list(Arrow=arrow, Head=arrHead);
  class(lst) = c("arrow", "list");
  # Plot lines:
  lines(lst, col=col);
  invisible(lst);
}

Arrows.Heads.R: Code for arrowHeadDoubleInverted

### Double Lined Inverted ArrowHead: ---<<
# dH = abs(d) ensures always inverted!
#' @export
arrowHeadDoubleInverted = function(x, y, slope, d=-1, dH=abs(d), dV=c(d, -d), scale=1) {
  # Shift point along line:
  # dH = abs(dV[1]);
  # Head: 2nd "<" of "<<"
  dHneg = - dH;
  pV = shiftPoint(c(x, y), slope=slope, d = dHneg, scale=scale);
  arrHead  = list(arrowHeadSimple(pV[1], pV[2], slope=slope, d = dH, scale=scale));
  midpoint = list(pV);
  # Head: 1st "<" of "<<"
  pV = shiftPoint(c(x, y), slope=slope, d = d + dHneg);
  arrHead2 = list(arrowHeadSimple(pV[1], pV[2], slope=slope, d = dH, scale=scale));
  arrHead  = c(arrHead, arrHead2);
  midpoint = c(list(pV), midpoint);
  attr(arrHead, "Mid") = midpoint;
  return(arrHead);
}
discoleo commented 2 years ago
DarianFlorianVoda commented 2 years ago

All have now join parameter.