Line data Source code
1 : // Copyright (c) 2021 Made to Order Software Corp. All Rights Reserved
2 : //
3 : // https://snapwebsites.org/project/ftmesh
4 : // contact@m2osw.com
5 : //
6 : // This program is free software; you can redistribute it and/or modify
7 : // it under the terms of the GNU General Public License as published by
8 : // the Free Software Foundation; either version 2 of the License, or
9 : // (at your option) any later version.
10 : //
11 : // This program is distributed in the hope that it will be useful,
12 : // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 : // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 : // GNU General Public License for more details.
15 : //
16 : // You should have received a copy of the GNU General Public License along
17 : // with this program; if not, write to the Free Software Foundation, Inc.,
18 : // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 : #pragma once
20 :
21 : /** \file
22 : * \brief Definitions of the ftpoint class.
23 : *
24 : * Define a (x, y, z) point with some operation.
25 : *
26 : * The type is defined such that it can be used with the glut directly.
27 : * i.e. we have an array of three doubles named f_coordinates.
28 : *
29 : * \note
30 : * We also verify that the double type is what GLdouble is but here we
31 : * do not want to leak any OpenGL header file.
32 : */
33 :
34 :
35 : // C++ lib
36 : //
37 : #include <cmath>
38 : #include <cstring>
39 : #include <memory>
40 : #include <vector>
41 :
42 :
43 :
44 : namespace ftmesh
45 : {
46 :
47 :
48 :
49 : struct point
50 : {
51 : typedef std::shared_ptr<point> pointer_t;
52 : typedef std::vector<point> vector_t;
53 : typedef std::vector<pointer_t> safe_vector_t; // "safe" as in the points do not move in memory
54 :
55 12 : point()
56 12 : {
57 12 : }
58 :
59 2257 : point(double x, double y)
60 2257 : {
61 2257 : f_coordinates[0] = x;
62 2257 : f_coordinates[1] = y;
63 2257 : }
64 :
65 2374 : point(double x, double y, double z)
66 2374 : {
67 2374 : f_coordinates[0] = x;
68 2374 : f_coordinates[1] = y;
69 2374 : f_coordinates[2] = z;
70 2374 : }
71 :
72 : point(point const & rhs) = default;
73 :
74 : point & operator = (point const & rhs) = default;
75 :
76 702 : bool operator != (point const & rhs) const
77 : {
78 702 : return std::memcmp(f_coordinates, rhs.f_coordinates, sizeof(f_coordinates)) != 0;
79 : }
80 :
81 754 : point operator + (point const & rhs) const
82 : {
83 754 : return point(x() + rhs.x(), y() + rhs.y(), z() + rhs.z());
84 : }
85 :
86 170 : point operator - (point const & rhs) const
87 : {
88 170 : return point(x() - rhs.x(), y() - rhs.y(), z() - rhs.z());
89 : }
90 :
91 1450 : point operator * (double scale) const
92 : {
93 1450 : return point(x() * scale, y() * scale, z() * scale);
94 : }
95 :
96 170 : double angle() const
97 : {
98 170 : return atan2(y(), x());
99 : }
100 :
101 362 : bool is_left_of(point const & rhs) const
102 : {
103 362 : return f_coordinates[0] < rhs.f_coordinates[0];
104 : }
105 :
106 5542 : double x() const
107 : {
108 5542 : return f_coordinates[0];
109 : }
110 :
111 6114 : double y() const
112 : {
113 6114 : return f_coordinates[1];
114 : }
115 :
116 3298 : double z() const
117 : {
118 3298 : return f_coordinates[2];
119 : }
120 :
121 : // WARNING: we use an array of GLdouble so we are 100% compatible with
122 : // the GLU tesselation which requires those are vertices; we
123 : // verify that GLdouble is double (see )
124 : //
125 : double f_coordinates[3] = {};
126 : };
127 :
128 :
129 :
130 : } // namespace ftmesh
131 : // vim: ts=4 sw=4 et
132 :
|