/**
 * Create an expression from points (and CSS unit)
 * to use with a CSS calc() function.
 */
@function linear-expression( $p1, $p2, $parentheses: true ) {

  // Convert absolute units to pixel
  // https://sass-lang.com/documentation/operators/numeric#units

  $p1x:         0px + nth($p1, 1);
  $p1y:         0px + nth($p1, 2);

  $p2x:         0px + nth($p2, 1);
  $p2y:         0px + nth($p2, 2);

  @if ($p1x == $p2x or $p1y == $p2y) {
    @error "SASS Linear Expression doesn't accept identical X or Y values.";
  }

  $rise:        $p2y - $p1y;
  $run:         $p2x - $p1x;
  $slope:       $rise / $run;
  $intercept:   $p1y - $slope * $p1x;

  $expression:  "#{$intercept} + #{$slope * 100vw}";

  @if ($parentheses) {
    $expression: "(#{$expression})";
  }

  @return $expression;

}
