Geogram Version 1.8.5
A programming library of geometric algorithms
Loading...
Searching...
No Matches
expansion_nt.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2000-2022 Inria
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * * Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * * Neither the name of the ALICE Project-Team nor the names of its
14 * contributors may be used to endorse or promote products derived from this
15 * software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 * POSSIBILITY OF SUCH DAMAGE.
28 *
29 * Contact: Bruno Levy
30 *
31 * https://www.inria.fr/fr/bruno-levy
32 *
33 * Inria,
34 * Domaine de Voluceau,
35 * 78150 Le Chesnay - Rocquencourt
36 * FRANCE
37 *
38 */
39
40#ifndef GEOGRAM_NUMERICS_EXPANSION_NT
41#define GEOGRAM_NUMERICS_EXPANSION_NT
42
46
55namespace GEO {
56
57 class expansion_nt;
58 class rational_nt;
59
70 class GEOGRAM_API expansion_nt {
71 public:
78 UNINITIALIZED
79 };
80
85 enum Operation {
86 SUM, DIFF, PRODUCT
87 };
88
92 explicit expansion_nt(
93 UninitializedType uninitialized
94 ) : rep_(nullptr) {
95 geo_argused(uninitialized);
96 }
97
102 explicit expansion_nt(double x = 0.0) {
103 rep_ = expansion::new_expansion_on_heap(1);
104 rep()[0] = x;
105 rep().set_length(1);
106 }
107
114 explicit expansion_nt(const expansion& rhs) {
115 rep_ = expansion::new_expansion_on_heap(rhs.length());
116 rep().assign(rhs);
117 }
118
132 explicit expansion_nt(
133 Operation op, const expansion& x, const expansion& y
134 ) {
135 switch(op) {
136 case SUM:
137 rep_ = expansion::new_expansion_on_heap(
138 expansion::sum_capacity(x,y)
139 );
140 rep_->assign_sum(x,y);
141 break;
142 case DIFF:
143 rep_ = expansion::new_expansion_on_heap(
144 expansion::diff_capacity(x,y)
145 );
146 rep_->assign_diff(x,y);
147 break;
148 case PRODUCT:
149 rep_ = expansion::new_expansion_on_heap(
150 expansion::product_capacity(x,y)
151 );
152 rep_->assign_product(x,y);
153 break;
154 }
155 }
156
170 explicit expansion_nt(
171 Operation op,
172 const expansion& x, const expansion& y, const expansion& z
173 ) {
174 switch(op) {
175 case SUM:
176 rep_ = expansion::new_expansion_on_heap(
177 expansion::sum_capacity(x,y,z)
178 );
179 rep_->assign_sum(x,y,z);
180 break;
181 case DIFF:
183 break;
184 case PRODUCT:
185 rep_ = expansion::new_expansion_on_heap(
186 expansion::product_capacity(x,y,z)
187 );
188 rep_->assign_product(x,y,z);
189 break;
190 }
191 }
192
206 explicit expansion_nt(
207 Operation op,
208 const expansion& x, const expansion& y,
209 const expansion& z, const expansion& t
210 ) {
211 switch(op) {
212 case SUM:
213 rep_ = expansion::new_expansion_on_heap(
214 expansion::sum_capacity(x,y,z,t)
215 );
216 rep_->assign_sum(x,y,z,t);
217 break;
218 case DIFF:
220 break;
221 case PRODUCT:
222 const expansion& p1 = expansion_product(x,y);
223 const expansion& p2 = expansion_product(z,t);
224 rep_ = expansion::new_expansion_on_heap(
225 expansion::product_capacity(p1,p2)
226 );
227 rep_->assign_sum(p1,p2);
228 break;
229 }
230 }
231
245 explicit expansion_nt(Operation op, double x, double y) {
246 switch(op) {
247 case SUM:
248 rep_ = expansion::new_expansion_on_heap(
249 expansion::sum_capacity(x,y)
250 );
251 rep_->assign_sum(x,y);
252 break;
253 case DIFF:
254 rep_ = expansion::new_expansion_on_heap(
255 expansion::diff_capacity(x,y)
256 );
257 rep_->assign_diff(x,y);
258 break;
259 case PRODUCT:
260 rep_ = expansion::new_expansion_on_heap(
261 expansion::product_capacity(x,y)
262 );
263 rep_->assign_product(x,y);
264 break;
265 }
266 }
267
273 copy(rhs);
274 }
275
282 rep_ = nullptr;
283 std::swap(rep_, rhs.rep_);
284 }
285
291 expansion_nt& operator= (const expansion_nt& rhs) {
292 if(&rhs != this) {
293 cleanup();
294 copy(rhs);
295 }
296 return *this;
297 }
298
304 expansion_nt& operator= (expansion_nt&& rhs) {
305 if(&rhs != this) {
306 cleanup();
307 std::swap(rep_, rhs.rep_);
308 }
309 return *this;
310 }
311
318 cleanup();
319 }
320
326 void optimize() {
327 rep().optimize();
328 }
329
330 /********************************************************************/
331
337 expansion_nt& operator+= (const expansion_nt& rhs);
338
344 expansion_nt& operator-= (const expansion_nt& rhs);
345
351 expansion_nt& operator*= (const expansion_nt& rhs);
352
358 expansion_nt& operator+= (double rhs);
359
365 expansion_nt& operator-= (double rhs);
366
375 expansion_nt& operator*= (double rhs);
376
377 /********************************************************************/
378
384 expansion_nt operator+ (const expansion_nt& rhs) const;
385
392 expansion_nt operator- (const expansion_nt& rhs) const;
393
400 expansion_nt operator* (const expansion_nt& rhs) const;
401
407 expansion_nt operator+ (double rhs) const;
408
414 expansion_nt operator- (double rhs) const;
415
421 expansion_nt operator* (double rhs) const;
422
423 /********************************************************************/
424
429 expansion_nt operator- () const;
430
431 /********************************************************************/
432
437 Sign compare(const expansion_nt& rhs) const {
438 return rep().compare(rhs.rep());
439 }
440
445 Sign compare(double rhs) const {
446 return rep().compare(rhs);
447 }
448
456 bool operator> (const expansion_nt& rhs) const {
457 return (int(compare(rhs))>0);
458 }
459
467 bool operator>= (const expansion_nt& rhs) const {
468 return (int(compare(rhs))>=0);
469 }
470
478 bool operator< (const expansion_nt& rhs) const {
479 return (int(compare(rhs))<0);
480 }
481
489 bool operator<= (const expansion_nt& rhs) const {
490 return (int(compare(rhs))<=0);
491 }
492
500 bool operator> (double rhs) const {
501 return (int(compare(rhs))>0);
502 }
503
511 bool operator>= (double rhs) const {
512 return (int(compare(rhs))>=0);
513 }
514
522 bool operator< (double rhs) const {
523 return (int(compare(rhs))<0);
524 }
525
533 bool operator<= (double rhs) const {
534 return (int(compare(rhs))<=0);
535 }
536
537 /********************************************************************/
538
544 double estimate() const {
545 return rep().estimate();
546 }
547
552 Sign sign() const {
553 return rep().sign();
554 }
555
563 index_t length() const {
564 return rep().length();
565 }
566
575 double component(index_t i) const {
576 geo_debug_assert(i < length());
577 return rep()[i];
578 }
579
589 rep_(rep) {
590 }
591
601 return *rep_;
602 }
603
612 const expansion& rep() const {
613 return *rep_;
614 }
615
621 std::string to_string() const {
622 return (rep_ == nullptr) ?
623 std::string("null") :
624 rep_->to_string() ;
625 }
626
627 protected:
628
635 void copy(const expansion_nt& rhs) {
636 if(rhs.rep_ == nullptr) {
637 rep_ = nullptr;
638 } else {
639 rep_ = expansion::new_expansion_on_heap(rhs.rep().capacity());
640 rep_->set_length(rhs.rep().length());
641 for(index_t i=0; i<rep_->length(); ++i) {
642 (*rep_)[i] = rhs.rep()[i];
643 }
644 }
645 }
646
650 void cleanup() {
651 if(rep_ != nullptr) {
652 expansion::delete_expansion_on_heap(rep_);
653 rep_ = nullptr;
654 }
655 }
656
657 private:
658 expansion* rep_;
659 friend expansion_nt operator- (double a, const expansion_nt& b);
660
661 friend expansion_nt expansion_nt_sq_dist(
662 const double* a, const double* b, coord_index_t dim
663 );
664
665 friend expansion_nt expansion_nt_dot_at(
666 const double* a, const double* b, const double* c,
667 coord_index_t dim
668 );
669 friend class rational_nt;
670 };
671
679 inline expansion_nt operator+ (double a, const expansion_nt& b) {
680 return b + a;
681 }
682
690 inline expansion_nt operator- (double a, const expansion_nt& b) {
691 expansion_nt result = b - a;
692 result.rep().negate();
693 return result;
694 }
695
703 inline expansion_nt operator* (double a, const expansion_nt& b) {
704 return b * a;
705 }
706
715 inline bool operator== (const expansion_nt& a, const expansion_nt& b) {
716 return a.rep().equals(b.rep());
717 }
718
727 inline bool operator== (const expansion_nt& a, double b) {
728 return a.rep().equals(b);
729 }
730
739 inline bool operator== (double a, const expansion_nt& b) {
740 return b.rep().equals(a);
741 }
742
751 inline bool operator!= (const expansion_nt& a, const expansion_nt& b) {
752 return !a.rep().equals(b.rep());
753 }
754
763 inline bool operator!= (const expansion_nt& a, double b) {
764 return !a.rep().equals(b);
765 }
766
775 inline bool operator!= (double a, const expansion_nt& b) {
776 return !b.rep().equals(a);
777 }
778
790 const double* a, const double* b, coord_index_t dim
791 ) {
794 );
795 result->assign_sq_dist(a, b, dim);
796 return expansion_nt(result);
797 }
798
811 const double* a, const double* b, const double* c, coord_index_t dim
812 ) {
815 );
816 result->assign_dot_at(a, b, c, dim);
817 return expansion_nt(result);
818 }
819
820 /************************************************************************/
821
827 template <> inline Sign geo_sgn(const expansion_nt& x) {
828 return x.sign();
829 }
830
831 /************************************************************************/
832
840 inline bool expansion_nt_is_zero(const expansion_nt& x) {
841 return (x.sign() == GEO::ZERO);
842 }
843
851 inline bool expansion_nt_is_one(const expansion_nt& x) {
852 return x.rep().equals(1.0);
853 }
854
855
865 const expansion_nt& x, const expansion_nt& y
866 ) {
867 const expansion& diff = expansion_diff(x.rep(), y.rep());
868 return diff.sign();
869 }
870
878 expansion_nt result(
881 ))
882 );
883 result.rep().assign_square(x.rep());
884 return result;
885 }
886
887
895 const expansion_nt& a00,const expansion_nt& a01,
896 const expansion_nt& a10,const expansion_nt& a11
897 );
898
906 const expansion_nt& a00,const expansion_nt& a01,const expansion_nt& a02,
907 const expansion_nt& a10,const expansion_nt& a11,const expansion_nt& a12,
908 const expansion_nt& a20,const expansion_nt& a21,const expansion_nt& a22
909 );
910
918 const expansion_nt& a00,const expansion_nt& a01,
919 const expansion_nt& a02,const expansion_nt& a03,
920 const expansion_nt& a10,const expansion_nt& a11,
921 const expansion_nt& a12,const expansion_nt& a13,
922 const expansion_nt& a20,const expansion_nt& a21,
923 const expansion_nt& a22,const expansion_nt& a23,
924 const expansion_nt& a30,const expansion_nt& a31,
925 const expansion_nt& a32,const expansion_nt& a33
926 );
927
933 template <> inline expansion_nt det2x2(
934 const expansion_nt& a11, const expansion_nt& a12,
935 const expansion_nt& a21, const expansion_nt& a22
936 ) {
938 a11,a12,
939 a21,a22
940 );
941 }
942
948 template <> inline expansion_nt det3x3(
949 const expansion_nt& a11, const expansion_nt& a12,
950 const expansion_nt& a13,
951 const expansion_nt& a21, const expansion_nt& a22,
952 const expansion_nt& a23,
953 const expansion_nt& a31, const expansion_nt& a32,
954 const expansion_nt& a33
955 ) {
957 a11,a12,a13,
958 a21,a22,a23,
959 a31,a32,a33
960 );
961 }
962
968 template <> inline expansion_nt det4x4(
969 const expansion_nt& a11, const expansion_nt& a12,
970 const expansion_nt& a13, const expansion_nt& a14,
971 const expansion_nt& a21, const expansion_nt& a22,
972 const expansion_nt& a23, const expansion_nt& a24,
973 const expansion_nt& a31, const expansion_nt& a32,
974 const expansion_nt& a33, const expansion_nt& a34,
975 const expansion_nt& a41, const expansion_nt& a42,
976 const expansion_nt& a43, const expansion_nt& a44
977 ) {
979 a11,a12,a13,a14,
980 a21,a22,a23,a24,
981 a31,a32,a33,a34,
982 a41,a42,a43,a44
983 );
984 }
985
986
987 /************************************************************************/
988}
989
996inline std::ostream& operator<< (
997 std::ostream& os, const GEO::expansion_nt& a
998) {
999 return os << a.estimate();
1000}
1001
1009inline std::istream& operator>> ( std::istream& is, GEO::expansion_nt& a) {
1010 double d;
1011 is >> d;
1012 if (is) {
1013 a = GEO::expansion_nt(d);
1014 }
1015 return is;
1016}
1017
1018/*****************************************************************************/
1019
1020namespace GEO {
1021
1030 class GEOGRAM_API rational_nt {
1031 public:
1032
1039 UNINITIALIZED
1040 };
1041
1045 explicit rational_nt(UninitializedType uninitialized) :
1046 num_(expansion_nt::UNINITIALIZED),
1047 denom_(expansion_nt::UNINITIALIZED) {
1048 geo_argused(uninitialized);
1049 }
1050
1051
1056 explicit rational_nt(double x = 0.0) : num_(x), denom_(1.0) {
1057 }
1058
1063 explicit rational_nt(const expansion_nt& x) : num_(x), denom_(1.0) {
1064 }
1065
1071 explicit rational_nt(expansion_nt&& x) : num_(x), denom_(1.0) {
1072 }
1073
1079 explicit rational_nt(double num, double denom)
1080 : num_(num), denom_(denom) {
1081 }
1082
1088 explicit rational_nt(const expansion_nt& num, const expansion_nt& denom)
1089 : num_(num), denom_(denom) {
1090 }
1091
1098 explicit rational_nt(
1099 expansion_nt&& num, expansion_nt&& denom
1100 ) : num_(num), denom_(denom) {
1101 }
1102
1108 copy(rhs);
1109 }
1110
1116 num_(rhs.num_),
1117 denom_(rhs.denom_) {
1118 }
1119
1125 rational_nt& operator= (const rational_nt& rhs) {
1126 num_ = rhs.num_;
1127 denom_ = rhs.denom_;
1128 return *this;
1129 }
1130
1136 rational_nt& operator= (rational_nt&& rhs) {
1137 num_ = rhs.num_;
1138 denom_ = rhs.denom_;
1139 return *this;
1140 }
1141
1146 const expansion_nt& num() const {
1147 return num_;
1148 }
1149
1154 const expansion_nt& denom() const {
1155 return denom_;
1156 }
1157
1163 return num_;
1164 }
1165
1171 return denom_;
1172 }
1173
1179 void optimize() {
1180 num().optimize();
1181 denom().optimize();
1182 }
1183
1184 /********************************************************************/
1185
1191 rational_nt& operator+= (const rational_nt& rhs) {
1192 if(has_same_denom(rhs)) {
1193 num_ += rhs.num_;
1194 } else {
1195 num_ = num_ * rhs.denom_ + rhs.num_ * denom_;
1196 denom_ *= rhs.denom_;
1197 }
1198 return *this;
1199 }
1200
1206 rational_nt& operator-= (const rational_nt& rhs) {
1207 if(has_same_denom(rhs)) {
1208 num_ -= rhs.num_;
1209 } else {
1210 num_ = num_ * rhs.denom_ - rhs.num_ * denom_;
1211 denom_ *= rhs.denom_;
1212 }
1213 return *this;
1214 }
1215
1221 rational_nt& operator*= (const rational_nt& rhs) {
1222 num_ *= rhs.num_;
1223 denom_ *= rhs.denom_;
1224 return *this;
1225 }
1226
1232 rational_nt& operator/= (const rational_nt& rhs) {
1233 num_ *= rhs.denom_;
1234 denom_ *= rhs.num_;
1235 return *this;
1236 }
1237
1243 rational_nt& operator+= (double rhs) {
1244 num_ += denom_ * rhs;
1245 return *this;
1246 }
1247
1253 rational_nt& operator-= (double rhs) {
1254 num_ -= denom_ * rhs;
1255 return *this;
1256 }
1257
1266 rational_nt& operator*= (double rhs) {
1267 num_ *= rhs;
1268 return *this;
1269 }
1270
1279 rational_nt& operator/= (double rhs) {
1280 denom_ *= rhs;
1281 return *this;
1282 }
1283
1284 /********************************************************************/
1285
1291 rational_nt operator+ (const rational_nt& rhs) const {
1292 if(has_same_denom(rhs)) {
1293 return rational_nt(
1294 num_ + rhs.num_,
1295 denom_
1296 );
1297 }
1298 return rational_nt(
1299 num_ * rhs.denom_ + rhs.num_ * denom_,
1300 denom_ * rhs.denom_
1301 );
1302 }
1303
1310 rational_nt operator- (const rational_nt& rhs) const {
1311 if(has_same_denom(rhs)) {
1312 return rational_nt(
1313 num_ - rhs.num_,
1314 denom_
1315 );
1316 }
1317 return rational_nt(
1318 num_ * rhs.denom_ - rhs.num_ * denom_,
1319 denom_ * rhs.denom_
1320 );
1321 }
1322
1329 rational_nt operator* (const rational_nt& rhs) const {
1330 return rational_nt(
1331 num_ * rhs.num_,
1332 denom_ * rhs.denom_
1333 );
1334 }
1335
1342 rational_nt operator/ (const rational_nt& rhs) const {
1343 return rational_nt(
1344 num_ * rhs.denom_,
1345 denom_ * rhs.num_
1346 );
1347 }
1348
1349
1355 rational_nt operator+ (double rhs) const {
1356 return rational_nt(
1357 num_ + rhs * denom_,
1358 denom_
1359 );
1360 }
1361
1367 rational_nt operator- (double rhs) const {
1368 return rational_nt(
1369 num_ - rhs * denom_,
1370 denom_
1371 );
1372 }
1373
1379 rational_nt operator* (double rhs) const {
1380 return rational_nt(
1381 num_ *rhs,
1382 denom_
1383 );
1384 }
1385
1391 rational_nt operator/ (double rhs) const {
1392 return rational_nt(
1393 num_,
1394 denom_*rhs
1395 );
1396 }
1397
1398 /********************************************************************/
1399
1404 rational_nt operator- () const {
1405 return rational_nt(
1406 -num_,
1407 denom_
1408 );
1409 }
1410
1411 /********************************************************************/
1412
1417 Sign compare(const rational_nt& rhs) const;
1418
1423 Sign compare(double rhs) const;
1424
1432 bool operator> (const rational_nt& rhs) const {
1433 return (int(compare(rhs))>0);
1434 }
1435
1443 bool operator>= (const rational_nt& rhs) const {
1444 return (int(compare(rhs))>=0);
1445 }
1446
1454 bool operator< (const rational_nt& rhs) const {
1455 return (int(compare(rhs))<0);
1456 }
1457
1465 bool operator<= (const rational_nt& rhs) const {
1466 return (int(compare(rhs))<=0);
1467 }
1468
1476 bool operator> (double rhs) const {
1477 return (int(compare(rhs))>0);
1478 }
1479
1487 bool operator>= (double rhs) const {
1488 return (int(compare(rhs))>=0);
1489 }
1490
1498 bool operator< (double rhs) const {
1499 return (int(compare(rhs))<0);
1500 }
1501
1509 bool operator<= (double rhs) const {
1510 return (int(compare(rhs))<=0);
1511 }
1512
1513 /********************************************************************/
1514
1520 double estimate() const {
1521 return num_.estimate() / denom_.estimate();
1522 }
1523
1528 Sign sign() const {
1529 geo_debug_assert(denom_.sign() != ZERO);
1530 return Sign(num_.sign() * denom_.sign());
1531 }
1532
1533 protected:
1538 void copy(const rational_nt& rhs) {
1539 num_ = rhs.num_;
1540 denom_ = rhs.denom_;
1541 }
1542
1553 bool has_same_denom(const rational_nt& rhs) const {
1554 return denom_ == rhs.denom_;
1555 }
1556
1557 private:
1558 expansion_nt num_;
1559 expansion_nt denom_;
1560 };
1561
1562 /**************************************************************************/
1563
1571 inline rational_nt operator+ (double a, const rational_nt& b) {
1572 return b + a;
1573 }
1574
1582 inline rational_nt operator- (double a, const rational_nt& b) {
1583 rational_nt result = b - a;
1584 result.num().rep().negate();
1585 return result;
1586 }
1587
1595 inline rational_nt operator* (double a, const rational_nt& b) {
1596 return b * a;
1597 }
1598
1606 inline rational_nt operator/ (double a, const rational_nt& b) {
1607 return rational_nt(
1608 a*b.denom(),
1609 b.num()
1610 );
1611 }
1612
1621 inline bool operator== (const rational_nt& a, const rational_nt& b) {
1622 return (a.compare(b) == ZERO);
1623 }
1624
1633 inline bool operator== (const rational_nt& a, double b) {
1634 return (a.compare(b) == ZERO);
1635 }
1636
1645 inline bool operator== (double a, const rational_nt& b) {
1646 return (b.compare(a) == ZERO);
1647 }
1648
1657 inline bool operator!= (const rational_nt& a, const rational_nt& b) {
1658 return (a.compare(b) != ZERO);
1659 }
1660
1669 inline bool operator!= (const rational_nt& a, double b) {
1670 return (a.compare(b) != ZERO);
1671 }
1672
1681 inline bool operator!= (double a, const rational_nt& b) {
1682 return (b.compare(a) != ZERO);
1683 }
1684
1685 /**************************************************************************/
1686
1692 template <> inline Sign geo_sgn(const rational_nt& x) {
1693 return x.sign();
1694 }
1695
1696 /**************************************************************************/
1697
1698}
1699
1700#endif
#define geo_assert_not_reached
Sets a non reachable point in the program.
Definition assert.h:177
#define geo_debug_assert(x)
Verifies that a condition is met.
Definition assert.h:195
Common include file, providing basic definitions. Should be included before anything else by all head...
Expansion_nt (expansion Number Type) is used to compute the sign of polynoms exactly.
expansion_nt(double x=0.0)
Constructs a new expansion_nt from a double.
const expansion & rep() const
Gets the internal expansion that represents this expansion_nt.
double estimate() const
Computes an approximation of the stored value in this expansion.
void copy(const expansion_nt &rhs)
Copies an expansion into this one.
Sign sign() const
Gets the sign of this expansion_nt.
expansion & rep()
Gets the internal expansion that represents this expansion_nt.
expansion_nt expansion_nt_sq_dist(const double *a, const double *b, coord_index_t dim)
Computes an expansion that represents the square distance between two points.
double component(index_t i) const
Gets the i-th component of this expansion.
~expansion_nt()
Expansion_nt destructor.
std::string to_string() const
Gets a string representation of this expansion.
expansion_nt expansion_nt_dot_at(const double *a, const double *b, const double *c, coord_index_t dim)
Computes an expansion that represents the dot product of two vectors determined by three points.
expansion_nt(expansion_nt &&rhs)
Move-constructor.
expansion_nt(UninitializedType uninitialized)
Constructs an uninitialized expansion_nt.
expansion_nt(Operation op, const expansion &x, const expansion &y, const expansion &z)
Constructs a new expansion_nt from three expansions.
UninitializedType
This type is used to overload expression_nt constructors with a version that does not create an expan...
expansion_nt(const expansion &rhs)
Constructs a new expansion_nt from an expansion.
void cleanup()
Cleanups the memory associated with this expansion_nt.
index_t length() const
Gets the length of this expansion.
void optimize()
Optimizes the internal representation without changing the represented value.
expansion_nt(Operation op, const expansion &x, const expansion &y)
Constructs a new expansion_nt from two expansions.
Sign compare(const expansion_nt &rhs) const
Compares two expansion_nt.
expansion_nt(expansion *rep)
Constructs a new expansion_nt from an expansion.
expansion_nt(Operation op, double x, double y)
Constructs a new expansion_nt from two doubles.
expansion_nt(Operation op, const expansion &x, const expansion &y, const expansion &z, const expansion &t)
Constructs a new expansion_nt from four expansions.
Operation
This type is used by the constructor that takes two expansion.
expansion_nt(const expansion_nt &rhs)
Copy-constructor.
Sign compare(double rhs) const
Compares an expansion_nt with a double.
Represents numbers in arbitrary precision with a low-level API.
index_t length() const
Gets the length of this expansion.
bool equals(const expansion &rhs) const
Compares two expansions.
index_t capacity() const
Gets the capacity of this expansion.
expansion & assign_dot_at(const double *p1, const double *p2, const double *p0, coord_index_t dim)
Assigns the dot product of two vectors to this expansion (should not be used by client code).
static index_t sq_dist_capacity(coord_index_t dim)
Computes the required capacity of an expansion to store the exact squared distance between two points...
expansion & negate()
Changes the sign of an expansion.
static index_t square_capacity(double a)
Computes the required capacity of an expansion to store the exact square of a double.
static index_t dot_at_capacity(coord_index_t dim)
Computes the required capacity of an expansion to store the exact dot product between two vectors.
static expansion * new_expansion_on_heap(index_t capa)
Allocates an expansion on the heap.
expansion & assign_square(double a)
Assigns the square of a double to this expansion (should not be used by client code).
expansion & assign_sq_dist(const double *p1, const double *p2, coord_index_t dim)
Assigns the squared distance between two points to this expansion (should not be used by client code)...
Sign sign() const
Gets the sign of the expansion.
Rational_nt (rational Number Type) is used to compute the sign of rational fractions exactly.
expansion_nt & num()
gets the numerator.
Sign compare(const rational_nt &rhs) const
Compares two rational_nt.
rational_nt(double num, double denom)
Constructs a new rational_nt from two doubles.
rational_nt(const expansion_nt &x)
Constructs a new rational_nt from an expansion_nt.
void copy(const rational_nt &rhs)
Copies a rational into this one.
rational_nt(const rational_nt &rhs)
Copy-constructor.
rational_nt(expansion_nt &&x)
Constructs a new rational_nt from an expansion_nt with move semantics.
double estimate() const
Computes an approximation of the stored value in this rational.
rational_nt(rational_nt &&rhs)
Move-constructor.
expansion_nt & denom()
gets the denominator.
const expansion_nt & denom() const
gets the denominator.
const expansion_nt & num() const
gets the numerator.
UninitializedType
This type is used to overload expression_nt constructors with a version that does not create an expan...
void optimize()
Optimizes the internal representation without changing the represented value.
Sign sign() const
Gets the sign of this rational_nt.
rational_nt(UninitializedType uninitialized)
Constructs an uninitialized rational_nt.
Sign compare(double rhs) const
Compares a rational_nt with a double.
rational_nt(const expansion_nt &num, const expansion_nt &denom)
Constructs a new rational_nt from two expansion_nt.
bool has_same_denom(const rational_nt &rhs) const
Tests whether a rational_nt has trivially the same denominator as this rational_nt.
rational_nt(double x=0.0)
Constructs a new rational_nt from a double.
rational_nt(expansion_nt &&num, expansion_nt &&denom)
Constructs a new rational_nt from two expansion_nt with move semantics.
std::ostream & operator<<(std::ostream &os, const GEO::expansion_nt &a)
Displays the approximated value of an expansion_nt to a stream.
std::istream & operator>>(std::istream &is, GEO::expansion_nt &a)
Reads a double precision number from a stream and converts it to an approximation.
Generic matrix type.
Implementation of multi-precision arithmetics.
Global Vorpaline namespace.
Definition algorithm.h:64
bool expansion_nt_is_zero(const expansion_nt &x)
Tests whether an expansion_nt is zero.
Quaternion operator-(const Quaternion &a, const Quaternion &b)
Computes the difference between two Quaternion.
Definition quaternion.h:252
void geo_argused(const T &)
Suppresses compiler warnings about unused parameters.
Definition argused.h:60
expansion_nt expansion_nt_determinant(const expansion_nt &a00, const expansion_nt &a01, const expansion_nt &a10, const expansion_nt &a11)
Computes a 2x2 determinant.
T det3x3(const T &a11, const T &a12, const T &a13, const T &a21, const T &a22, const T &a23, const T &a31, const T &a32, const T &a33)
Computes a three-by-three determinant.
Definition determinant.h:69
T det4x4(const T &a11, const T &a12, const T &a13, const T &a14, const T &a21, const T &a22, const T &a23, const T &a24, const T &a31, const T &a32, const T &a33, const T &a34, const T &a41, const T &a42, const T &a43, const T &a44)
Computes a four-by-four determinant.
Definition determinant.h:85
Sign geo_sgn(const T &x)
Gets the sign of a value.
Definition numeric.h:246
expansion_nt expansion_nt_square(const expansion_nt &x)
Computes the square of an expansion_nt.
geo_index_t index_t
The type for storing and manipulating indices.
Definition numeric.h:287
Sign expansion_nt_compare(const expansion_nt &x, const expansion_nt &y)
Compares two expansion_nt.
Sign
Integer constants that represent the sign of a value.
Definition numeric.h:224
@ ZERO
Definition numeric.h:228
T det2x2(const T &a11, const T &a12, const T &a21, const T &a22)
Computes a two-by-two determinant.
Definition determinant.h:58
bool expansion_nt_is_one(const expansion_nt &x)
Tests whether an expansion_nt is equal to one.
Quaternion operator+(const Quaternion &a, const Quaternion &b)
Computes the sum of two Quaternion.
Definition quaternion.h:239
vecng< DIM, FT > operator*(const Matrix< DIM, FT > &M, const vecng< DIM, FT > &x)
Computes a matrix vector product.
Definition matrix.h:516
geo_coord_index_t coord_index_t
The type for storing coordinate indices, and iterating on the coordinates of a point.
Definition numeric.h:321