Skip to content

Instantly share code, notes, and snippets.

@LoicGoyet
Created March 10, 2016 13:56
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LoicGoyet/1fbe5b3e31704473e257 to your computer and use it in GitHub Desktop.
Save LoicGoyet/1fbe5b3e31704473e257 to your computer and use it in GitHub Desktop.
The get-hypotenuse() is a sass function to calc the hypotenuse width on a triangle rectangle
// http://www.antimath.info/css/sass-sqrt-function/
@function sqrt($r) {
$x0: 1;
$x1: $x0;
@for $i from 1 through 10 {
$x1: $x0 - ($x0 * $x0 - abs($r)) / (2 * $x0);
$x0: $x1;
}
@return $x1;
}
@function strip-units($number) {
@return $number / ($number * 0 + 1);
}
@function square($number) {
$unitless: strip-units($number);
@return ($unitless * $unitless);
}
@function get-unit($number) {
@return unit($number);
}
@function get-hypotenuse($ab, $ac) {
@if get-unit($ab) == get-unit($ac) {
@return sqrt(square($ab) + square($ac)) + unquote(get-unit($ab));
} @else {
@error 'The two value into the get-hypotenuse() function must share the same unit type';
}
}
@staghouse
Copy link

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment