// ==========================================================================
// Functions
// ==========================================================================

/**
 * px to em conversion
 * @link http://www.pjmccormick.com/sweet-sass-function-convert-px-em
 * @requires {variable} $base-font-size
 * @param {number} $target - size to convert
 * @param {number} $context ($base-font-size) - context conversion is based on
 * @example scss
 * .foobar { padding-bottom: em(30); }
 * @returns {number}
 */

@function em($target, $context: $base-font-size) {
   @if $target == 0 { @return 0 }
   @return $target / $context + 0em;
}

/**
 * px to rem
 * @link http://www.pjmccormick.com/sweet-sass-function-convert-px-em
 * @requires {variable} $base-font-size
 * @param {number} $target - size to convert
 * @param {number} $context ($base-font-size) - context conversion is based on
 * @example scss
 * .foobar { padding-bottom: rem(30); }
 * @returns {number}
 */

@function rem($target, $context: $base-font-size) {
  @if $target == 0 { @return 0 }
  @return $target / $context + 0rem;
}

/**
 * em to px conversion
 * @link http://www.pjmccormick.com/sweet-sass-function-convert-px-em
 * @requires {variable} $base-font-size
 * @param {number} $target - size to convert
 * @param {number} $context ($base-font-size) - context conversion is based on
 * @example scss
 * .foobar { padding-bottom: px(30); }
 * @returns {number}
 */

@function px($target, $context: $base-font-size) {
  @if $target == 0 { @return 0 }
  @return $target * $context + 0px;
}

/**
 * Aspect Ratio
 * @param {number} $ratio-numerator - ratio numerator
 * @param {number} $ratio-denominator - ratio denominator
 * @example scss
 * .foobar { padding-bottom: aspect-ratio(16,9); } // @returns 56.25%
 * @returns {number}
 */

@function aspect-ratio($ratio-numerator, $ratio-denominator) {
  @return (($ratio-denominator / $ratio-numerator) * 100%);
}

/**
 * Aspect Ratio
 * Based on Fixed Image Dimensions
 * @param {number} $w - image width
 * @param {number} $h - image height
 * @example scss
 * .foobar { padding: 0 0 aspect-ratio-fixed(1080, 720); } // @returns 66.666666666667%
 * @returns {number}
 */

@function aspect-ratio-fixed($w, $h) {
  @return ($h / $w) * 100%;
}

/**
 * Context Calculator
 * @param {number} $target
 * @param {number} $context
 * @example scss
 * .foobar { padding-bottom: context-calc(30,15); }
 * @returns {number}
 */

@function context-calc($target, $context) {
  @return ($target / $context) * 100%;
}


/**
 * Strip Unit Values
 * @link http://hugogiraudel.com/2013/08/12/sass-functions
 * @param {string} $num
 * @example scss
 * .foobar { padding-bottom: strip-unit(30px); }
 * @returns {number}
 */

@function strip-unit($num) {
    @return $num / ($num * 0 + 1);
}
