stlab.adobe.com Adobe Systems Incorporated

number_unit.hpp

Go to the documentation of this file.
00001 /*
00002     Copyright 2005-2007 Adobe Systems Incorporated
00003     Distributed under the MIT License (see accompanying file LICENSE_1_0_0.txt
00004     or a copy at http://stlab.adobe.com/licenses.html)
00005 */
00006 
00007 /****************************************************************************************************/
00008 
00009 #ifndef ADOBE_NUMBER_UNIT_HPP
00010 #define ADOBE_NUMBER_UNIT_HPP
00011 
00012 /****************************************************************************************************/
00013 
00014 #include <adobe/algorithm/clamp.hpp>
00015 #include <adobe/name_fwd.hpp>
00016 #include <adobe/dictionary_fwd.hpp>
00017 
00018 #include <string>
00019 
00025 /****************************************************************************************************/
00026 
00027 namespace adobe {
00028 
00029 /****************************************************************************************************/
00030 
00046 struct unit_t
00047 {
00051     unit_t() :
00052         base_unit_id_m(0),
00053         decimal_places_m(0),    
00054         trailing_zeroes_m(false),
00055         format_m("#"),
00056         increment_m(1),
00057         scale_m_m(1),
00058         scale_b_m(0),
00059         min_value_m((std::numeric_limits<double>::min)()),
00060         max_value_m((std::numeric_limits<double>::max)())
00061     { }
00062 
00064     std::string name_m;
00066     std::string short_name_m;
00068     adobe::name_t base_unit_filter_m;
00070     adobe::name_t base_unit_m;
00071     // Unique id for base unit
00072     unsigned int base_unit_id_m;    
00073 
00075     unsigned int decimal_places_m;
00076     bool trailing_zeroes_m;
00077 
00079     std::string format_m;   
00080 
00082     double increment_m;
00083 
00085     double scale_m_m;
00086 
00088     double scale_b_m; 
00089 
00091     double min_value_m;
00092 
00094     double max_value_m;
00095 };
00096 
00160 unit_t to_unit(const dictionary_t& dict,  const unit_t& default_unit = unit_t());
00161 
00172 inline double to_scaled_value(double base_value, const unit_t& unit)
00173 { return (unit.scale_m_m * base_value) + unit.scale_b_m; }
00174 
00185 inline double to_base_value(double scaled_value, const unit_t& unit)
00186 { return (scaled_value - unit.scale_b_m) / unit.scale_m_m; }
00187 
00204 inline double to_pinned_base_value(double               scaled_value,
00205                                    const unit_t& unit,
00206                                    double               min,
00207                                    double               max)
00208 {
00209     double base(to_base_value(scaled_value, unit));
00210 
00211     if (min == (std::numeric_limits<double>::min)())
00212         min = base;
00213 
00214     if (max == (std::numeric_limits<double>::max)())
00215         max = base;
00216 
00217     return adobe::clamp(base, min, max);
00218 }
00219 
00220 /****************************************************************************************************/
00221 
00222 } //namespace adobe
00223 
00224 /****************************************************************************************************/
00225 
00226 #endif
00227 
00228 /****************************************************************************************************/

Copyright © 2006-2007 Adobe Systems Incorporated.

Use of this website signifies your agreement to the Terms of Use and Online Privacy Policy.

Search powered by Google