OpenLexocad  27.1
GeometricTools.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <Geom/Dir.h>
4 #include <Geom/Pln.h>
5 #include <Geom/Pnt.h>
6 #include <Geom/Vec2d.h>
7 #include <Geom/XYZ.h>
8 
9 #include <iostream>
10 #include <vector>
11 
12 
13 namespace Geom
14 {
15 class LX_GEOM_EXPORT GeometricTools
16 {
17 public:
18  GeometricTools(void);
19  ~GeometricTools(void);
20 
22  static Geom::Dir getFaceNormal(const COORDS& face);
23  static Geom::Dir getFaceNormal(const std::vector<Geom::Pnt>& face);
24 
26  static Geom::Dir getNFaceNormal(const std::vector<Geom::Pnt>& face);
27  static Geom::Dir getNFaceNormal(const COORDS& face);
28  // Newell's method without exceptions
29  static bool getNFaceNormalNoExc(const std::vector<Geom::Pnt>& face, Geom::Dir& dir);
30 
36  static Geom::Dir getConcaveFaceNormalXY(const std::vector<Geom::Pnt>& face);
37 
38  static bool getNonColinearEdges(const COORDS& face, Geom::Vec& edge1, Geom::Vec& edge2);
39  static int savePoint(const Geom::XYZ& p, COORDS& points);
40  static bool isEqual(double d1, double d2, double tolerance = 1E-06);
41  static bool isEqual(const Geom::XYZ& v1, const Geom::XYZ& v2, double tolerance = 1E-06);
42  static bool isEqual(const Geom::Dir& d1, const Geom::Dir& d2, double tolerance = 1E-06);
43  static bool isEqual(const Geom::Vec& v1, const Geom::Vec& v2, double tolerance = 1E-06);
44  static bool isEqual(const Geom::Pnt& p1, const Geom::Pnt& p2, double tolerance = 1E-06);
45  static double roundValue(double value, double roundValue);
46 #ifndef LXAPI // NOT PART OF THE LEXOCAD API (FOR LXSDK AND SWIG)
47  static float roundfValue(float value, float roundValue);
48 #endif
49  static double round(double value, int digits);
50  static double roundValueOffset(const double& coord, const double& valueToRound, const double& roundToValue);
51  static bool isEven(const int Value) { return Value % 2 == 0; }
52  static bool isOdd(const int Value) { return Value % 2 == 1; }
53  static int factorial(int x) { return x > 1 ? x * factorial(x - 1) : 1; }
54  static bool getMedianPlaneFromPoints(const std::vector<Geom::Pnt>& points, Geom::Pln& pln);
55 
56 private:
57  static bool _calculateNonColinearEdges(const COORDS& face, Geom::Vec& edge1, Geom::Vec& edge2);
58  static Geom::Dir _getNewellNormal(const COORDS& face);
59  static bool _getPredominantEdgesDirXY(const COORDS& face, Geom::Dir& normal);
60 
61  // To get the face normal
62  static int _checkFaceCounter;
63  static unsigned int _checkEdgeIndex;
64 };
65 
66 } // namespace Geom
67 
68 
69  LX_GEOM_EXPORT std::ostream& operator<<(std::ostream& o, const Geom::Vec& vec);
70  LX_GEOM_EXPORT std::ostream& operator<<(std::ostream& o, const Geom::Dir& dir);
71  LX_GEOM_EXPORT std::ostream& operator<<(std::ostream& o, const Geom::Pln& dir);
72  LX_GEOM_EXPORT std::ostream& operator<<(std::ostream& o, const Geom::Pnt& pnt);
73  LX_GEOM_EXPORT std::ostream& operator<<(std::ostream& o, const Geom::Vec2d& pnt);
74  LX_GEOM_EXPORT std::ostream& operator<<(std::ostream& o, const Geom::XYZ& xyz);
75  LX_GEOM_EXPORT std::ostream& operator<<(std::ostream& o, const Geom::Ax2& placement);
76  LX_GEOM_EXPORT std::ostream& operator<<(std::ostream& o, const Geom::Trsf& t);
Definition: Variant.h:60
Definition: Pln.h:57
Defines a non-persistent 3D Cartesian point.
Definition: Pnt.h:43
Definition: GeometricTools.h:15
std::vector< Geom::XYZ > COORDS
Definition: XYZ.h:32
static bool isEven(const int Value)
Definition: GeometricTools.h:51
Definition: Ax2.h:67
Definition: XYZ.h:43
Definition: Trsf.h:57
Definition: Dir.h:45
static int factorial(int x)
Definition: GeometricTools.h:53
Defines a non-persistent vector in 2D space.
Definition: Vec2d.h:34
static bool isOdd(const int Value)
Definition: GeometricTools.h:52
Defines a non-persistent vector in 3D space.
Definition: Vec.h:44
LX_GEOM_EXPORT std::ostream & operator<<(std::ostream &o, const Geom::Vec &vec)