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 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532
|
/*
* interface.c
*
* This file contains the following functions, which the
* user interface uses to read the fields in the Triangulation
* data structure.
*
* char *get_triangulation_name(Triangulation *manifold);
* char set_triangulation_name(Triangulation *manifold, char *new_name);
* SolutionType get_complete_solution_type(Triangulation *manifold);
* SolutionType get_filled_solution_type(Triangulation *manifold);
* int get_num_tetrahedra(Triangulation *manifold);
* Orientability get_orientability(Triangulation *manifold);
* int get_num_cusps(Triangulation *manifold);
* int get_num_or_cusps(Triangulation *manifold);
* int get_num_nonor_cusps(Triangulation *manifold);
* int get_max_singularity(Triangulation *manifold);
* int get_num_generators(Triangulation *manifold);
* void get_cusp_info( Triangulation *manifold,
* int cusp_index,
* CuspTopology *topology,
* Boolean *is_complete,
* double *m,
* double *l,
* Complex *initial_shape,
* Complex *current_shape,
* int *initial_shape_precision,
* int *current_shape_precision,
* Complex *initial_modulus,
* Complex *current_modulus);
* FuncResult set_cusp_info( Triangulation *manifold,
* int cusp_index,
* Boolean cusp_is_complete,
* double m,
* double l);
* void get_holonomy( Triangulation *manifold,
* int cusp_index,
* Complex *meridional_holonomy,
* Complex *longitudinal_holonomy,
* int *meridional_precision,
* int *longitudinal_precision);
* void get_tet_shape( Triangulation *manifold,
* int which_tet,
* Boolean fixed_alignment,
* double *shape_rect_real,
* double *shape_rect_imag,
* double *shape_log_real,
* double *shape_log_imag,
* int *precision_rect_real,
* int *precision_rect_imag,
* int *precision_log_real,
* int *precision_log_imag,
* Boolean *is_geometric);
* int get_num_edge_classes(
* Triangulation *manifold,
* int edge_class_order,
* Boolean greater_than_or_equal);
*
* The Triangulation data structure itself, as well as its
* component data structures, remain private to the kernel.
*
* These functions are documented more thoroughly in SnapPea.h.
*/
#include "kernel.h"
static int longest_side(Tetrahedron *tet);
char *get_triangulation_name(
Triangulation *manifold)
{
return manifold->name;
}
void set_triangulation_name(
Triangulation *manifold,
char *new_name)
{
/*
* Free the old name, if there is one.
*/
if (manifold->name != NULL)
my_free(manifold->name);
/*
* Allocate space for the new name . . .
*/
manifold->name = NEW_ARRAY(strlen(new_name) + 1, char);
/*
* . . . and copy it in.
*/
strcpy(manifold->name, new_name);
}
SolutionType get_complete_solution_type(
Triangulation *manifold)
{
return manifold->solution_type[complete];
}
SolutionType get_filled_solution_type(
Triangulation *manifold)
{
return manifold->solution_type[filled];
}
int get_num_tetrahedra(
Triangulation *manifold)
{
return manifold->num_tetrahedra;
}
Orientability get_orientability(
Triangulation *manifold)
{
return manifold->orientability;
}
int get_num_cusps(
Triangulation *manifold)
{
return manifold->num_cusps;
}
int get_num_or_cusps(
Triangulation *manifold)
{
return manifold->num_or_cusps;
}
int get_num_nonor_cusps(
Triangulation *manifold)
{
return manifold->num_nonor_cusps;
}
int get_max_singularity(
Triangulation *manifold)
{
Cusp *cusp;
int m,
l,
singularity,
max_singularity;
max_singularity = 1;
for ( cusp = manifold->cusp_list_begin.next;
cusp != &manifold->cusp_list_end;
cusp = cusp->next)
{
if (cusp->is_complete == FALSE)
{
m = (int) cusp->m;
l = (int) cusp->l;
if ( cusp->m == (double) m
&& cusp->l == (double) l)
{
singularity = gcd(m, l);
if (max_singularity < singularity)
max_singularity = singularity;
}
}
}
return max_singularity;
}
int get_num_generators(
Triangulation *manifold)
{
return manifold->num_generators;
}
void get_cusp_info(
Triangulation *manifold,
int cusp_index,
CuspTopology *topology,
Boolean *is_complete,
double *m,
double *l,
Complex *initial_shape,
Complex *current_shape,
int *initial_shape_precision,
int *current_shape_precision,
Complex *initial_modulus,
Complex *current_modulus)
{
Cusp *cusp;
cusp = find_cusp(manifold, cusp_index);
/*
* Write information corresponding to nonNULL pointers.
*/
if (topology != NULL)
*topology = cusp->topology;
if (is_complete != NULL)
*is_complete = cusp->is_complete;
if (m != NULL)
*m = cusp->m;
if (l != NULL)
*l = cusp->l;
if (initial_shape != NULL)
*initial_shape = cusp->cusp_shape[initial];
/* = Zero if initial hyperbolic structure is degenerate */
if (current_shape != NULL)
*current_shape = cusp->cusp_shape[current];
/* = Zero if cusp is filled or hyperbolic structure is degenerate */
if (initial_shape_precision != NULL)
*initial_shape_precision = cusp->shape_precision[initial];
/* = 0 if initial hyperbolic structure is degenerate */
if (current_shape_precision != NULL)
*current_shape_precision = cusp->shape_precision[current];
/* = 0 if cusp is filled or hyperbolic structure is degenerate */
if (initial_modulus != NULL)
{
if (cusp->shape_precision[initial] > 0)
*initial_modulus = cusp_modulus(cusp->cusp_shape[initial]);
else
*initial_modulus = Zero;
}
if (current_modulus != NULL)
{
if (cusp->shape_precision[current] > 0)
*current_modulus = cusp_modulus(cusp->cusp_shape[current]);
else
*current_modulus = Zero;
}
}
FuncResult set_cusp_info(
Triangulation *manifold,
int cusp_index,
Boolean cusp_is_complete,
double m,
double l)
{
Cusp *cusp;
cusp = find_cusp(manifold, cusp_index);
/*
* Write the given Dehn coefficients into the cusp.
*/
if (cusp_is_complete)
{
cusp->is_complete = TRUE;
cusp->m = 0.0;
cusp->l = 0.0;
}
else
{
/*
* Check the input.
*
* The comment at the top of holonomy.c explains why only
* (m,0) Dehn fillings are possible on nonorientable cusps.
*/
if (m == 0.0 && l == 0.0)
{
uAcknowledge("Can't do (0,0) Dehn filling.");
return func_bad_input;
}
if (cusp->topology == Klein_cusp && l != 0.0)
{
uAcknowledge("Only (p,0) Dehn fillings are possible on a nonorientable cusp.");
return func_bad_input;
}
/*
* Copy the input into the cusp.
*/
cusp->is_complete = FALSE;
cusp->m = m;
cusp->l = l;
}
return func_OK;
}
void get_holonomy(
Triangulation *manifold,
int cusp_index,
Complex *meridional_holonomy,
Complex *longitudinal_holonomy,
int *meridional_precision,
int *longitudinal_precision)
{
Cusp *cusp;
cusp = find_cusp(manifold, cusp_index);
if (meridional_holonomy != NULL)
*meridional_holonomy = cusp->holonomy[ultimate][M];
if (longitudinal_holonomy != NULL)
{
*longitudinal_holonomy = cusp->holonomy[ultimate][L];
/*
* Longitudes on Klein bottle cusps are stored as their
* double covers (cf. peripheral_curves.c), so we divide
* by two to compensate. (Recall that this isn't actually
* the holonomy, but the log of the holonomy, i.e. the
* complex length.)
*
* As explained at the top of holonomy.c, the holonomy
* in this case must be real, so we clear any roundoff
* error in the imaginary part.
*/
if (cusp->topology == Klein_cusp)
{
longitudinal_holonomy->real /= 2.0;
longitudinal_holonomy->imag = 0.0;
}
}
if (meridional_precision != NULL)
*meridional_precision = complex_decimal_places_of_accuracy(
cusp->holonomy[ ultimate ][M],
cusp->holonomy[penultimate][M]);
if (longitudinal_precision != NULL)
*longitudinal_precision = complex_decimal_places_of_accuracy(
cusp->holonomy[ ultimate ][L],
cusp->holonomy[penultimate][L]);
}
void get_tet_shape(
Triangulation *manifold,
int which_tet,
Boolean fixed_alignment,
double *shape_rect_real,
double *shape_rect_imag,
double *shape_log_real,
double *shape_log_imag,
int *precision_rect_real,
int *precision_rect_imag,
int *precision_log_real,
int *precision_log_imag,
Boolean *is_geometric)
{
int count,
the_coordinate_system;
Tetrahedron *tet;
ComplexWithLog *ultimate_shape,
*penultimate_shape;
/*
* If no solution is present, return all zeros.
*/
if (manifold->solution_type[filled] == not_attempted)
{
*shape_rect_real = 0.0;
*shape_rect_imag = 0.0;
*shape_log_real = 0.0;
*shape_log_imag = 0.0;
*precision_rect_real = 0;
*precision_rect_imag = 0;
*precision_log_real = 0;
*precision_log_imag = 0;
*is_geometric = FALSE;
return;
}
/*
* Check that which_tet is within bounds.
*/
if (which_tet < 0 || which_tet >= manifold->num_tetrahedra)
uFatalError("get_tet_shape", "interface");
/*
* Find the Tetrahedron in position which_tet.
*/
for (tet = manifold->tet_list_begin.next, count = 0;
tet != &manifold->tet_list_end && count != which_tet;
tet = tet->next, count++)
;
/*
* If we went all the way through the list of Tetrahedra
* without finding position which_tet, then something
* is very wrong.
*/
if (tet == &manifold->tet_list_end)
uFatalError("get_tet_shape", "interface");
/*
* If fixed_alignment is TRUE, use a fixed coordinate system.
* Otherwise choose the_coordinate_system so that the longest side
* of the triangle is the initial side of the angle.
*/
if (fixed_alignment == TRUE)
the_coordinate_system = 0;
else
the_coordinate_system = (longest_side(tet) + 1) % 3;
/*
* Note the addresses of the ultimate and penultimate shapes.
*/
ultimate_shape = &tet->shape[filled]->cwl[ ultimate ][the_coordinate_system];
penultimate_shape = &tet->shape[filled]->cwl[penultimate][the_coordinate_system];
/*
* Report the ultimate shapes.
*/
*shape_rect_real = ultimate_shape->rect.real;
*shape_rect_imag = ultimate_shape->rect.imag;
*shape_log_real = ultimate_shape->log.real;
*shape_log_imag = ultimate_shape->log.imag;
/*
* Estimate the precision.
*/
*precision_rect_real = decimal_places_of_accuracy(ultimate_shape->rect.real, penultimate_shape->rect.real);
*precision_rect_imag = decimal_places_of_accuracy(ultimate_shape->rect.imag, penultimate_shape->rect.imag);
*precision_log_real = decimal_places_of_accuracy(ultimate_shape->log.real, penultimate_shape->log.real);
*precision_log_imag = decimal_places_of_accuracy(ultimate_shape->log.imag, penultimate_shape->log.imag);
/*
* Check whether the tetrahedron is geometric.
*/
*is_geometric = tetrahedron_is_geometric(tet);
}
static int longest_side(
Tetrahedron *tet)
{
int i,
desired_index;
double sine[3],
max_sine;
/*
* longest_side() returns the index (0, 1 or 2) of the edge opposite
* the longest side of tet's triangular vertex cross section.
*
* We'll use the Law of Sines, which says that the lengths of a triangle's
* sides are proportional to the sines of the opposite angles.
*
* We take the absolute value of each sine, just in case the
* Tetrahedron is negatively oriented.
*/
for (i = 0; i < 3; i++)
sine[i] = fabs(tet->shape[filled]->cwl[ultimate][i].rect.imag) /
complex_modulus(tet->shape[filled]->cwl[ultimate][i].rect);
max_sine = -1.0;
for (i = 0; i < 3; i++)
if (sine[i] > max_sine)
{
max_sine = sine[i];
desired_index = i;
}
return desired_index;
}
int get_num_edge_classes(
Triangulation *manifold,
int edge_class_order,
Boolean greater_than_or_equal)
{
int count;
EdgeClass *edge;
count = 0;
for (edge = manifold->edge_list_begin.next;
edge != &manifold->edge_list_end;
edge = edge->next)
if ( greater_than_or_equal ?
edge->order >= edge_class_order :
edge->order == edge_class_order)
count++;
return count;
}
|