text: /*
   * Copyright (c) 2014, Julien Bernard
   *
   * Permission to use, copy, modify, and/or distribute this software for any
   * purpose with or without fee is hereby granted, provided that the above
   * copyright notice and this permission notice appear in all copies.
   *
   * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
   * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
   * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
   * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
   * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
   * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
   * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
   */
  #ifndef MM_UTILS_H
  #define MM_UTILS_H
  
  namespace mm {
  
    inline
    double value_with_sea_level(double value, double sea_level) {
      if (value < sea_level) {
        return value / sea_level * 0.5;
      }
  
      return (value - sea_level) / (1.0 - sea_level) * 0.5 + 0.5;
    }
  
    inline
    double clamp(double value, double min, double max) {
      if (value < min) {
        return min;
      }
  
      if (value > max) {
        return max;
      }
  
      return value;
    }
  
  }
  
  #endif // MM_UTILS_H
  
  
  