g4tools  5.4.0
Macros | Functions
geom File Reference
#include "mesh"
Include dependency graph for geom:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define tools_glutess_geom
 
#define VertEq(u, v)   ((u)->s == (v)->s && (u)->t == (v)->t)
 
#define VertLeq(u, v)   (((u)->s < (v)->s) || ((u)->s == (v)->s && (u)->t <= (v)->t))
 
#define EdgeEval(u, v, w)   __gl_edgeEval(u,v,w)
 
#define EdgeSign(u, v, w)   __gl_edgeSign(u,v,w)
 
#define TransLeq(u, v)
 
#define TransEval(u, v, w)   __gl_transEval(u,v,w)
 
#define TransSign(u, v, w)   __gl_transSign(u,v,w)
 
#define EdgeGoesLeft(e)   VertLeq( (e)->Dst, (e)->Org )
 
#define EdgeGoesRight(e)   VertLeq( (e)->Org, (e)->Dst )
 
#define VertL1dist(u, v)   (GLU_ABS(u->s - v->s) + GLU_ABS(u->t - v->t))
 
#define VertCCW(u, v, w)   __gl_vertCCW(u,v,w)
 
#define Interpolate(a, x, b, y)
 
#define Swap(a, b)   do { GLUvertex *t = a; a = b; b = t; } while(false)
 

Functions

int __gl_vertLeq (GLUvertex *u, GLUvertex *v)
 inlined C code : /////////////////////////////////// More...
 
GLUdouble __gl_edgeEval (GLUvertex *u, GLUvertex *v, GLUvertex *w)
 
GLUdouble __gl_edgeSign (GLUvertex *u, GLUvertex *v, GLUvertex *w)
 
GLUdouble __gl_transEval (GLUvertex *u, GLUvertex *v, GLUvertex *w)
 
GLUdouble __gl_transSign (GLUvertex *u, GLUvertex *v, GLUvertex *w)
 
int __gl_vertCCW (GLUvertex *u, GLUvertex *v, GLUvertex *w)
 
void __gl_edgeIntersect (GLUvertex *o1, GLUvertex *d1, GLUvertex *o2, GLUvertex *d2, GLUvertex *v)
 

Macro Definition Documentation

◆ EdgeEval

#define EdgeEval (   u,
  v,
 
)    __gl_edgeEval(u,v,w)

Definition at line 11 of file geom.

◆ EdgeGoesLeft

#define EdgeGoesLeft (   e)    VertLeq( (e)->Dst, (e)->Org )

Definition at line 22 of file geom.

◆ EdgeGoesRight

#define EdgeGoesRight (   e)    VertLeq( (e)->Org, (e)->Dst )

Definition at line 23 of file geom.

◆ EdgeSign

#define EdgeSign (   u,
  v,
 
)    __gl_edgeSign(u,v,w)

Definition at line 12 of file geom.

◆ Interpolate

#define Interpolate (   a,
  x,
  b,
 
)
Value:
(a = (a < 0) ? 0 : a, b = (b < 0) ? 0 : b, \
((a <= b) ? ((b == 0) ? ((x+y) / 2) \
: (x + (y-x) * (a/(a+b)))) \
: (y + (x-y) * (b/(a+b)))))

Definition at line 169 of file geom.

◆ Swap

#define Swap (   a,
 
)    do { GLUvertex *t = a; a = b; b = t; } while(false)

Definition at line 176 of file geom.

◆ tools_glutess_geom

#define tools_glutess_geom

Definition at line 4 of file geom.

◆ TransEval

#define TransEval (   u,
  v,
 
)    __gl_transEval(u,v,w)

Definition at line 18 of file geom.

◆ TransLeq

#define TransLeq (   u,
 
)
Value:
(((u)->t < (v)->t) || \
((u)->t == (v)->t && (u)->s <= (v)->s))

Definition at line 16 of file geom.

◆ TransSign

#define TransSign (   u,
  v,
 
)    __gl_transSign(u,v,w)

Definition at line 19 of file geom.

◆ VertCCW

#define VertCCW (   u,
  v,
 
)    __gl_vertCCW(u,v,w)

Definition at line 27 of file geom.

◆ VertEq

#define VertEq (   u,
 
)    ((u)->s == (v)->s && (u)->t == (v)->t)

Definition at line 8 of file geom.

◆ VertL1dist

#define VertL1dist (   u,
 
)    (GLU_ABS(u->s - v->s) + GLU_ABS(u->t - v->t))

Definition at line 25 of file geom.

◆ VertLeq

#define VertLeq (   u,
 
)    (((u)->s < (v)->s) || ((u)->s == (v)->s && (u)->t <= (v)->t))

Definition at line 9 of file geom.

Function Documentation

