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         unit_name_m(0),
00053         base_unit_id_m(0),
00054         decimal_places_m(0),    
00055         trailing_zeroes_m(false),
00056         format_m("#"),
00057         increment_m(1),
00058         scale_m_m(1),
00059         scale_b_m(0),
00060         min_value_m((std::numeric_limits<double>::min)()),
00061         max_value_m((std::numeric_limits<double>::max)())
00062     { }
00063     
00064     // this is a name_t indentifier for identifying which unit is selected
00065     unsigned long unit_name_m;
00066 
00068     std::string name_m;
00070     std::string short_name_m;
00072     adobe::name_t base_unit_filter_m;
00074     adobe::name_t base_unit_m;
00075     // Unique id for base unit
00076     unsigned int base_unit_id_m;    
00077 
00079     unsigned int decimal_places_m;
00080     bool trailing_zeroes_m;
00081 
00083     std::string format_m;   
00084 
00086     double increment_m;
00087 
00089     double scale_m_m;
00090 
00092     double scale_b_m; 
00093 
00095     double min_value_m;
00096 
00098     double max_value_m;
00099 };
00100 
00164 unit_t to_unit(const dictionary_t& dict,  const unit_t& default_unit = unit_t());
00165 
00176 inline double to_scaled_value(double base_value, const unit_t& unit)
00177 { return (unit.scale_m_m * base_value) + unit.scale_b_m; }
00178 
00189 inline double to_base_value(double scaled_value, const unit_t& unit)
00190 { return (scaled_value - unit.scale_b_m) / unit.scale_m_m; }
00191 
00208 inline double to_pinned_base_value(double               scaled_value,
00209                                    const unit_t& unit,
00210                                    double               min,
00211                                    double               max)
00212 {
00213     double base(to_base_value(scaled_value, unit));
00214 
00215     if (min == (std::numeric_limits<double>::min)())
00216         min = base;
00217 
00218     if (max == (std::numeric_limits<double>::max)())
00219         max = base;
00220 
00221     return adobe::clamp(base, min, max);
00222 }
00223 
00224 /****************************************************************************************************/
00225 
00226 } //namespace adobe
00227 
00228 /****************************************************************************************************/
00229 
00230 #endif
00231 
00232 /****************************************************************************************************/

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