scifir-units 2.0.0
scifir-units is a library of units of measurement, angles, coordinates, fields, and related data, all lightweight, that help in the development of scientific software and scientific machines
Loading...
Searching...
No Matches
dimension.cpp
Go to the documentation of this file.
1#include "./dimension.hpp"
2
3#include "./constants.hpp"
4
5#include "boost/algorithm/string.hpp"
6
7#include "unicode/unistr.h"
8#include "unicode/uchar.h"
9
10#include <cmath>
11#include <iostream>
12#include <numbers>
13#include <set>
14#include <sstream>
15#include <string>
16#include <utility>
17
18using namespace std;
19
20namespace scifir
21{
22 map<string,vector<dimension>> dimension::base_dimensions = map<string,vector<dimension>>();
23 map<int,string> dimension::full_symbols = map<int,string>();
25 set<string> dimension::prefixes_options {"Q", "R", "Y", "Z", "E", "P", "T", "G", "M", "k", "h", "d", "c", "m", "\u00B5", "u", "n", "p", "f", "a", "z", "y", "r", "q"};
26
27 dimension::dimension() : prefix(),dimension_type(dimension::NONE),dimension_position(dimension::NO_POSITION),symbol()
28 {}
29
30#ifdef IS_UNIX
31 dimension::dimension(const dimension& x) : prefix(x.prefix),dimension_type(x.dimension_type),dimension_position(x.dimension_position)
32 {
33 std::strncpy(symbol, x.symbol, 3);
34 }
35
36 dimension::dimension(dimension&& x) : prefix(std::move(x.prefix)),dimension_type(std::move(x.dimension_type)),dimension_position(std::move(x.dimension_position))
37 {
38 std::strncpy(symbol, std::move(x.symbol), 3);
39 }
40#elif IS_WINDOWS
41 dimension::dimension(const dimension& x) : prefix(x.prefix),dimension_type(x.dimension_type),dimension_position(x.dimension_position)
42 {
43 strncpy_s(symbol, x.symbol, 3);
44 }
45
46 dimension::dimension(dimension&& x) : prefix(std::move(x.prefix)),dimension_type(std::move(x.dimension_type)),dimension_position(std::move(x.dimension_position))
47 {
48 strncpy_s(symbol, std::move(x.symbol), 3);
49 }
50#endif
51
54
57
58 dimension::dimension(const string& init_dimension,dimension::position new_position) : prefix(),dimension_type(dimension::NONE),dimension_position(new_position),symbol()
59 {
60 string dimension_name;
61 string prefix_name;
62 if(dimension::prefixes_options.count(init_dimension.substr(0,1)) and init_dimension != "degree" and init_dimension != "rad" and init_dimension != "sr" and init_dimension != "m" and init_dimension != "Hz" and init_dimension != "Pa" and init_dimension.substr(0,2) != "da" and init_dimension != "°C" and init_dimension.substr(0,3) != "mol" and init_dimension != "cd" and init_dimension != "Ω" and init_dimension != "Ohm" and init_dimension != "ohm" and init_dimension != "T" and init_dimension != "Gy" and init_dimension != "kat" and init_dimension != "Å" and init_dimension != "angstrom" and init_dimension != "min" and init_dimension != "hour" and init_dimension != "day" and init_dimension != "pc" and init_dimension != "amu" and init_dimension != "M" and init_dimension != "particles" and init_dimension != "money" and init_dimension != "px" and init_dimension != "memo" and init_dimension != "mEq" and init_dimension != "dB")
63 {
64 prefix_name = init_dimension.substr(0,1);
66 }
67 else if(init_dimension == "day")
68 {
69 prefix_name = "";
71 }
72 else if(init_dimension.substr(0,2) == "da")
73 {
74 prefix_name = "da";
76 }
77 else
78 {
79 prefix_name = "";
81 }
83 if(dimension_name == "m")
84 {
86 }
87 else if(dimension_name == "degree" or dimension_name == "θ")
88 {
90 }
91 else if(dimension_name == "rad")
92 {
94 }
95 else if(dimension_name == "sr")
96 {
98 }
99 else if(dimension_name == "s")
100 {
102 }
103 else if(dimension_name == "g")
104 {
106 }
107 else if(dimension_name == "C")
108 {
110 }
111 else if(dimension_name == "K")
112 {
114 }
115 else if(dimension_name == "°C")
116 {
118 }
119 else if(dimension_name == "mol")
120 {
122 }
123 else if(dimension_name == "cd")
124 {
126 }
127 else if(dimension_name == "B")
128 {
130 }
131 else if(dimension_name == "bit")
132 {
134 }
135 else if(dimension_name == "Hz")
136 {
138 }
139 else if(dimension_name == "N")
140 {
142 }
143 else if(dimension_name == "Pa")
144 {
146 }
147 else if(dimension_name == "J")
148 {
150 }
151 else if(dimension_name == "W")
152 {
154 }
155 else if(dimension_name == "A")
156 {
158 }
159 else if(dimension_name == "V")
160 {
162 }
163 else if(dimension_name == "F")
164 {
166 }
167 else if(dimension_name == "ohm" or dimension_name == "Ohm" or dimension_name == "Ω")
168 {
170 }
171 else if(dimension_name == "S")
172 {
174 }
175 else if(dimension_name == "Wb")
176 {
178 }
179 else if(dimension_name == "T")
180 {
182 }
183 else if(dimension_name == "H")
184 {
186 }
187 else if(dimension_name == "lm")
188 {
190 }
191 else if(dimension_name == "lx")
192 {
194 }
195 else if(dimension_name == "Bq")
196 {
198 }
199 else if(dimension_name == "Gy")
200 {
202 }
203 else if(dimension_name == "Sv")
204 {
206 }
207 else if(dimension_name == "kat")
208 {
210 }
211 else if(dimension_name == "angstrom" or dimension_name == "Å")
212 {
214 }
215 else if(dimension_name == "L")
216 {
218 }
219 else if(dimension_name == "min")
220 {
222 }
223 else if(dimension_name == "hour")
224 {
226 }
227 else if(dimension_name == "day")
228 {
230 }
231 else if(dimension_name == "ly")
232 {
234 }
235 else if(dimension_name == "AU")
236 {
238 }
239 else if(dimension_name == "pc")
240 {
242 }
243 else if(dimension_name == "eV")
244 {
246 }
247 else if(dimension_name == "Da")
248 {
250 }
251 else if(dimension_name == "amu")
252 {
254 }
255 else if(dimension_name == "barn")
256 {
258 }
259 else if(dimension_name == "M")
260 {
262 }
263 else if(dimension_name == "particles")
264 {
266 }
267 else if(dimension_name == "money")
268 {
270 }
271 else if(dimension_name == "px")
272 {
274 }
275 else if(dimension_name == "memo")
276 {
278 }
279 else if(dimension_name == "IU")
280 {
282 }
283 else if(dimension_name == "mEq")
284 {
286 }
287 else if(dimension_name == "dB")
288 {
290 }
291 else if(dimension_name == "")
292 {
294 }
295 else
296 {
298 if (init_dimension.size() > 2)
299 {
301#ifdef IS_UNIX
302 std::strncpy(symbol, symbol_abreviation.c_str(), 2);
303#elif IS_WINDOWS
304 strncpy_s(symbol, 3, symbol_abreviation.c_str(), 2);
305#endif
307 }
308 else
309 {
310#ifdef IS_UNIX
311 std::strncpy(symbol, init_dimension.c_str(), 2);
312#elif IS_WINDOWS
313 strncpy_s(symbol, 3, init_dimension.c_str(), 2);
314#endif
316 }
317 }
318 }
319
320#ifdef IS_UNIX
322 {
323 prefix = x.prefix;
326 std::strncpy(symbol,x.symbol,3);
327 return *this;
328 }
329
330 dimension& dimension::operator =(dimension&& x)
331 {
332 prefix = std::move(x.prefix);
333 dimension_type = std::move(x.dimension_type);
334 dimension_position = std::move(x.dimension_position);
335 std::strncpy(symbol,std::move(x.symbol),3);
336 return *this;
337 }
338#elif IS_WINDOWS
339 dimension& dimension::operator =(const dimension& x)
340 {
341 prefix = x.prefix;
342 dimension_type = x.dimension_type;
343 dimension_position = x.dimension_position;
344 strncpy_s(symbol,x.symbol,3);
345 return *this;
346 }
347
348 dimension& dimension::operator =(dimension&& x)
349 {
350 prefix = std::move(x.prefix);
351 dimension_type = std::move(x.dimension_type);
352 dimension_position = std::move(x.dimension_position);
353 strncpy_s(symbol,std::move(x.symbol),3);
354 return *this;
355 }
356#endif
357
358 string dimension::get_name() const
359 {
360 switch(dimension_type)
361 {
362 case dimension::NONE:
363 return "empty";
364 case dimension::METRE:
365 return "metre";
367 return "degree";
369 return "radian";
371 return "steradian";
373 return "second";
374 case dimension::GRAM:
375 return "gram";
377 return "coulomb";
379 return "kelvin";
381 return "celsius";
382 case dimension::MOLE:
383 return "mole";
385 return "candela";
386 case dimension::BYTE:
387 return "byte";
388 case dimension::BIT:
389 return "bit";
390 case dimension::HERTZ:
391 return "hertz";
393 return "newton";
395 return "pascal";
396 case dimension::JOULE:
397 return "joule";
398 case dimension::WATT:
399 return "watt";
401 return "ampere";
402 case dimension::VOLT:
403 return "volt";
404 case dimension::FARAD:
405 return "farad";
406 case dimension::OHM:
407 return "ohm";
409 return "siemens";
410 case dimension::WEBER:
411 return "weber";
412 case dimension::TESLA:
413 return "tesla";
414 case dimension::HENRY:
415 return "henry";
416 case dimension::LUMEN:
417 return "lumen";
418 case dimension::LUX:
419 return "lux";
421 return "becquerel";
422 case dimension::GRAY:
423 return "gray";
425 return "sievert";
426 case dimension::KATAL:
427 return "katal";
429 return "angstrom";
430 case dimension::LITRE:
431 return "litre";
433 return "minute";
434 case dimension::HOUR:
435 return "hour";
436 case dimension::DAY:
437 return "day";
439 return "light year";
441 return "astronomical unit";
443 return "parsec";
445 return "electron volt";
447 return "dalton";
449 return "atomic mass unit";
450 case dimension::BARN:
451 return "barn";
453 return "molarity";
455 return "particles";
457 return "custom-dimension";
459 return "custom-basic";
461 return "custom-full-symbol";
462 case dimension::MONEY:
463 return "money";
464 case dimension::PIXEL:
465 return "pixel";
466 case dimension::MEMO:
467 return "memo";
469 return "international-unit";
471 return "milliequivalent";
473 return "decibel";
474 }
475 return "";
476 }
477
479 {
480 return prefix.get_name() + get_name();
481 }
482
484 {
485 switch(dimension_type)
486 {
487 case dimension::NONE:
488 return "empty";
489 case dimension::METRE:
490 return "metres";
492 return "degrees";
494 return "radians";
496 return "steradians";
498 return "seconds";
499 case dimension::GRAM:
500 return "grams";
502 return "coulombs";
504 return "kelvins";
506 return "celsius";
507 case dimension::MOLE:
508 return "moles";
510 return "candelas";
511 case dimension::BYTE:
512 return "bytes";
513 case dimension::BIT:
514 return "bits";
515 case dimension::HERTZ:
516 return "hertz";
518 return "newtons";
520 return "pascals";
521 case dimension::JOULE:
522 return "joules";
523 case dimension::WATT:
524 return "watts";
526 return "amperes";
527 case dimension::VOLT:
528 return "volts";
529 case dimension::FARAD:
530 return "farads";
531 case dimension::OHM:
532 return "ohms";
534 return "siemens";
535 case dimension::WEBER:
536 return "webers";
537 case dimension::TESLA:
538 return "teslas";
539 case dimension::HENRY:
540 return "henries";
541 case dimension::LUMEN:
542 return "lumens";
543 case dimension::LUX:
544 return "luxes";
546 return "becquerels";
547 case dimension::GRAY:
548 return "grays";
550 return "sieverts";
551 case dimension::KATAL:
552 return "katals";
554 return "angstroms";
555 case dimension::LITRE:
556 return "litres";
558 return "minutes";
559 case dimension::HOUR:
560 return "hours";
561 case dimension::DAY:
562 return "days";
564 return "light years";
566 return "astronomical units";
568 return "parsecs";
570 return "electron volts";
572 return "daltons";
574 return "atomic mass units";
575 case dimension::BARN:
576 return "barns";
578 return "molarities";
580 return "particles";
582 return "custom-dimension";
584 return "custom-basic";
586 return "custom-full-symbol";
587 case dimension::MONEY:
588 return "money";
589 case dimension::PIXEL:
590 return "pixels";
591 case dimension::MEMO:
592 return "memos";
594 return "international-units";
596 return "milliequivalents";
598 return "decibels";
599 }
600 return "";
601 }
602
604 {
605 return prefix.get_name() + get_plural();
606 }
607
609 {
610 switch(dimension_type)
611 {
612 case dimension::NONE:
613 return "empty";
614 case dimension::METRE:
615 return "m";
616#ifdef IS_UNIX
618 return "θ";
619#elif IS_WINDOWS
621 return "θ";
622#endif
624 return "rad";
626 return "sr";
628 return "s";
629 case dimension::GRAM:
630 return "g";
632 return "C";
634 return "K";
636 return "°C";
637 case dimension::MOLE:
638 return "mol";
640 return "cd";
641 case dimension::BYTE:
642 return "B";
643 case dimension::BIT:
644 return "bit";
645 case dimension::HERTZ:
646 return "Hz";
648 return "N";
650 return "Pa";
651 case dimension::JOULE:
652 return "J";
653 case dimension::WATT:
654 return "W";
656 return "A";
657 case dimension::VOLT:
658 return "V";
659 case dimension::FARAD:
660 return "F";
661#ifdef IS_UNIX
662 case dimension::OHM:
663 return "Ω";
664#elif IS_WINDOWS
665 case dimension::OHM:
666 return "Ω";
667#endif
669 return "S";
670 case dimension::WEBER:
671 return "Wb";
672 case dimension::TESLA:
673 return "T";
674 case dimension::HENRY:
675 return "H";
676 case dimension::LUMEN:
677 return "lm";
678 case dimension::LUX:
679 return "lx";
681 return "Bq";
682 case dimension::GRAY:
683 return "Gy";
685 return "Sv";
686 case dimension::KATAL:
687 return "kat";
688#ifdef IS_UNIX
690 return "Å";
691#elif IS_WINDOWS
693 return "Å";
694#endif
695 case dimension::LITRE:
696 return "L";
698 return "min";
699 case dimension::HOUR:
700 return "hour";
701 case dimension::DAY:
702 return "day";
704 return "ly";
706 return "AU";
708 return "pc";
710 return "eV";
712 return "Da";
714 return "amu";
715 case dimension::BARN:
716 return "barn";
718 return "M";
720 return "particles";
722 return string("").assign(symbol, symbol + 3);
724 return "custom-basic";
727 case dimension::MONEY:
728 return "money";
729 case dimension::PIXEL:
730 return "px";
731 case dimension::MEMO:
732 return "memo";
734 return "IU";
736 return "mEq";
738 return "dB";
739 }
740 return "";
741 }
742
744 {
745 switch(dimension_type)
746 {
747 case dimension::NONE:
748 return 1.0l;
749 case dimension::METRE:
750 return 1.0l;
752 return std::numbers::pi_v<float> / 180.0l;
754 return 1.0l;
756 return 1.0l;
757 case dimension::GRAM:
758 return 1.0l;
760 return 1.0l;
762 return 1.0l;
764 return 1.0l;
766 return 1.0l;
767 case dimension::MOLE:
768 return 1.0l;
770 return 1.0l;
771 case dimension::BYTE:
772 return 1.0l;
773 case dimension::BIT:
774 return 0.125l;
775 case dimension::HERTZ:
776 return 1.0l;
778 return 1.0l;
780 return 1.0l;
781 case dimension::JOULE:
782 return 1.0l;
783 case dimension::WATT:
784 return 1.0l;
786 return 1.0l;
787 case dimension::VOLT:
788 return 1.0l;
789 case dimension::FARAD:
790 return 1;
791 case dimension::OHM:
792 return 1.0l;
794 return 1.0l;
795 case dimension::WEBER:
796 return 1.0l;
797 case dimension::TESLA:
798 return 1.0l;
799 case dimension::HENRY:
800 return 1.0l;
801 case dimension::LUMEN:
802 return 1.0l;
803 case dimension::LUX:
804 return 1.0l;
806 return 1.0l;
807 case dimension::GRAY:
808 return 1.0l;
810 return 1.0l;
811 case dimension::KATAL:
812 return 1.0l;
814 return 1.0l;
815 case dimension::LITRE:
816 return 1.0l;
818 return 60l;
819 case dimension::HOUR:
820 return 3600l;
821 case dimension::DAY:
822 return 86400l;
824 return 9.4607379375591e15;
826 return 149597870700.0l;
828 return 30856775814913673.0l;
830 return 0.0000000000000000001602176634l;
832 return 0.00000000000000000000000000166053886l;
834 return 0.00000000000000000000000000166053886l;
835 case dimension::BARN:
836 return 0.0000000000000000000000000001l;
838 return 1.0l;
840 return 1.0l/AVOGADRO_CONSTANT;
842 return 1.0l;
844 return 1.0l;
846 return 1.0l;
847 case dimension::MONEY:
848 return 1.0l;
849 case dimension::PIXEL:
850 return 1.0l;
851 case dimension::MEMO:
852 return 1.0l;
854 return 1.0l;
856 return 1.0l;
858 return 1.0l;
859 }
860 return 1.0l;
861 }
862
863 long double dimension::prefix_math() const
864 {
865 return prefix_math(prefix);
866 }
867
869 {
871 {
872 return std::pow(1024, x_prefix.get_conversion_factor() / 3);
873 }
874 else
875 {
876 return std::pow(10, x_prefix.get_conversion_factor());
877 }
878 }
879
881 {
882 switch(dimension_type)
883 {
884 case dimension::NONE:
885 return false;
886 case dimension::METRE:
887 return true;
889 return true;
891 return true;
893 return true;
894 case dimension::GRAM:
895 return true;
897 return true;
899 return true;
901 return true;
903 return true;
904 case dimension::MOLE:
905 return true;
907 return true;
908 case dimension::BYTE:
909 return true;
910 case dimension::BIT:
911 return true;
912 case dimension::HERTZ:
913 return true;
915 return false;
917 return false;
918 case dimension::JOULE:
919 return false;
920 case dimension::WATT:
921 return false;
923 return true;
924 case dimension::VOLT:
925 return false;
926 case dimension::FARAD:
927 return false;
928 case dimension::OHM:
929 return false;
931 return false;
932 case dimension::WEBER:
933 return false;
934 case dimension::TESLA:
935 return false;
936 case dimension::HENRY:
937 return false;
938 case dimension::LUMEN:
939 return false;
940 case dimension::LUX:
941 return false;
943 return true;
944 case dimension::GRAY:
945 return false;
947 return false;
948 case dimension::KATAL:
949 return false;
951 return true;
952 case dimension::LITRE:
953 return false;
955 return true;
956 case dimension::HOUR:
957 return true;
958 case dimension::DAY:
959 return true;
961 return true;
963 return true;
965 return true;
967 return false;
969 return true;
971 return true;
972 case dimension::BARN:
973 return false;
975 return false;
977 return true;
979 return false;
981 return true;
983 return false;
984 case dimension::MONEY:
985 return true;
986 case dimension::PIXEL:
987 return true;
988 case dimension::MEMO:
989 return true;
991 return true;
993 return true;
995 return true;
996 }
997 return false;
998 }
999
1001 {
1003 {
1004 return false;
1005 }
1006 else
1007 {
1008 return !is_simple_dimension();
1009 }
1010 }
1011
1013 {
1014 switch(dimension_type)
1015 {
1016 case dimension::NONE:
1017 return false;
1018 case dimension::METRE:
1019 return true;
1020 case dimension::DEGREE:
1021 return false;
1022 case dimension::RADIAN:
1023 return true;
1025 return true;
1026 case dimension::GRAM:
1027 return true;
1028 case dimension::SECOND:
1029 return true;
1030 case dimension::COULOMB:
1031 return true;
1032 case dimension::KELVIN:
1033 return true;
1034 case dimension::CELSIUS:
1035 return false;
1036 case dimension::MOLE:
1037 return true;
1038 case dimension::CANDELA:
1039 return true;
1040 case dimension::BYTE:
1041 return true;
1042 case dimension::BIT:
1043 return false;
1044 case dimension::HERTZ:
1045 return false;
1046 case dimension::NEWTON:
1047 return false;
1048 case dimension::PASCAL:
1049 return false;
1050 case dimension::JOULE:
1051 return false;
1052 case dimension::WATT:
1053 return false;
1054 case dimension::AMPERE:
1055 return false;
1056 case dimension::VOLT:
1057 return false;
1058 case dimension::FARAD:
1059 return false;
1060 case dimension::OHM:
1061 return false;
1062 case dimension::SIEMENS:
1063 return false;
1064 case dimension::WEBER:
1065 return false;
1066 case dimension::TESLA:
1067 return false;
1068 case dimension::HENRY:
1069 return false;
1070 case dimension::LUMEN:
1071 return false;
1072 case dimension::LUX:
1073 return false;
1075 return false;
1076 case dimension::GRAY:
1077 return false;
1078 case dimension::SIEVERT:
1079 return false;
1080 case dimension::KATAL:
1081 return false;
1083 return false;
1084 case dimension::LITRE:
1085 return false;
1086 case dimension::MINUTE:
1087 return false;
1088 case dimension::HOUR:
1089 return false;
1090 case dimension::DAY:
1091 return false;
1093 return false;
1095 return false;
1096 case dimension::PARSEC:
1097 return false;
1099 return false;
1100 case dimension::DALTON:
1101 return false;
1103 return false;
1104 case dimension::BARN:
1105 return false;
1107 return false;
1109 return false;
1110 case dimension::CUSTOM:
1111 return false;
1113 return true;
1115 return false;
1116 case dimension::MONEY:
1117 return true;
1118 case dimension::PIXEL:
1119 return true;
1120 case dimension::MEMO:
1121 return true;
1123 return true;
1125 return true;
1126 case dimension::DECIBEL:
1127 return true;
1128 }
1129 return false;
1130 }
1131
1133 {
1135 {
1136 return false;
1137 }
1138 else
1139 {
1140 return !is_base_dimension();
1141 }
1142 }
1143
1145 {
1146 switch(dimension_type)
1147 {
1148 case dimension::NONE:
1149 return false;
1150 case dimension::METRE:
1151 return true;
1152 case dimension::DEGREE:
1153 return false;
1154 case dimension::RADIAN:
1155 return false;
1157 return false;
1158 case dimension::GRAM:
1159 return true;
1160 case dimension::SECOND:
1161 return true;
1162 case dimension::COULOMB:
1163 return false;
1164 case dimension::KELVIN:
1165 return true;
1166 case dimension::CELSIUS:
1167 return false;
1168 case dimension::MOLE:
1169 return true;
1170 case dimension::CANDELA:
1171 return true;
1172 case dimension::BYTE:
1173 return false;
1174 case dimension::BIT:
1175 return false;
1176 case dimension::HERTZ:
1177 return false;
1178 case dimension::NEWTON:
1179 return false;
1180 case dimension::PASCAL:
1181 return false;
1182 case dimension::JOULE:
1183 return false;
1184 case dimension::WATT:
1185 return false;
1186 case dimension::AMPERE:
1187 return true;
1188 case dimension::VOLT:
1189 return false;
1190 case dimension::FARAD:
1191 return false;
1192 case dimension::OHM:
1193 return false;
1194 case dimension::SIEMENS:
1195 return false;
1196 case dimension::WEBER:
1197 return false;
1198 case dimension::TESLA:
1199 return false;
1200 case dimension::HENRY:
1201 return false;
1202 case dimension::LUMEN:
1203 return false;
1204 case dimension::LUX:
1205 return false;
1207 return false;
1208 case dimension::GRAY:
1209 return false;
1210 case dimension::SIEVERT:
1211 return false;
1212 case dimension::KATAL:
1213 return false;
1215 return false;
1216 case dimension::LITRE:
1217 return false;
1218 case dimension::MINUTE:
1219 return false;
1220 case dimension::HOUR:
1221 return false;
1222 case dimension::DAY:
1223 return false;
1225 return false;
1227 return false;
1228 case dimension::PARSEC:
1229 return false;
1231 return false;
1232 case dimension::DALTON:
1233 return false;
1235 return false;
1236 case dimension::BARN:
1237 return false;
1239 return false;
1241 return false;
1242 case dimension::CUSTOM:
1243 return false;
1245 return false;
1247 return false;
1248 case dimension::MONEY:
1249 return false;
1250 case dimension::PIXEL:
1251 return false;
1252 case dimension::MEMO:
1253 return false;
1255 return false;
1257 return false;
1258 case dimension::DECIBEL:
1259 return false;
1260 }
1261 return false;
1262 }
1263
1265 {
1266 switch(dimension_type)
1267 {
1268 case dimension::NONE:
1269 return false;
1270 case dimension::METRE:
1271 return false;
1272 case dimension::DEGREE:
1273 return true;
1274 case dimension::RADIAN:
1275 return true;
1277 return true;
1278 case dimension::GRAM:
1279 return false;
1280 case dimension::SECOND:
1281 return false;
1282 case dimension::COULOMB:
1283 return true;
1284 case dimension::KELVIN:
1285 return false;
1286 case dimension::CELSIUS:
1287 return true;
1288 case dimension::MOLE:
1289 return false;
1290 case dimension::CANDELA:
1291 return false;
1292 case dimension::BYTE:
1293 return false;
1294 case dimension::BIT:
1295 return false;
1296 case dimension::HERTZ:
1297 return true;
1298 case dimension::NEWTON:
1299 return true;
1300 case dimension::PASCAL:
1301 return true;
1302 case dimension::JOULE:
1303 return true;
1304 case dimension::WATT:
1305 return true;
1306 case dimension::AMPERE:
1307 return false;
1308 case dimension::VOLT:
1309 return true;
1310 case dimension::FARAD:
1311 return true;
1312 case dimension::OHM:
1313 return true;
1314 case dimension::SIEMENS:
1315 return true;
1316 case dimension::WEBER:
1317 return true;
1318 case dimension::TESLA:
1319 return true;
1320 case dimension::HENRY:
1321 return true;
1322 case dimension::LUMEN:
1323 return true;
1324 case dimension::LUX:
1325 return true;
1327 return true;
1328 case dimension::GRAY:
1329 return true;
1330 case dimension::SIEVERT:
1331 return true;
1332 case dimension::KATAL:
1333 return true;
1335 return false;
1336 case dimension::LITRE:
1337 return false;
1338 case dimension::MINUTE:
1339 return false;
1340 case dimension::HOUR:
1341 return false;
1342 case dimension::DAY:
1343 return false;
1345 return false;
1347 return false;
1348 case dimension::PARSEC:
1349 return false;
1351 return false;
1352 case dimension::DALTON:
1353 return false;
1355 return false;
1356 case dimension::BARN:
1357 return false;
1359 return false;
1361 return false;
1362 case dimension::CUSTOM:
1363 return false;
1365 return false;
1367 return false;
1368 case dimension::MONEY:
1369 return false;
1370 case dimension::PIXEL:
1371 return false;
1372 case dimension::MEMO:
1373 return false;
1375 return false;
1377 return false;
1378 case dimension::DECIBEL:
1379 return false;
1380 }
1381 return false;
1382 }
1383
1385 {
1387 {
1388 return true;
1389 }
1390 else
1391 {
1392 return false;
1393 }
1394 }
1395
1397 {
1399 switch (dimension_type)
1400 {
1401 case dimension::NONE:
1403 break;
1404 case dimension::METRE:
1406 break;
1407 case dimension::DEGREE:
1409 break;
1410 case dimension::RADIAN:
1412 break;
1415 break;
1416 case dimension::SECOND:
1418 break;
1419 case dimension::GRAM:
1421 break;
1422 case dimension::COULOMB:
1424 break;
1425 case dimension::KELVIN:
1427 break;
1428 case dimension::CELSIUS:
1430 break;
1431 case dimension::MOLE:
1433 break;
1434 case dimension::CANDELA:
1436 break;
1437 case dimension::BYTE:
1439 break;
1440 case dimension::BIT:
1442 break;
1443 case dimension::HERTZ:
1445 break;
1446 case dimension::NEWTON:
1451 break;
1452 case dimension::PASCAL:
1457 break;
1458 case dimension::JOULE:
1464 break;
1465 case dimension::WATT:
1472 break;
1473 case dimension::AMPERE:
1476 break;
1477 case dimension::VOLT:
1484 break;
1485 case dimension::FARAD:
1493 break;
1494 case dimension::OHM:
1501 break;
1502 case dimension::SIEMENS:
1509 break;
1510 case dimension::WEBER:
1516 break;
1517 case dimension::TESLA:
1521 break;
1522 case dimension::HENRY:
1528 break;
1529 case dimension::LUMEN:
1532 break;
1533 case dimension::LUX:
1538 break;
1541 break;
1542 case dimension::GRAY:
1547 break;
1548 case dimension::SIEVERT:
1553 break;
1554 case dimension::KATAL:
1557 break;
1560 break;
1561 case dimension::LITRE:
1565 break;
1566 case dimension::MINUTE:
1568 break;
1569 case dimension::HOUR:
1571 break;
1572 case dimension::DAY:
1574 break;
1577 break;
1580 break;
1581 case dimension::PARSEC:
1583 break;
1590 break;
1591 case dimension::DALTON:
1593 break;
1596 break;
1597 case dimension::BARN:
1600 break;
1606 break;
1609 break;
1610 case dimension::CUSTOM:
1611 {
1612 //return dimension::base_dimensions[symbol];
1613 break;
1614 }
1616 {
1617 basic_dimensions.push_back(*this);
1618 break;
1619 }
1621 {
1622 break;
1623 //return dimension::base_dimensions[dimension::get_full_symbol(symbol)];
1624 }
1625 case dimension::MONEY:
1627 break;
1628 case dimension::PIXEL:
1630 break;
1631 case dimension::MEMO:
1633 break;
1636 break;
1639 break;
1640 case dimension::DECIBEL:
1642 break;
1643 }
1644 return basic_dimensions;
1645 }
1646
1648 {
1650 {
1652 }
1653 else
1654 {
1656 }
1657 }
1658
1659 string to_string(const dimension& x)
1660 {
1662 out << x.prefix << x.get_symbol();
1663 return out.str();
1664 }
1665
1667 {
1669 if (x_dimensions.size() > 0)
1670 {
1671 if (with_brackets)
1672 {
1673 out << "[";
1674 }
1677 bool first_print = true;
1678 for (const dimension& x_dimension : x_dimensions)
1679 {
1680 if (x_dimension.dimension_position == dimension::NUMERATOR)
1681 {
1682 bool printed = false;
1684 {
1685 if (print_dimension == x_dimension.dimension_type)
1686 {
1687 printed = true;
1688 }
1689 }
1690 if (printed == true)
1691 {
1692 continue;
1693 }
1695 for (const dimension& y_dimension : x_dimensions)
1696 {
1697 if (x_dimension.dimension_type == y_dimension.dimension_type)
1698 {
1699 counted_prefixes[y_dimension.prefix]++;
1700 }
1701 }
1702 for (const auto& x_prefix : counted_prefixes)
1703 {
1704 if (!first_print)
1705 {
1706 out << "*";
1707 }
1708 out << x_prefix.first << x_dimension.get_symbol();
1709 if (x_prefix.second > 1)
1710 {
1711 out << x_prefix.second;
1712 }
1713 first_print = false;
1714 }
1715 printed_dimensions.push_back(x_dimension.dimension_type);
1716 }
1717 }
1718 printed_dimensions.clear();
1719 bool first_negative_iteration = true;
1720 bool first_negative_prefix = true;
1721 for (const dimension& x_dimension : x_dimensions)
1722 {
1723 if (x_dimension.dimension_position == dimension::DENOMINATOR)
1724 {
1725 if (first_negative_iteration == true)
1726 {
1727 if (first_print)
1728 {
1729 out << "1";
1730 }
1731 out << "/";
1733 }
1734 bool printed = false;
1736 {
1737 if (print_dimension == x_dimension.dimension_type)
1738 {
1739 printed = true;
1740 }
1741 }
1742 if (printed == true)
1743 {
1744 continue;
1745 }
1747 for (const dimension& y_dimension : x_dimensions)
1748 {
1749 if (x_dimension.dimension_type == y_dimension.dimension_type)
1750 {
1751 counted_prefixes[y_dimension.prefix]++;
1752 }
1753 }
1754 for (const auto& x_prefix : counted_prefixes)
1755 {
1756 if (first_negative_prefix == false)
1757 {
1758 out << "*";
1759 }
1760 out << x_prefix.first << x_dimension.get_symbol();
1761 if (x_prefix.second > 1)
1762 {
1763 out << x_prefix.second;
1764 }
1765 first_negative_prefix = false;
1766 }
1767 printed_dimensions.push_back(x_dimension.dimension_type);
1768 }
1769 }
1770 if (with_brackets)
1771 {
1772 out << "]";
1773 }
1774 }
1775 else
1776 {
1777 out << "[empty]";
1778 }
1779 return out.str();
1780 }
1781
1783 {
1785 bool is_fraction = false;
1786 if (x_dimensions.size() > 0)
1787 {
1790 bool first_print = true;
1791 for (const dimension& x_dimension : x_dimensions)
1792 {
1793 if (x_dimension.dimension_position == dimension::NUMERATOR)
1794 {
1795 bool printed = false;
1797 {
1798 if (print_dimension == x_dimension.dimension_type)
1799 {
1800 printed = true;
1801 }
1802 }
1803 if (printed == true)
1804 {
1805 continue;
1806 }
1808 for (const dimension& y_dimension : x_dimensions)
1809 {
1810 if (x_dimension.dimension_type == y_dimension.dimension_type)
1811 {
1812 counted_prefixes[y_dimension.prefix]++;
1813 }
1814 }
1815 for (const auto& x_prefix : counted_prefixes)
1816 {
1817 if (!first_print)
1818 {
1819 out << "*";
1820 }
1821 out << x_prefix.first << x_dimension.get_symbol();
1822 if (x_prefix.second > 1)
1823 {
1824 out << "^" << x_prefix.second;
1825 }
1826 first_print = false;
1827 }
1828 printed_dimensions.push_back(x_dimension.dimension_type);
1829 }
1830 }
1831 printed_dimensions.clear();
1832 bool first_negative_iteration = true;
1833 bool first_negative_prefix = true;
1834 for (const dimension& x_dimension : x_dimensions)
1835 {
1836 if (x_dimension.dimension_position == dimension::DENOMINATOR)
1837 {
1838 is_fraction = true;
1839 if (first_negative_iteration == true)
1840 {
1841 if (first_print)
1842 {
1843 out << "1";
1844 }
1845 out << "}{";
1847 }
1848 bool printed = false;
1850 {
1851 if (print_dimension == x_dimension.dimension_type)
1852 {
1853 printed = true;
1854 }
1855 }
1856 if (printed == true)
1857 {
1858 continue;
1859 }
1861 for (const dimension& y_dimension : x_dimensions)
1862 {
1863 if (x_dimension.dimension_type == y_dimension.dimension_type)
1864 {
1865 counted_prefixes[y_dimension.prefix]++;
1866 }
1867 }
1868 for (const auto& x_prefix : counted_prefixes)
1869 {
1870 if (first_negative_prefix == false)
1871 {
1872 out << "*";
1873 }
1874 out << x_prefix.first << x_dimension.get_symbol();
1875 if (x_prefix.second > 1)
1876 {
1877 out << "^" << x_prefix.second;
1878 }
1879 first_negative_prefix = false;
1880 }
1881 printed_dimensions.push_back(x_dimension.dimension_type);
1882 }
1883 }
1884 if (is_fraction)
1885 {
1886 out << "}";
1887 }
1888 if (with_brackets)
1889 {
1890 out << "]";
1891 }
1892 }
1893 else
1894 {
1895 out << "[empty]";
1896 }
1897 if (is_fraction)
1898 {
1899 if (with_brackets)
1900 {
1901 return "[\frac{" + out.str();
1902 }
1903 else
1904 {
1905 return "\frac{" + out.str();
1906 }
1907 }
1908 else
1909 {
1910 if (with_brackets)
1911 {
1912 return "[" + out.str();
1913 }
1914 else
1915 {
1916 return out.str();
1917 }
1918 }
1919 }
1920
1922 {
1923 boost::algorithm::erase_all(init_dimensions, " ");
1925 int new_scale = 1;
1926 int new_size = 1;
1927 int new_start = 0;
1928 icu::UnicodeString new_dimension_str;
1929 vector<dimension> dimensions = vector<dimension>();
1930 icu::UnicodeString x_unicode = icu::UnicodeString(init_dimensions.c_str());
1931 int total_chars = x_unicode.countChar32();
1932 for(unsigned int j = 0; j < total_chars; j++)
1933 {
1934 if(x_unicode[j] == UChar32(U'1') and x_unicode[j + 1] == UChar32(U'/'))
1935 {
1937 }
1939 {
1941 if(u_isdigit(x_unicode[j + 1]))
1942 {
1944 }
1945 }
1946 if(x_unicode[j] == UChar32(U'*'))
1947 {
1948 new_size = 0;
1949 new_start = j + 1;
1950 }
1951 else if(x_unicode[j] == UChar32(U'/'))
1952 {
1954 new_size = 0;
1955 new_start = j + 1;
1956 }
1957 if(!new_dimension_str.countChar32() == 0)
1958 {
1960 string new_dimension_str_stl2 = "";
1962 if(new_dimension_str.countChar32() == 1)
1963 {
1964 if(new_dimension_str[0] == 0x03A9)
1965 {
1967 }
1968 else if(new_dimension_str[0] == 0x00C5)
1969 {
1971 }
1972 else if(new_dimension_str[0] == 0x03B8)
1973 {
1975 }
1976 else
1977 {
1978 string new_dimension_str_stl = "";
1981 }
1982 }
1983 else
1984 {
1985 if(new_dimension_str[new_dimension_str.countChar32() - 1] == 0x03A9)
1986 {
1987 string new_prefix_str = "";
1988 new_dimension_str.tempSubString(0,new_dimension_str.countChar32() - 1).toUTF8String(new_prefix_str);
1991 }
1992 else if(new_dimension_str[new_dimension_str.countChar32() - 1] == 0x00C5)
1993 {
1994 string new_prefix_str = "";
1995 new_dimension_str.tempSubString(0,new_dimension_str.countChar32() - 1).toUTF8String(new_prefix_str);
1998 }
1999 else if(new_dimension_str[new_dimension_str.countChar32() - 1] == 0x03B8)
2000 {
2001 string new_prefix_str = "";
2002 new_dimension_str.tempSubString(0,new_dimension_str.countChar32() - 1).toUTF8String(new_prefix_str);
2005 }
2006 else if(new_dimension_str[new_dimension_str.countChar32() - 2] == 0x00B0 && new_dimension_str[new_dimension_str.countChar32() - 1] == 0x0043)
2007 {
2008 string new_prefix_str = "";
2009 new_dimension_str.tempSubString(0,new_dimension_str.countChar32() - 2).toUTF8String(new_prefix_str);
2012 }
2013 else
2014 {
2015 string new_dimension_str_stl = "";
2018 }
2019 }
2020 for (int k = 0; k < new_scale; k++)
2021 {
2022 dimensions.push_back(new_dimension);
2023 }
2024 new_dimension_str.remove();
2025 new_scale = 1;
2026 new_size = 0;
2027 }
2028 new_size++;
2029 }
2030 return dimensions;
2031 }
2032
2038
2040 {
2042 for(unsigned int i = 0; i < x.size(); i++)
2043 {
2044 vector<dimension> x_subdimensions = x[i].get_base_dimensions();
2046 {
2047 if (x[i].dimension_position == dimension::DENOMINATOR)
2048 {
2049 x_subdimension.invert();
2050 }
2051 new_x.push_back(x_subdimension);
2052 }
2053 }
2054 return new_x;
2055 }
2056
2058 {
2060 for(unsigned int i = 0; i < x.size(); i++)
2061 {
2062 if (x[i].dimension_position == dimension::NUMERATOR)
2063 {
2064 value *= x[i].get_conversion_factor();
2065 value *= x[i].prefix_math();
2066 }
2067 else if (x[i].dimension_position == dimension::DENOMINATOR)
2068 {
2069 value /= x[i].get_conversion_factor();
2070 value /= x[i].prefix_math();
2071 }
2072 vector<dimension> x_subdimensions = x[i].get_base_dimensions();
2074 {
2075 if (x[i].dimension_position == dimension::DENOMINATOR)
2076 {
2077 x_subdimension.invert();
2078 }
2079 new_x.push_back(x_subdimension);
2080 }
2081 }
2082 if (x.size() == 1 and x[0].dimension_type == dimension::CELSIUS and x[0].dimension_position == dimension::NUMERATOR)
2083 {
2084 value += 273.15l;
2085 }
2086 return new_x;
2087 }
2088
2090 {
2092 for(const dimension& y_dimension : y)
2093 {
2094 new_dimensions.push_back(y_dimension);
2095 }
2096 return new_dimensions;
2097 }
2098
2100 {
2101 for(const dimension& y_dimension : y)
2102 {
2103 x.push_back(y_dimension);
2104 }
2105 return normalize_dimensions(x,value);
2106 }
2107
2109 {
2110 for(dimension y_dimension : y)
2111 {
2112 y_dimension.invert();
2113 x.push_back(y_dimension);
2114 }
2115 return normalize_dimensions(x,value);
2116 }
2117
2119 {
2121 for (const dimension& x_dimension : x)
2122 {
2123 dimensions_count[x_dimension.dimension_type]++;
2124 }
2125 for (const auto& x_count : dimensions_count)
2126 {
2127 if ((x_count.second % index) != 0)
2128 {
2129 return vector<dimension>();
2130 }
2131 }
2133 if (dimensions_count.size() == 1) // If there's only one type of dimension, square it and conserve its type
2134 {
2135 for (int i = 0; i < dimensions_count[x[0].dimension_type]; i++)
2136 {
2137 if (x[i].dimension_position == dimension::NUMERATOR)
2138 {
2139 value *= x[i].get_conversion_factor();
2140 value *= x[i].prefix_math();
2141 }
2142 else if (x[i].dimension_position == dimension::DENOMINATOR)
2143 {
2144 value /= x[i].get_conversion_factor();
2145 value /= x[i].prefix_math();
2146 }
2147 }
2148 int total_dimensions = int(std::pow(dimensions_count[x[0].dimension_type], 1.0f / index));
2149 x[0].prefix.prefix_type = prefix::NONE;
2150 for (int j = 0; j < total_dimensions; j++)
2151 {
2152 new_dimensions.push_back(x[0]);
2153 }
2154 return new_dimensions;
2155 }
2156 else // If there's more than one type of dimension, creates the simple dimensions of them, and squares the total. If there are special names, they are changed by their simple dimensions
2157 {
2158 x = normalize_dimensions(x,value);
2160 dimensions_count.clear();
2161 for (const dimension& x_dimension : x)
2162 {
2163 dimensions_count[x_dimension.dimension_type]++;
2164 }
2165 for (const dimension& x_dimension : x)
2166 {
2167 bool counted = false;
2169 {
2170 if (counted_dimension == x_dimension.dimension_type)
2171 {
2172 counted = true;
2173 }
2174 }
2175 if (counted == true)
2176 {
2177 continue;
2178 }
2179 int total_dimensions = int(std::pow(dimensions_count[x_dimension.dimension_type], 1.0f / index));
2180 for (int j = 0; j < total_dimensions; j++)
2181 {
2182 new_dimensions.push_back(x_dimension);
2183 }
2184 counted_dimensions.push_back(x_dimension.dimension_type);
2185 }
2186 }
2187 return new_dimensions;
2188 }
2189
2191 {
2193 for (const dimension& x_dimension: x)
2194 {
2195 for (unsigned int j = 1; j <= exponent; j++)
2196 {
2197 new_dimensions.push_back(x_dimension);
2198 }
2199 }
2200 return new_dimensions;
2201 }
2202
2204 {
2206 if (new_x.size() == 1)
2207 {
2208 return x;
2209 }
2211 for(unsigned int i = 0; i < new_x.size(); i++)
2212 {
2213 for(unsigned int j = i + 1; j < new_x.size(); j++)
2214 {
2215 if (skip_dimensions.size() > 0)
2216 {
2217 bool skip = false;
2218 for(unsigned int k = 0; k < skip_dimensions.size(); k++)
2219 {
2220 if (j == skip_dimensions[k])
2221 {
2222 skip = true;
2223 break;
2224 }
2225 }
2226 if (skip)
2227 {
2228 continue;
2229 }
2230 }
2231 if (new_x[i].dimension_type == new_x[j].dimension_type and new_x[i].dimension_position != new_x[j].dimension_position)
2232 {
2233 skip_dimensions.push_back(i);
2234 skip_dimensions.push_back(j);
2235 break;
2236 }
2237 }
2238 }
2240 for(unsigned int i = 0; i < new_x.size(); i++)
2241 {
2242 bool skip = false;
2243 for(unsigned int j = 0; j < skip_dimensions.size(); j++)
2244 {
2245 if (i == skip_dimensions[j])
2246 {
2247 skip = true;
2248 break;
2249 }
2250 }
2251 if (!skip)
2252 {
2253 new_dimensions.push_back(new_x[i]);
2254 }
2255 }
2256 return new_dimensions;
2257 }
2258
2260 {
2262 if (new_x.size() == 1)
2263 {
2264 return x;
2265 }
2267 for(unsigned int i = 0; i < new_x.size(); i++)
2268 {
2269 for(unsigned int j = i + 1; j < new_x.size(); j++)
2270 {
2271 if (skip_dimensions.size() > 0)
2272 {
2273 bool skip = false;
2274 for(unsigned int k = 0; k < skip_dimensions.size(); k++)
2275 {
2276 if (j == skip_dimensions[k])
2277 {
2278 skip = true;
2279 break;
2280 }
2281 }
2282 if (skip)
2283 {
2284 continue;
2285 }
2286 }
2287 if (new_x[i].dimension_type == new_x[j].dimension_type and new_x[i].dimension_position != new_x[j].dimension_position)
2288 {
2289 if (new_x[i].dimension_position == dimension::NUMERATOR)
2290 {
2291 value *= float(new_x[i].get_conversion_factor());
2292 value *= float(new_x[i].prefix_math());
2293 }
2294 else if (new_x[i].dimension_position == dimension::DENOMINATOR)
2295 {
2296 value /= float(new_x[i].get_conversion_factor());
2297 value /= float(new_x[i].prefix_math());
2298 }
2299 if (new_x[j].dimension_position == dimension::NUMERATOR)
2300 {
2301 value *= float(new_x[j].get_conversion_factor());
2302 value *= float(new_x[j].prefix_math());
2303 }
2304 else if (new_x[j].dimension_position == dimension::DENOMINATOR)
2305 {
2306 value /= float(new_x[j].get_conversion_factor());
2307 value /= float(new_x[j].prefix_math());
2308 }
2309 skip_dimensions.push_back(i);
2310 skip_dimensions.push_back(j);
2311 break;
2312 }
2313 }
2314 }
2316 for(unsigned int i = 0; i < new_x.size(); i++)
2317 {
2318 bool skip = false;
2319 for(unsigned int j = 0; j < skip_dimensions.size(); j++)
2320 {
2321 if (i == skip_dimensions[j])
2322 {
2323 skip = true;
2324 break;
2325 }
2326 }
2327 if (!skip)
2328 {
2329 new_dimensions.push_back(new_x[i]);
2330 }
2331 }
2332 return new_dimensions;
2333 }
2334
2336 {
2337 return u_isalpha(x) || x == UChar32(U'Ω') || x == UChar32(U'Å') || x == UChar32(U'θ') || x == UChar32(U'°');
2338 }
2339
2340 bool common_dimension(const dimension& x,const dimension& y)
2341 {
2342 for (const dimension& x_dimension : x.get_base_dimensions())
2343 {
2344 for (const dimension& y_dimension : y.get_base_dimensions())
2345 {
2346 if (x_dimension.dimension_type == y_dimension.dimension_type and x_dimension.dimension_position == y_dimension.dimension_position)
2347 {
2348 return true;
2349 }
2350 }
2351 }
2352 return false;
2353 }
2354
2361
2363 {
2366 if (x_base_dimensions.size() == y_base_dimensions.size())
2367 {
2368 if (x_base_dimensions.size() == 0)
2369 {
2370 return true;
2371 }
2374 {
2375 bool is_equal = false;
2376 for (unsigned int j = 0; j < y_base_dimensions.size(); j++)
2377 {
2378 bool skip_j = false;
2379 if (skip.size() > 0)
2380 {
2381 for (unsigned int k = 0; k < skip.size(); k++)
2382 {
2383 if (j == skip[k])
2384 {
2385 skip_j = true;
2386 }
2387 }
2388 }
2389 if (skip_j)
2390 {
2391 continue;
2392 }
2393 if (x_dimension.dimension_type == y_base_dimensions[j].dimension_type and x_dimension.dimension_position == y_base_dimensions[j].dimension_position)
2394 {
2395 skip.push_back(j);
2396 is_equal = true;
2397 break;
2398 }
2399 }
2400 if (!is_equal)
2401 {
2402 return false;
2403 }
2404 }
2405 return true;
2406 }
2407 else
2408 {
2409 return false;
2410 }
2411 }
2412
2414 {
2416 if (x.size() == y.size())
2417 {
2418 for (const dimension& x_dimension: x)
2419 {
2420 bool is_equal = false;
2421 for (unsigned int j = 0; j < y.size(); j++)
2422 {
2423 bool skip_j = false;
2424 if (skip.size() > 0)
2425 {
2426 for (unsigned int k = 0; k < skip.size(); k++)
2427 {
2428 if (j == skip[k])
2429 {
2430 skip_j = true;
2431 }
2432 }
2433 }
2434 if (skip_j)
2435 {
2436 continue;
2437 }
2438 if (x_dimension == y[j])
2439 {
2440 skip.push_back(j);
2441 is_equal = true;
2442 break;
2443 }
2444 }
2445 if (!is_equal)
2446 {
2447 return false;
2448 }
2449 }
2450 return true;
2451 }
2452 else
2453 {
2454 return false;
2455 }
2456 }
2457}
2458
2460{
2462 {
2463 return true;
2464 }
2465 else
2466 {
2467 return false;
2468 }
2469}
2470
2472{
2473 return !(x == y);
2474}
2475
2476ostream& operator <<(ostream& os, const scifir::dimension& x)
2477{
2478 return os << x.prefix.get_symbol() << x.get_symbol();
2479}
Class that represents dimensions of the SI system of units. Each dimension sizes 6 bytes,...
Definition dimension.hpp:31
bool is_dimensionless() const
If the dimension_type is DEGREE, RADIAN or STERADIAN, it's considered dimensionless,...
position
Represents the position of the dimension, which can be at the numerator or at the denominator....
Definition dimension.hpp:38
@ DENOMINATOR
The dimension is at the denominator.
Definition dimension.hpp:38
@ NUMERATOR
The dimension is at the numerator.
Definition dimension.hpp:38
dimension & operator=(const dimension &x)
Copy assignment. The dimension copies the dimension x.
string get_fullplural() const
Returns the plural of the dimension with the name of the prefix first.
bool is_composite_dimension() const
If the dimension has more simple dimensions, it's a composite dimension.
string get_name() const
Returns the name of the dimension.
scifir::prefix prefix
The prefix of the dimension. It's used along with the symbol of the dimension when printing it.
Definition dimension.hpp:74
dimension::position dimension_position
The position of the dimension, which can be the NUMERATOR, the DENOMINATOR or NO_POSITION....
Definition dimension.hpp:76
bool is_base_dimension() const
Returns true if the dimension is a base dimension, which includes all base dimensions of the SI syste...
char symbol[3]
The value of the position of the character of a custom dimension in the map of full_symbols.
Definition dimension.hpp:77
string get_fullname() const
Returns the name of the dimension with the name of the prefix first.
bool is_SI_derived_dimension() const
If the dimension is not a SI base dimension, it's considered a SI derived dimension.
static int total_full_symbols
dimension::type dimension_type
The type of the dimension.
Definition dimension.hpp:75
static map< string, vector< dimension > > base_dimensions
bool is_SI_base_dimension() const
Returns true if the dimension is a SI base dimension. Following the SI system of units,...
bool is_simple_dimension() const
If the dimension doesn't has more base dimensions, it's a simple dimension.
type
Represents a dimension of the SI system of units. All the dimensions of the SI system of units are su...
Definition dimension.hpp:34
@ MOLARITY
Molarity, plural molarities. The derived dimensions are mol / L. Dimension of concentration of a chem...
Definition dimension.hpp:35
@ NONE
No dimension. Default value for the default constructor.
Definition dimension.hpp:35
@ BECQUEREL
Becquerel, plural becquerels. The derived dimensions are 1 / s. Dimension of radioactivity....
Definition dimension.hpp:35
@ KATAL
Katal, plural katals. The derived dimensions are mol / s. Dimension of catalytic activity....
Definition dimension.hpp:35
@ LITRE
Litre, plural litres. The derived dimensions are dm3. Dimension of volume. Symbol L.
Definition dimension.hpp:35
@ LUMEN
Lumen, plural lumens. The derived dimensions are cd * sr Dimension of luminous flux....
Definition dimension.hpp:35
@ MEMO
Memo, plural memos. Invented unit inside Scifir, it's not part of the SI system of units....
Definition dimension.hpp:35
@ STERADIAN
Steradian, plural steradians. Dimension of solid angle. A solid angle is an angle in volume....
Definition dimension.hpp:35
@ TESLA
Tesla, plural teslas. The derived dimensions are V * s / m2. Dimension of magnetic strength....
Definition dimension.hpp:35
@ INTERNATIONAL_UNIT
International unit, plural international units. It measures the amount of effect or biological activi...
Definition dimension.hpp:35
@ BARN
Barn, plural barns. Dimension of area. The derived dimensions are 10^-28 m2. It's used inside nuclear...
Definition dimension.hpp:35
@ LIGHT_YEAR
Light year, plural light years. Dimension of length. The derived dimensions are 9,...
Definition dimension.hpp:35
@ HENRY
Henry, plural henries. The derived dimensions are V * s / A. Dimension of electric inductance....
Definition dimension.hpp:35
@ AMPERE
Ampere, plural amperes. The derived dimensions are C / s. Dimension of electric current....
Definition dimension.hpp:35
@ MOLE
Mole, plural moles. SI dimension of quantity. Symbol mol.
Definition dimension.hpp:35
@ CUSTOM_FULL_SYMBOL
Custom dimension. It's identical to a CUSTOM dimension in his use, but its symbol is stored in the st...
Definition dimension.hpp:35
@ VOLT
Volt, plural volts. The derived dimensions are J / C, W / A. Dimension of voltage....
Definition dimension.hpp:35
@ OHM
Ohm, plural ohms. The derived dimensions are V / A. Dimension of electric resistance....
Definition dimension.hpp:35
@ COULOMB
Coulomb, plural coulombs. SI dimension of charge. Special name. Symbol C.
Definition dimension.hpp:35
@ LUX
Lux, plural luxes. The derived dimensions are cd * sr / m2. Dimension of illuminance....
Definition dimension.hpp:35
@ GRAY
Gray, plural grays. The derived dimensions are m2 / s2. Dimension of ionising radiation (absorbed dos...
Definition dimension.hpp:35
@ ANGSTROM
Ángstrom, plural angstroms. The derived dimensions are 10^-10 m. Dimension of length,...
Definition dimension.hpp:35
@ ELECTRON_VOLT
Electron volt, plural electron volts. The derived dimensions are 1.602176634 * 10^−19 J....
Definition dimension.hpp:35
@ GRAM
Gram, plural grams. SI dimension of mass. Symbol g.
Definition dimension.hpp:35
@ SIEVERT
Sievert, plural sieverts. The derived dimensions are J / kg. Dimension of ionising radiation (equival...
Definition dimension.hpp:35
@ DALTON
Dalton, plural daltons. The derived dimensions are 1,66053886 * 10^-24. Dimension of mass....
Definition dimension.hpp:35
@ MILLIEQUIVALENT
Milliequivalent, plural Milliequivalents. Amount of moles in a given chemical reaction needed to reac...
Definition dimension.hpp:35
@ CELSIUS
Celsius, plural celsius. SI dimension of temperature, derived from kelvin. Symbol °C....
Definition dimension.hpp:35
@ DEGREE
Degree, plural degrees. Dimension of angle. Symbol θ.
Definition dimension.hpp:35
@ PASCAL
Pascal, plural pascals. The derived dimensions are kg / s2 * m. Dimension of pressure....
Definition dimension.hpp:35
@ PIXEL
Pixel, plural pixels. it represents the amount of pixels, it can be used as a replacemet of the metre...
Definition dimension.hpp:35
@ ATOMIC_MASS_UNIT
Atomic mass unit, plural atomic mass units. The derived dimensions are Da. Equivalent to the Dalton....
Definition dimension.hpp:35
@ ASTRONOMICAL_UNIT
Astronomical unit, plural astronomical units. Dimension of length. The derived dimensions are 149,...
Definition dimension.hpp:35
@ HERTZ
Hertz, plural hertz. The derived dimensions are 1 / s. Dimension of frequency. Special name....
Definition dimension.hpp:35
@ DAY
Day, plural days. The derived dimensions are 86,400 s. Dimension of time. Symbol day,...
Definition dimension.hpp:35
@ WATT
Watt, plural watts. The derived dimensions are kg * m2 / s3. Dimension of power. Special name....
Definition dimension.hpp:35
@ NEWTON
Newton, plural newtons. The derived dimensions are kg * m / s2. Dimension of force....
Definition dimension.hpp:35
@ HOUR
Hour, plural hours. The derived dimensions are 3,600 s. Dimension of time. Symbol hour,...
Definition dimension.hpp:35
@ PARTICLES
Total of particles, the total amount that the mole represents. It's not exactly a dimension,...
Definition dimension.hpp:35
@ MONEY
Money, plural money. The money is not specified in a specific currency, you must use the ISO 4217 of ...
Definition dimension.hpp:35
@ BIT
Bit, plural bits. Dimension of amount of information, of each binary digit. Symbol bit.
Definition dimension.hpp:35
@ SECOND
Second, plural seconds. SI dimension of time. Symbol s.
Definition dimension.hpp:35
@ MINUTE
Minute, plural minutes. The derived dimensions are 60 s. Dimension of time. Symbol min.
Definition dimension.hpp:35
@ CANDELA
Candela, plural candelas. SI dimension of luminous intensity. Symbol cd.
Definition dimension.hpp:35
@ RADIAN
Radian, plural radians. Dimension of angle. Special name. Symbol rad.
Definition dimension.hpp:35
@ BYTE
Byte, plural bytes. Dimension of amount of information. Symbol B.
Definition dimension.hpp:35
@ SIEMENS
Siemens, plural siemens. The derived dimensions are 1 / Ω. Dimension of electric conductance....
Definition dimension.hpp:35
@ JOULE
Joule, plural joules. The derived dimensions are kg * m2 / s2. Dimension of energy....
Definition dimension.hpp:35
@ FARAD
Farad, plural farads. The derived dimensions are A * s / V. Dimension of electric capacitance....
Definition dimension.hpp:35
@ WEBER
Weber, plural webers. The derived dimensions are T * m2. Dimension of magnetic flux....
Definition dimension.hpp:35
@ KELVIN
Kelvin, plural kelvins. SI dimension of temperature. Symbol K.
Definition dimension.hpp:35
@ METRE
Meter, plural meters. SI dimension of length. Symbol m.
Definition dimension.hpp:35
@ PARSEC
Parsec, plural parsecs. Dimension of length. The derived dimensions are 3.2616 ly....
Definition dimension.hpp:35
@ CUSTOM
Custom dimension. It means the dimension is a custom dimension, which can have any value and meaning,...
Definition dimension.hpp:35
string get_symbol() const
Returns the symbol of the dimension. In the case of a custom dimension, it returns the custom dimensi...
string get_plural() const
Returns the plural of the dimension.
static set< string > prefixes_options
vector< dimension > get_base_dimensions() const
Returns the base dimensions of the dimensions, which can be the same dimension or all the base dimens...
long double get_conversion_factor() const
Returns the conversion factor of the dimension.
static map< int, string > full_symbols
bool is_derived_dimension() const
If the dimension is not a base dimension, it's considered a derived dimension.
static string get_full_symbol(const char *x_symbol)
Returns the symbol of a custom_full_symbol dimension stored in the private static map dimension::full...
dimension()
Default constructor. The dimension_type is NONE, the dimension_position is NO_POSITION,...
Definition dimension.cpp:27
long double prefix_math() const
Returns the math between the prefix and the dimension, which varies if the dimension is a B or anothe...
void invert()
Changes the position of the dimension to the reverse, from the NUMERATOR to the DENOMINATOR,...
static char * create_full_symbol(const string &full_symbol)
Creates a new dimension that's stored in the private static map dimension::full_symbols.
Definition dimension.hpp:87
Class that represents prefixes of the SI system of units. Each prefix sizes 1 byte....
Definition prefix.hpp:14
prefix()
Default constructor. The prefix_type is set to NONE.
Definition prefix.cpp:9
string get_symbol() const
Symbol of the prefix given the prefix_type. The symbol of micro is supported in his Unicode version.
Definition prefix.cpp:152
string get_name() const
Name of the prefix given the prefix_type.
Definition prefix.cpp:94
type
Represents a prefix of the SI system of units. All the prefixes of the SI system of units are support...
Definition prefix.hpp:16
@ NONE
There is no prefix. Then, the dimension is not increased or decreased by some factor.
Definition prefix.hpp:16
@ KILO
Prefix of a factor of 10^3.
Definition prefix.hpp:16
bool operator!=(const scifir::dimension &x, const scifir::dimension &y)
Checks if the dimension type and the position of two dimensions are any of them different....
ostream & operator<<(ostream &os, const scifir::dimension &x)
Adds the string representation of a dimension to an output stream.
bool operator==(const scifir::dimension &x, const scifir::dimension &y)
Checks if the dimension type, the position and the prefix of two dimensions are the same.
The namespace scifir contains all scifir-units, excepting the string literals, which are outside.
Definition address.cpp:6
bool equal_dimensions(const string &init_dimensions_x, const string &init_dimensions_y)
Checks if two initialization strings of dimensions initialize the same basic dimensions.
vector< dimension > divide_dimensions(vector< dimension > x, const vector< dimension > &y, long double &value)
Divides the first vector of dimensions with the other. The result is normalized after,...
@ NONE
No predefined astronomical body selected.
bool equal_dimensions_and_prefixes(const vector< dimension > &x, const vector< dimension > &y)
Checks if the base dimensions of two vectors of dimensions are equal, and if they have also the same ...
bool common_dimension(const dimension &x, const dimension &y)
Checks if there's an equal basic dimension between the basic dimensions of those two dimensions.
vector< dimension > normalize_dimensions(const vector< dimension > &x)
Normalizes the dimensions, which means that repited dimensions at the numerator and at the denominato...
string to_string(const aid &x)
Creates a string representation of aid, it's for aid equivalent to the display() function of aid.
Definition aid.cpp:582
vector< dimension > create_base_dimensions(const string &init_dimensions)
Creates the base dimensions from an initialization string of dimensions.
bool is_dimension_char(const UChar32 &x)
const long double AVOGADRO_CONSTANT
Definition constants.hpp:15
string to_latex(const vector< dimension > &x_dimensions, bool with_brackets)
vector< dimension > multiply_dimensions(const vector< dimension > &x, const vector< dimension > &y)
Multiplies two vectors of dimensions. The result is normalized after, which means that equal dimensio...
vector< dimension > square_dimensions(vector< dimension > x, int index, long double &value)
Squares a vector of dimensions by an index. The value is updated too related to the prefix math and t...
vector< dimension > create_dimensions(string init_dimensions)
Creates the dimensions from an initialization string of dimensions.
vector< dimension > power_dimensions(const vector< dimension > &x, int exponent)
Powers the dimensions by an exponent.