Created
March 10, 2016 13:56
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you!