◆ __gl_edgeEval()

GLUdouble __gl_edgeEval ( GLUvertex u,
GLUvertex v,
GLUvertex w 
)
inline

Definition at line 40 of file geom.

41 {
42  /* Given three vertices u,v,w such that VertLeq(u,v) && VertLeq(v,w),
43  * evaluates the t-coord of the edge uw at the s-coord of the vertex v.
44  * Returns v->t - (uw)(v->s), ie. the signed distance from uw to v.
45  * If uw is vertical (and thus passes thru v), the result is zero.
46  *
47  * The calculation is extremely accurate and stable, even when v
48  * is very close to u or w. In particular if we set v->t = 0 and
49  * let r be the negated result (this evaluates (uw)(v->s)), then
50  * r is guaranteed to satisfy MIN(u->t,w->t) <= r <= MAX(u->t,w->t).
51  */
52  GLUdouble gapL, gapR;
53 
54  assert( VertLeq( u, v ) && VertLeq( v, w ));
55 
56  gapL = v->s - u->s;
57  gapR = w->s - v->s;
58 
59  if( gapL + gapR > 0 ) {
60  if( gapL < gapR ) {
61  return (v->t - u->t) + (u->t - w->t) * (gapL / (gapL + gapR));
62  } else {
63  return (v->t - w->t) + (w->t - u->t) * (gapR / (gapL + gapR));
64  }
65  }
66  /* vertical line */
67  return 0;
68 }

◆ __gl_edgeIntersect()

void __gl_edgeIntersect ( GLUvertex o1,
GLUvertex d1,
GLUvertex o2,
GLUvertex d2,
GLUvertex v 
)
inline

Definition at line 178 of file geom.

185 {
186  GLUdouble z1, z2;
187 
188  /* This is certainly not the most efficient way to find the intersection
189  * of two line segments, but it is very numerically stable.
190  *
191  * Strategy: find the two middle vertices in the VertLeq ordering,
192  * and interpolate the intersection s-value from these. Then repeat
193  * using the TransLeq ordering to find the intersection t-value.
194  */
195 
196  if( ! VertLeq( o1, d1 )) { Swap( o1, d1 ); }
197  if( ! VertLeq( o2, d2 )) { Swap( o2, d2 ); }
198  if( ! VertLeq( o1, o2 )) { Swap( o1, o2 ); Swap( d1, d2 ); }
199 
200  if( ! VertLeq( o2, d1 )) {
201  /* Technically, no intersection -- do our best */
202  v->s = (o2->s + d1->s) / 2;
203  } else if( VertLeq( d1, d2 )) {
204  /* Interpolate between o2 and d1 */
205  z1 = EdgeEval( o1, o2, d1 );
206  z2 = EdgeEval( o2, d1, d2 );
207  if( z1+z2 < 0 ) { z1 = -z1; z2 = -z2; }
208  v->s = Interpolate( z1, o2->s, z2, d1->s );
209  } else {
210  /* Interpolate between o2 and d2 */
211  z1 = EdgeSign( o1, o2, d1 );
212  z2 = -EdgeSign( o1, d2, d1 );
213  if( z1+z2 < 0 ) { z1 = -z1; z2 = -z2; }
214  v->s = Interpolate( z1, o2->s, z2, d2->s );
215  }
216 
217  /* Now repeat the process for t */
218 
219  if( ! TransLeq( o1, d1 )) { Swap( o1, d1 ); }
220  if( ! TransLeq( o2, d2 )) { Swap( o2, d2 ); }
221  if( ! TransLeq( o1, o2 )) { Swap( o1, o2 ); Swap( d1, d2 ); }
222 
223  if( ! TransLeq( o2, d1 )) {
224  /* Technically, no intersection -- do our best */
225  v->t = (o2->t + d1->t) / 2;
226  } else if( TransLeq( d1, d2 )) {
227  /* Interpolate between o2 and d1 */
228  z1 = TransEval( o1, o2, d1 );
229  z2 = TransEval( o2, d1, d2 );
230  if( z1+z2 < 0 ) { z1 = -z1; z2 = -z2; }
231  v->t = Interpolate( z1, o2->t, z2, d1->t );
232  } else {
233  /* Interpolate between o2 and d2 */
234  z1 = TransSign( o1, o2, d1 );
235  z2 = -TransSign( o1, d2, d1 );
236  if( z1+z2 < 0 ) { z1 = -z1; z2 = -z2; }
237  v->t = Interpolate( z1, o2->t, z2, d2->t );
238  }
239 }

◆ __gl_edgeSign()

GLUdouble __gl_edgeSign ( GLUvertex u,
GLUvertex v,
GLUvertex w 
)
inline

Definition at line 70 of file geom.

