File: identify_solution_type.c

package info (click to toggle)
snappea 3.0d3-20.1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 5,896 kB
  • ctags: 3,582
  • sloc: ansic: 33,469; sh: 8,293; python: 7,623; makefile: 240
file content (195 lines) | stat: -rw-r--r-- 4,278 bytes parent folder | download | duplicates (12)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
/*
 *	identify_solution_type.c
 *
 *	This file provides the function
 *
 *		void identify_solution_type(Triangulation *manifold);
 *
 *	which identifies the type of solution contained in the
 *	tet->shape[filled] structures of the Tetrahedra of Triangulation *manifold,
 *	and writes the result to manifold->solution_type[filled].  Possible
 *	values are given by the SolutionType enum (see SnapPea.h).
 *
 *	Its subroutine
 *
 *		Boolean solution_is_degenerate(Triangulation *manifold);
 *
 *	Is also available within the kernel, so do_Dehn_filling() can tell
 *	whether it is converging towards a degenerate structure.
 */

#include "kernel.h"

/*
 *	A solution must have volume at least VOLUME_EPSILON to count
 *	as a positive volume solution.  Otherwise the volume will be
 *	considered zero or negative.
 */
 
#define VOLUME_EPSILON		1e-2


/*
 *	DEGENERACY_EPSILON defines how close a tetrahedron shape must
 *	be to zero to count as zero.  It is given in logarithmic form.
 *	E.g., if DEGENERACY_EPSILON is -6, then the tetrahedron shape
 *	(in rectangular form) must lie within a distance exp(-6) = 0.0024...
 *	of the origin.
 */

#define DEGENERACY_EPSILON	-6


/*
 *	A solution is considered flat iff it's not degenerate and the
 *	argument of each edge parameter is within FLAT_EPSILON of 0.0 or PI.
 */

#define FLAT_EPSILON		1e-2


static Boolean	solution_is_flat(Triangulation *manifold);
static Boolean	solution_is_geometric(Triangulation *manifold);


void identify_solution_type(
	Triangulation	*manifold)
{
	if (solution_is_degenerate(manifold))
	{
		manifold->solution_type[filled] = degenerate_solution;
		return;
	}

	if (solution_is_flat(manifold))
	{
		manifold->solution_type[filled] = flat_solution;
		return;
	}

	if (solution_is_geometric(manifold))
	{
		manifold->solution_type[filled] = geometric_solution;
		return;
	}

	if (volume(manifold, NULL) > VOLUME_EPSILON)
	{
		manifold->solution_type[filled] = nongeometric_solution;
		return;
	}

	manifold->solution_type[filled] = other_solution;
}


Boolean solution_is_degenerate(
	Triangulation	*manifold)
{
	Tetrahedron	*tet;
	int			i;

	/*
	 *	If any complex edge parameter of any Tetrahedron is
	 *	close to zero, return TRUE.  Otherwise return FALSE.
	 *
	 *	Note that it's enough to check for shapes close to
	 *	zero:  if an edge parameter is close to one or infinity,
	 *	then some other edge parameter of the same Tetrahedron
	 *	will be close to zero.
	 */

	for (tet = manifold->tet_list_begin.next;
		 tet != &manifold->tet_list_end;
		 tet = tet->next)

		for (i = 0; i < 3; i++)

			if (tet->shape[filled]->cwl[ultimate][i].log.real < DEGENERACY_EPSILON)

				return TRUE;

	return FALSE;
}


static Boolean solution_is_flat(
	Triangulation	*manifold)
{
	Tetrahedron	*tet;
	int			i;
	double		the_angle;

	/*
	 *	If any edge parameter has angle more than FLAT_EPSILON away
	 *	from 0.0 or PI, return FALSE.  Otherwise, return TRUE.
	 */

	for (tet = manifold->tet_list_begin.next;
		 tet != &manifold->tet_list_end;
		 tet = tet->next)

		for (i = 0; i < 3; i++)
		{
			the_angle = tet->shape[filled]->cwl[ultimate][i].log.imag;

			if (fabs(the_angle)      > FLAT_EPSILON
			 && fabs(the_angle - PI) > FLAT_EPSILON)

				return FALSE;
		}

	return TRUE;
}


static Boolean solution_is_geometric(
	Triangulation	*manifold)
{
	Tetrahedron	*tet;

	/*
	 *	If any edge parameter has argument less than minus FLAT_EPSILON
	 *	or greater than PI + FLAT_EPSILON, return FALSE.
	 *	Otherwise, return TRUE.
	 *
	 *	This allows a solution with some flat tetrahedra to count as geometric.
	 *	However, if all the tetrahedra were flat, the SolutionType would have
	 *	been previously identified as flat_solution, and we wouldn't have
	 *	gotten to this function.
	 */

	for (tet = manifold->tet_list_begin.next;
		 tet != &manifold->tet_list_end;
		 tet = tet->next)

		if (tetrahedron_is_geometric(tet) == FALSE)

			return FALSE;

	return TRUE;
}


Boolean tetrahedron_is_geometric(
	Tetrahedron	*tet)
{
	int		i;
	double	the_angle;

	/*
	 *	See comments in solution_is_geometric() above.
	 */

	for (i = 0; i < 3; i++)
	{
		the_angle = tet->shape[filled]->cwl[ultimate][i].log.imag;

		if (the_angle <    - FLAT_EPSILON
		 || the_angle > PI + FLAT_EPSILON)

			return FALSE;
	}

	return TRUE;
}