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
minute;
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;
92 extern AST_UTIL_API Unit
Pa;
94 extern AST_UTIL_API Unit
K;
100AST_UTIL_API Unit
aUnitMultiply(
const Unit& unit1,
const Unit& unit2);
103AST_UTIL_API Unit
aUnitMultiply(
const Unit& unit1,
const Unit& unit2, StringView newname);
106AST_UTIL_API Unit
aUnitDivide(
const Unit& unit1,
const Unit& unit2);
109AST_UTIL_API Unit
aUnitDivide(
const Unit& unit1,
const Unit& unit2, StringView newname);
112AST_UTIL_API Unit
aUnitPower(
const Unit& unit,
int exponent);
115AST_UTIL_API Unit
aUnitPower(
const Unit& unit,
int exponent, StringView newname);
121AST_UTIL_API Unit
aUnitInvert(
const Unit& unit, StringView newname);
127AST_UTIL_API
void aUnitFactorize(
const Unit& unit, Unit& newUnit,
double& scale);
141 #ifdef AST_BUILD_LIB_UTIL
162 : name_{std::string(name)}
164 , dimension_{dimension}
165 , subUnits_{subunits}
176 return Unit(
"", 0.0, EDimension::eUnit);
182 return Unit(
"", 1.0, EDimension::eUnit);
189 return Unit(aText(
"\u00D71"), 1.0, EDimension::eUnit);
196 static Unit Scale(
double scale);
201 return Unit(
"%", 0.01, EDimension::eUnit);
208 return Unit(
"s", 1.0, EDimension::eTime);
213 return Unit(
"min", 60.0, EDimension::eTime);
218 return Unit(
"h", 3600.0, EDimension::eTime);
223 return Unit(
"day", 86400.0, EDimension::eTime);
228 return Unit(
"ms", 0.001, EDimension::eTime);
236 return Unit(
"m", 1.0, EDimension::eLength);
241 return Unit(
"km", 1000.0, EDimension::eLength);
246 return Unit(
"cm", 0.01, EDimension::eLength);
251 return Unit(
"dm", 0.1, EDimension::eLength);
257 return Unit(
"mm", 0.001, EDimension::eLength);
264 return Unit(
"in", 0.0254, EDimension::eLength);
270 return Unit(
"ft", 0.3048, EDimension::eLength);
276 return Unit(
"yd", 0.9144, EDimension::eLength);
282 return Unit(
"mi", 1609.344, EDimension::eLength);
288 return Unit(
"kg", 1.0, EDimension::eMass);
293 return Unit(
"g", 0.001, EDimension::eMass);
299 return Unit(
"mg", 0.000001, EDimension::eMass);
305 return Unit(
"lb", 0.45359237, EDimension::eMass);
311 return Unit(
"rad", 1.0, EDimension::eAngle);
330 return Unit(
"N", 1.0, EDimension::eForce);
336 return Unit(
"A", 1.0, EDimension::eCurrent);
341 return Unit(
"K", 1.0, EDimension::eTemperature);
354 return Centimeter() / Second();
359 return Kilometer() / Hour();
364 return Meter() / Minute();
369 return Meter() * Meter();
374 return Kilometer() * Kilometer();
379 return Foot() * Foot();
385 return Yard() * Yard();
391 return Meter() * Meter() * Meter();
396 return Unit(
"L", 0.001, EDimension::eVolume);
402 return Unit(
"Pa", 1.0, EDimension::ePressure);
419 Unit(
double scale,
Dimension dimension,
const SubUnitListConst& subunits)
420 : rep_{std::make_shared<UnitRep>(
"", scale, dimension, (subunits))}
430 double fromSI(
double value)
const {
return value / getScale(); }
435 double toSI(
double value)
const {
return value * getScale(); }
457 const std::string&
name()
const {
return rep_->name_; }
461 bool isValid()
const {
return rep_->scale_ != 0.0; }
496 return Unit(newname, factor * rep_->scale_, rep_->dimension_);
521 if(rep_ == other.rep_)
524 return rep_->scale_ == other.rep_->scale_ && rep_->dimension_ == other.rep_->dimension_;
532 return !(*
this == other);
555 *
this = *
this * other;
563 *
this = *
this / other;
Unit m3
立方米
定义 Unit.cpp:457
Unit minute
分钟,不要命名为min,容易与std::min冲突
定义 Unit.cpp:437
Unit arcsec
弧秒
定义 Unit.cpp:451
Unit hour
小时
定义 Unit.cpp:438
Unit none
无单位
定义 Unit.cpp:421
Unit Pa
帕斯卡
定义 Unit.cpp:460
Unit rad
弧度
定义 Unit.cpp:450
Unit m2
平方米
定义 Unit.cpp:455
Unit K
开氏温度
定义 Unit.cpp:462
SubUnitListConst subUnits_
子单位列表
定义 Unit.hpp:170
Dimension dimension_
量纲
定义 Unit.hpp:169
std::string name_
名称
定义 Unit.hpp:167
static Unit Newton()
牛顿单位
定义 Unit.hpp:328
std::vector< UnitRepPair > SubUnitList
单位表示子项列表
定义 Unit.hpp:151
Unit(StringView name, double scale, Dimension dimension)
新建单位
定义 Unit.hpp:414
static Unit Day()
天单位
定义 Unit.hpp:221
Unit multiply(StringView newname, const Unit &other) const
单位乘法
定义 Unit.hpp:476
std::vector< UnitRepPairConst > SubUnitListConst
单位表示子项列表(常量)
定义 Unit.hpp:155
static Unit Meter()
米单位
定义 Unit.hpp:234
std::shared_ptr< UnitRep > UnitRepHandle
单位表示
定义 Unit.hpp:149
Unit scale(StringView newname, double factor) const
单位缩放
定义 Unit.hpp:494
double getScale() const
获取单位缩放因子
定义 Unit.hpp:449
static Unit Percent()
百分比单位
定义 Unit.hpp:199
static Unit Minute()
分钟单位
定义 Unit.hpp:211
bool operator!=(const Unit &other) const
单位不相等运算符
定义 Unit.hpp:530
Unit pow(StringView newname, int exponent) const
单位幂运算
定义 Unit.hpp:503
Unit divide(StringView newname, const Unit &other) const
单位除法
定义 Unit.hpp:485
Unit pow(int exponent) const
单位幂运算
定义 Unit.hpp:511
double toSI(double value) const
从该单位对应的值转换为国际单位制下的值
定义 Unit.hpp:435
Unit operator*(const Unit &other) const
单位乘法运算符
定义 Unit.hpp:538
static Unit Pascal()
帕斯卡单位(压力量纲)
定义 Unit.hpp:400
static Unit Milligram()
毫克单位
定义 Unit.hpp:297
bool operator==(const Unit &other) const
单位相等运算符
定义 Unit.hpp:519
static Unit Second()
秒单位
定义 Unit.hpp:206
static Unit None()
无单位
定义 Unit.hpp:180
static Unit CubicMeter()
立方米单位
定义 Unit.hpp:389
static Unit NaN()
无效单位
定义 Unit.hpp:174
static Unit SquareMeter()
平方米单位
定义 Unit.hpp:367
static Unit Yard()
码单位
定义 Unit.hpp:274
Dimension dimension() const
获取单位量纲
定义 Unit.hpp:453
static Unit Gram()
克单位
定义 Unit.hpp:291
Unit & operator*=(const Unit &other)
单位乘法赋值运算符
定义 Unit.hpp:553
static Unit Kilometer()
米单位
定义 Unit.hpp:239
Unit invert() const
单位倒数
定义 Unit.hpp:470
static Unit SquareYard()
平方码单位
定义 Unit.hpp:383
std::shared_ptr< const UnitRep > UnitRepHandleConst
单位表示句柄(常量)
定义 Unit.hpp:153
static Unit Centimeter()
厘米单位
定义 Unit.hpp:244
static Unit Liter()
升单位
定义 Unit.hpp:394
const std::string & name() const
获取单位名称
定义 Unit.hpp:457
double convertFrom(double value, const Unit &unit) const
转换为指定单位下的值
定义 Unit.hpp:445
static Unit Ampere()
安培单位
定义 Unit.hpp:334
Unit clone() const
单位克隆
定义 Unit.hpp:467
static Unit Kelvin()
开尔文单位
定义 Unit.hpp:339
static Unit Foot()
英尺单位
定义 Unit.hpp:268
static Unit Hour()
小时单位
定义 Unit.hpp:216
static Unit SquareFoot()
平方英尺单位
定义 Unit.hpp:377
Unit & operator/=(const Unit &other)
单位除法赋值运算符
定义 Unit.hpp:561
bool isValid() const
是否有效单位
定义 Unit.hpp:461
static Unit CentimeterPerSecond()
mole单位
定义 Unit.hpp:353
static Unit Millimeter()
毫米单位
定义 Unit.hpp:255
double fromSI(double value) const
从国际单位制转换为该单位对应的值
定义 Unit.hpp:430
static Unit Decimeter()
分米单位
定义 Unit.hpp:249
std::pair< UnitRepHandleConst, int > UnitRepPairConst
单位表示子项(常量)
定义 Unit.hpp:154
double convertTo(double value, const Unit &unit) const
转换为指定单位下的值
定义 Unit.hpp:440
static Unit Radian()
弧度单位
定义 Unit.hpp:309
static Unit ArcSecond()
弧秒单位
定义 Unit.hpp:322
static Unit Mile()
英里单位
定义 Unit.hpp:280
Unit(UnitRepHandle rep)
定义 Unit.hpp:424
Unit()
默认无单位
定义 Unit.hpp:407
static Unit Inch()
英寸单位
定义 Unit.hpp:262
static Unit Degree()
度单位
定义 Unit.hpp:315
Unit operator/(const Unit &other) const
单位除法运算符
定义 Unit.hpp:546
static Unit One()
无量纲单位
定义 Unit.hpp:186
static Unit Pound()
磅单位
定义 Unit.hpp:303
static Unit MeterPerMinute()
米每分钟单位
定义 Unit.hpp:362
static Unit Kilogram()
千克单位
定义 Unit.hpp:286
static Unit MilliSecond()
毫秒单位
定义 Unit.hpp:226
static Unit KilometerPerHour()
千米每秒单位
定义 Unit.hpp:357
static Unit SquareKilometer()
平方公里单位
定义 Unit.hpp:372
std::pair< UnitRepHandle, int > UnitRepPair
单位表示子项
定义 Unit.hpp:150
Unit aUnitMultiply(const Unit &unit1, const Unit &unit2)
单位乘法
定义 Unit.cpp:330
Unit aUnitPower(const Unit &unit, int exponent)
单位幂
定义 Unit.cpp:358
Unit aUnitInvert(const Unit &unit)
单位倒数
定义 Unit.cpp:373
void aUnitFactorize(const Unit &unit, Unit &newUnit, double &scale)
单位分解
定义 Unit.cpp:387
Unit aUnitDivide(const Unit &unit1, const Unit &unit2)
单位除法
定义 Unit.cpp:344
constexpr double kArcSecToRad
弧秒到弧度 kDegToRad/3600.0 度分秒的秒
定义 Constants.h:229
constexpr double kDegToRad
角度到弧度 kPI/180.0
定义 Constants.h:228
Unit unit_divide(const Unit &unit1, const Unit &unit2)
单位除法
定义 Unit.cpp:264
Unit unit_power(const Unit &unit, int exponent)
单位幂
定义 Unit.cpp:297
void unit_setname(Unit &unit, StringView name)
设置单位名称
定义 Unit.cpp:324
Unit unit_multiply(const Unit &unit1, const Unit &unit2)
单位乘法
定义 Unit.cpp:233