71 {
72  /* Returns a number whose sign matches EdgeEval(u,v,w) but which
73  * is cheaper to evaluate. Returns > 0, == 0 , or < 0
74  * as v is above, on, or below the edge uw.
75  */
76  GLUdouble gapL, gapR;
77 
78  /*
79 #define VertLeq(u,v) (((u)->s < (v)->s) || \
80  ((u)->s == (v)->s && (u)->t <= (v)->t))
81  */
82  assert( VertLeq( u, v ) && VertLeq( v, w ));
83 
84  gapL = v->s - u->s;
85  gapR = w->s - v->s;
86 
87  if( gapL + gapR > 0 ) {
88  return (v->t - w->t) * gapL + (v->t - u->t) * gapR;
89  }
90  /* vertical line */
91  return 0;
92 }

◆ __gl_transEval()

GLUdouble __gl_transEval ( GLUvertex u,
GLUvertex v,
GLUvertex w 
)
inline

Definition at line 99 of file geom.

100 {
101  /* Given three vertices u,v,w such that TransLeq(u,v) && TransLeq(v,w),
102  * evaluates the t-coord of the edge uw at the s-coord of the vertex v.
103  * Returns v->s - (uw)(v->t), ie. the signed distance from uw to v.
104  * If uw is vertical (and thus passes thru v), the result is zero.
105  *
106  * The calculation is extremely accurate and stable, even when v
107  * is very close to u or w. In particular if we set v->s = 0 and
108  * let r be the negated result (this evaluates (uw)(v->t)), then
109  * r is guaranteed to satisfy MIN(u->s,w->s) <= r <= MAX(u->s,w->s).
110  */
111  GLUdouble gapL, gapR;
112 
113  assert( TransLeq( u, v ) && TransLeq( v, w ));
114 
115  gapL = v->t - u->t;
116  gapR = w->t - v->t;
117 
118  if( gapL + gapR > 0 ) {
119  if( gapL < gapR ) {
120  return (v->s - u->s) + (u->s - w->s) * (gapL / (gapL + gapR));
121  } else {
122  return (v->s - w->s) + (w->s - u->s) * (gapR / (gapL + gapR));
123  }
124  }
125  /* vertical line */
126  return 0;
127 }

◆ __gl_transSign()

GLUdouble __gl_transSign ( GLUvertex u,
GLUvertex v,
GLUvertex w 
)
inline

Definition at line 129 of file geom.

130 {
131  /* Returns a number whose sign matches TransEval(u,v,w) but which
132  * is cheaper to evaluate. Returns > 0, == 0 , or < 0
133  * as v is above, on, or below the edge uw.
134  */
135  GLUdouble gapL, gapR;
136 
137  assert( TransLeq( u, v ) && TransLeq( v, w ));
138 
139  gapL = v->t - u->t;
140  gapR = w->t - v->t;
141 
142  if( gapL + gapR > 0 ) {
143  return (v->s - w->s) * gapL + (v->s - u->s) * gapR;
144  }
145  /* vertical line */
146  return 0;
147 }

◆ __gl_vertCCW()

int __gl_vertCCW ( GLUvertex u,
GLUvertex v,
GLUvertex w 
)
inline

Definition at line 150 of file geom.

151 {
152  /* For almost-degenerate situations, the results are not reliable.
153  * Unless the floating-point arithmetic can be performed without
154  * rounding errors, *any* implementation will give incorrect results
155  * on some degenerate inputs, so the client must have some way to
156  * handle this situation.
157  */
158  return (u->s*(v->t - w->t) + v->s*(w->t - u->t) + w->s*(u->t - v->t)) >= 0;
159 }

◆ __gl_vertLeq()

int __gl_vertLeq ( GLUvertex u,
GLUvertex v 
)
inline

inlined C code : ///////////////////////////////////

Definition at line 33 of file geom.

34 {
35  /* Returns TOOLS_GLU_TRUE if u is lexicographically <= v. */
36 
37  return VertLeq( u, v );
38 }
GLUvertex::s
GLUdouble s
Definition: mesh:90
GLUdouble
double GLUdouble
Definition: _glu:16
EdgeEval
#define EdgeEval(u, v, w)
Definition: geom:11
EdgeSign
#define EdgeSign(u, v, w)
Definition: geom:12
Interpolate
#define Interpolate(a, x, b, y)
Definition: geom:169
GLUvertex::t
GLUdouble t
Definition: mesh:90
TransLeq
#define TransLeq(u, v)
Definition: geom:16
TransEval
#define TransEval(u, v, w)
Definition: geom:18
VertLeq
#define VertLeq(u, v)
Definition: geom:9
Swap
#define Swap(a, b)
Definition: geom:176
TransSign
#define TransSign(u, v, w)
Definition: geom:19