25#include "AstUtil/Object.hpp"
26#include "AstUtil/SharedPtr.hpp"
27#include "AstUtil/StringView.hpp"
28#include "AstUtil/Constants.h"
51 extern AST_UTIL_API Unit
none;
53 extern AST_UTIL_API Unit
mm;
54 extern AST_UTIL_API Unit
cm;
55 extern AST_UTIL_API Unit
dm;
56 extern AST_UTIL_API Unit
m;
57 extern AST_UTIL_API Unit
km;
59 extern AST_UTIL_API Unit
in;
60 extern AST_UTIL_API Unit
ft;
61 extern AST_UTIL_API Unit
yd;
62 extern AST_UTIL_API Unit
mi;
66 extern AST_UTIL_API Unit
sec;
67 extern AST_UTIL_API Unit
s;
68 extern AST_UTIL_API Unit
ms;
69 extern AST_UTIL_API Unit min;
70 extern AST_UTIL_API Unit
hour;
71 extern AST_UTIL_API Unit
h;
72 extern AST_UTIL_API Unit
day;
74 extern AST_UTIL_API Unit
kg;
75 extern AST_UTIL_API Unit
g;
76 extern AST_UTIL_API Unit
mg;
77 extern AST_UTIL_API Unit
lb;
79 extern AST_UTIL_API Unit
N;
81 extern AST_UTIL_API Unit
deg;
82 extern AST_UTIL_API Unit
rad;
83 extern AST_UTIL_API Unit
arcsec;
85 extern AST_UTIL_API Unit
A;
87 extern AST_UTIL_API Unit
m2;
89 extern AST_UTIL_API Unit
m3;
90 extern AST_UTIL_API Unit
L;
97AST_UTIL_API Unit
aUnitMultiply(
const Unit& unit1,
const Unit& unit2);
100AST_UTIL_API Unit
aUnitMultiply(
const Unit& unit1,
const Unit& unit2, StringView newname);
103AST_UTIL_API Unit
aUnitDivide(
const Unit& unit1,
const Unit& unit2);
106AST_UTIL_API Unit
aUnitDivide(
const Unit& unit1,
const Unit& unit2, StringView newname);
109AST_UTIL_API Unit
aUnitPower(
const Unit& unit,
int exponent);
112AST_UTIL_API Unit
aUnitPower(
const Unit& unit,
int exponent, StringView newname);
118AST_UTIL_API Unit
aUnitInvert(
const Unit& unit, StringView newname);
124AST_UTIL_API
void aUnitFactorize(
const Unit& unit, Unit& newUnit,
double& scale);
157 : name_{std::string(name)}
159 , dimension_{dimension}
160 , subUnits_{subunits}
171 return Unit(
"", 0.0, EDimension::eUnit);
177 return Unit(
"", 1.0, EDimension::eUnit);
184 return Unit(aText(
"\u00D71"), 1.0, EDimension::eUnit);
191 static Unit Scale(
double scale);
196 return Unit(
"%", 0.01, EDimension::eUnit);
203 return Unit(
"s", 1.0, EDimension::eTime);
208 return Unit(
"min", 60.0, EDimension::eTime);
213 return Unit(
"h", 3600.0, EDimension::eTime);
218 return Unit(
"day", 86400.0, EDimension::eTime);
223 return Unit(
"ms", 0.001, EDimension::eTime);
231 return Unit(
"m", 1.0, EDimension::eLength);
236 return Unit(
"km", 1000.0, EDimension::eLength);
241 return Unit(
"cm", 0.01, EDimension::eLength);
246 return Unit(
"dm", 0.1, EDimension::eLength);
252 return Unit(
"mm", 0.001, EDimension::eLength);
259 return Unit(
"in", 0.0254, EDimension::eLength);
265 return Unit(
"ft", 0.3048, EDimension::eLength);
271 return Unit(
"yd", 0.9144, EDimension::eLength);
277 return Unit(
"mi", 1609.344, EDimension::eLength);
283 return Unit(
"kg", 1.0, EDimension::eMass);
288 return Unit(
"g", 0.001, EDimension::eMass);
294 return Unit(
"mg", 0.000001, EDimension::eMass);
300 return Unit(
"lb", 0.45359237, EDimension::eMass);
306 return Unit(
"rad", 1.0, EDimension::eAngle);
325 return Unit(
"N", 1.0, EDimension::eForce);
331 return Unit(
"A", 1.0, EDimension::eCurrent);
336 return Unit(
"K", 1.0, EDimension::eTemperature);
341 return Unit(
"mol", 1.0, EDimension::eAmount);
348 return Centimeter() / Second();
353 return Kilometer() / Hour();
358 return Meter() / Minute();
363 return Meter() * Meter();
368 return Kilometer() * Kilometer();
373 return Foot() * Foot();
379 return Yard() * Yard();
385 return Meter() * Meter() * Meter();
390 return Unit(
"L", 0.001, EDimension::eVolume);
403 Unit(
double scale,
Dimension dimension,
const SubUnitListConst& subunits)
404 : rep_{std::make_shared<UnitRep>(
"", scale, dimension, (subunits))}
414 double fromSI(
double value)
const {
return value / getScale(); }
419 double toSI(
double value)
const {
return value * getScale(); }
441 const std::string&
name()
const {
return rep_->name_; }
445 bool isValid()
const {
return rep_->scale_ != 0.0; }
480 return Unit(newname, factor * rep_->scale_, rep_->dimension_);
505 if(rep_ == other.rep_)
508 return rep_->scale_ == other.rep_->scale_ && rep_->dimension_ == other.rep_->dimension_;
516 return !(*
this == other);
539 *
this = *
this * other;
547 *
this = *
this / other;
Unit m3
立方米
定义 Unit.cpp:447
Unit arcsec
弧秒
定义 Unit.cpp:441
Unit hour
小时
定义 Unit.cpp:428
Unit none
无单位
定义 Unit.cpp:411
Unit rad
弧度
定义 Unit.cpp:440
Unit m2
平方米
定义 Unit.cpp:445
SubUnitListConst subUnits_
子单位列表
定义 Unit.hpp:165
Dimension dimension_
量纲
定义 Unit.hpp:164
std::string name_
名称
定义 Unit.hpp:162
static Unit Newton()
牛顿单位
定义 Unit.hpp:323
std::vector< UnitRepPair > SubUnitList
单位表示子项列表
定义 Unit.hpp:146
Unit(StringView name, double scale, Dimension dimension)
新建单位
定义 Unit.hpp:398
static Unit Day()
天单位
定义 Unit.hpp:216
Unit multiply(StringView newname, const Unit &other) const
单位乘法
定义 Unit.hpp:460
std::vector< UnitRepPairConst > SubUnitListConst
单位表示子项列表(常量)
定义 Unit.hpp:150
static Unit Mole()
mole单位
定义 Unit.hpp:339
static Unit Meter()
米单位
定义 Unit.hpp:229
std::shared_ptr< UnitRep > UnitRepHandle
单位表示
定义 Unit.hpp:144
Unit scale(StringView newname, double factor) const
单位缩放
定义 Unit.hpp:478
double getScale() const
获取单位缩放因子
定义 Unit.hpp:433
static Unit Percent()
百分比单位
定义 Unit.hpp:194
static Unit Minute()
分钟单位
定义 Unit.hpp:206
bool operator!=(const Unit &other) const
单位不相等运算符
定义 Unit.hpp:514
Unit pow(StringView newname, int exponent) const
单位幂运算
定义 Unit.hpp:487
Unit divide(StringView newname, const Unit &other) const
单位除法
定义 Unit.hpp:469
Unit pow(int exponent) const
单位幂运算
定义 Unit.hpp:495
double toSI(double value) const
从该单位对应的值转换为国际单位制下的值
定义 Unit.hpp:419
Unit operator*(const Unit &other) const
单位乘法运算符
定义 Unit.hpp:522
static Unit Milligram()
毫克单位
定义 Unit.hpp:292
bool operator==(const Unit &other) const
单位相等运算符
定义 Unit.hpp:503
static Unit Second()
秒单位
定义 Unit.hpp:201
static Unit None()
无单位
定义 Unit.hpp:175
static Unit CubicMeter()
立方米单位
定义 Unit.hpp:383
static Unit NaN()
无效单位
定义 Unit.hpp:169
static Unit SquareMeter()
平方米单位
定义 Unit.hpp:361
static Unit Yard()
码单位
定义 Unit.hpp:269
Dimension dimension() const
获取单位量纲
定义 Unit.hpp:437
static Unit Gram()
克单位
定义 Unit.hpp:286
Unit & operator*=(const Unit &other)
单位乘法赋值运算符
定义 Unit.hpp:537
static Unit Kilometer()
米单位
定义 Unit.hpp:234
Unit invert() const
单位倒数
定义 Unit.hpp:454
static Unit SquareYard()
平方码单位
定义 Unit.hpp:377
std::shared_ptr< const UnitRep > UnitRepHandleConst
单位表示句柄(常量)
定义 Unit.hpp:148
static Unit Centimeter()
厘米单位
定义 Unit.hpp:239
static Unit Liter()
升单位
定义 Unit.hpp:388
const std::string & name() const
获取单位名称
定义 Unit.hpp:441
double convertFrom(double value, const Unit &unit) const
转换为指定单位下的值
定义 Unit.hpp:429
static Unit Ampere()
安培单位
定义 Unit.hpp:329
Unit clone() const
单位克隆
定义 Unit.hpp:451
static Unit Kelvin()
开尔文单位
定义 Unit.hpp:334
static Unit Foot()
英尺单位
定义 Unit.hpp:263
static Unit Hour()
小时单位
定义 Unit.hpp:211
static Unit SquareFoot()
平方英尺单位
定义 Unit.hpp:371
Unit & operator/=(const Unit &other)
单位除法赋值运算符
定义 Unit.hpp:545
bool isValid() const
是否有效单位
定义 Unit.hpp:445
static Unit CentimeterPerSecond()
厘米每秒单位
定义 Unit.hpp:347
static Unit Millimeter()
毫米单位
定义 Unit.hpp:250
double fromSI(double value) const
从国际单位制转换为该单位对应的值
定义 Unit.hpp:414
static Unit Decimeter()
分米单位
定义 Unit.hpp:244
std::pair< UnitRepHandleConst, int > UnitRepPairConst
单位表示子项(常量)
定义 Unit.hpp:149
double convertTo(double value, const Unit &unit) const
转换为指定单位下的值
定义 Unit.hpp:424
static Unit Radian()
弧度单位
定义 Unit.hpp:304
static Unit ArcSecond()
弧秒单位
定义 Unit.hpp:317
static Unit Mile()
英里单位
定义 Unit.hpp:275
Unit(UnitRepHandle rep)
定义 Unit.hpp:408
Unit()
默认无单位
定义 Unit.hpp:395
static Unit Inch()
英寸单位
定义 Unit.hpp:257
static Unit Degree()
度单位
定义 Unit.hpp:310
Unit operator/(const Unit &other) const
单位除法运算符
定义 Unit.hpp:530
static Unit One()
无量纲单位
定义 Unit.hpp:181
static Unit Pound()
磅单位
定义 Unit.hpp:298
static Unit MeterPerMinute()
米每分钟单位
定义 Unit.hpp:356
static Unit Kilogram()
千克单位
定义 Unit.hpp:281
static Unit MilliSecond()
毫秒单位
定义 Unit.hpp:221
static Unit KilometerPerHour()
千米每秒单位
定义 Unit.hpp:351
static Unit SquareKilometer()
平方公里单位
定义 Unit.hpp:366
std::pair< UnitRepHandle, int > UnitRepPair
单位表示子项
定义 Unit.hpp:145
Unit aUnitMultiply(const Unit &unit1, const Unit &unit2)
单位乘法
定义 Unit.cpp:329
Unit aUnitPower(const Unit &unit, int exponent)
单位幂
定义 Unit.cpp:357
Unit aUnitInvert(const Unit &unit)
单位倒数
定义 Unit.cpp:372
void aUnitFactorize(const Unit &unit, Unit &newUnit, double &scale)
单位分解
定义 Unit.cpp:386
Unit aUnitDivide(const Unit &unit1, const Unit &unit2)
单位除法
定义 Unit.cpp:343
constexpr double kArcSecToRad
弧秒到弧度 kDegToRad/3600.0 度分秒的秒
定义 Constants.h:213
constexpr double kDegToRad
角度到弧度 kPI/180.0
定义 Constants.h:212
Unit unit_divide(const Unit &unit1, const Unit &unit2)
单位除法
定义 Unit.cpp:263
Unit unit_power(const Unit &unit, int exponent)
单位幂
定义 Unit.cpp:296
void unit_setname(Unit &unit, StringView name)
设置单位名称
定义 Unit.cpp:323
Unit unit_multiply(const Unit &unit1, const Unit &unit2)
单位乘法
定义 Unit.cpp:232