🛰️航天仿真算法库 SpaceAST
0.0.1
载入中...
搜索中...
未找到
UnitConverter.hpp
浏览该文件的文档.
1
20
21
#pragma once
22
23
#include "AstGlobal.h"
24
#include "AstUtil/Unit.hpp"
25
26
AST_NAMESPACE_BEGIN
27
28
31
class
UnitConverter
32
{
33
public
:
34
UnitConverter
():fromUnit_(
Unit
()), toUnit_(
Unit
()), conversionFactor_(1.0){}
35
36
UnitConverter
(
Unit
fromUnit,
Unit
toUnit)
37
: fromUnit_(fromUnit), toUnit_(toUnit), conversionFactor_(fromUnit.
getScale
() / toUnit.
getScale
()){}
38
42
double
convert
(
double
value)
const
{
return
value * conversionFactor_;}
43
46
Unit
getFromUnit
()
const
{
return
fromUnit_;}
47
50
Unit
getToUnit
()
const
{
return
toUnit_;}
51
53
void
setFromUnit
(
Unit
fromUnit){fromUnit_ = fromUnit; syncConversionFactor();}
54
56
void
setToUnit
(
Unit
toUnit){toUnit_ = toUnit; syncConversionFactor();}
57
60
double
getConversionFactor
()
const
{
return
conversionFactor_;}
61
62
protected
:
64
void
syncConversionFactor
(){conversionFactor_ = fromUnit_.getScale() / toUnit_.getScale();}
65
66
protected
:
67
Unit
fromUnit_
;
68
Unit
toUnit_
;
69
double
conversionFactor_
;
70
};
71
72
AST_NAMESPACE_END
ast::UnitConverter
单位转换器
定义
UnitConverter.hpp:32
ast::UnitConverter::getToUnit
Unit getToUnit() const
获取转换后的单位
定义
UnitConverter.hpp:50
ast::UnitConverter::conversionFactor_
double conversionFactor_
转换因子
定义
UnitConverter.hpp:69
ast::UnitConverter::convert
double convert(double value) const
转换单位
定义
UnitConverter.hpp:42
ast::UnitConverter::setToUnit
void setToUnit(Unit toUnit)
设置转换后的单位
定义
UnitConverter.hpp:56
ast::UnitConverter::fromUnit_
Unit fromUnit_
转换前的单位
定义
UnitConverter.hpp:67
ast::UnitConverter::getConversionFactor
double getConversionFactor() const
获取转换因子
定义
UnitConverter.hpp:60
ast::UnitConverter::setFromUnit
void setFromUnit(Unit fromUnit)
设置转换前的单位
定义
UnitConverter.hpp:53
ast::UnitConverter::getFromUnit
Unit getFromUnit() const
获取转换前的单位
定义
UnitConverter.hpp:46
ast::UnitConverter::toUnit_
Unit toUnit_
转换后的单位
定义
UnitConverter.hpp:68
ast::UnitConverter::syncConversionFactor
void syncConversionFactor()
同步转换因子
定义
UnitConverter.hpp:64
ast::Unit
单位
定义
Unit.hpp:136
ast::Unit::getScale
double getScale() const
获取单位缩放因子
定义
Unit.hpp:433
src
AstUtil
Quantity
UnitConverter.hpp
制作者
1.12.0