repo_name
stringlengths
5
122
path
stringlengths
3
232
text
stringlengths
6
1.05M
chpublichp/masspred
tools/region_filter-0.19/work_disembl.c
#include "main.h" _FUNCTION_DECLARATION_BEGIN_ void work_disembl(profile_t* profile, int position) _FUNCTION_DECLARATION_END_ { char* name; float treshold; row_t row; int row_number; char aa; float probability[3]; region_t region; int region_start; int region_end; switch(position) { case 1: name = "DisEMBL_Loops/coils"; treshold = 0.43; break; case 2: name = "DisEMBL_Remark-465"; treshold = 0.5; break; case 3: name = "DisEMBL_Hot-loops"; treshold = 0.086; break; default: return; } region = REGION_UNKNOWN; row_number = 1; while(fgets(row, MAX_ROW_SIZE, profile->input) != NULL) if(sscanf(row, " %c %f %f %f %*s", &aa, &probability[0], &probability[1], &probability[2]) == 4) { if(profile->numeric == TRUE) if(probability[position-1] <= treshold) dump_numeric_o(profile, name, row_number, aa, probability[position-1]); else dump_numeric_d(profile, name, row_number, aa, probability[position-1]); else { if(probability[position-1] <= treshold) { if(region == REGION_D) dump_plain_d(profile, name, region_start, region_end); if(region != REGION_O) region_start = row_number; region = REGION_O; } else { if(region == REGION_O) dump_plain_o(profile, name, region_start, region_end); if(region != REGION_D) region_start = row_number; region = REGION_D; } region_end = row_number; } row_number++; } if(profile->numeric != TRUE) switch(region) { case REGION_O: dump_plain_o(profile, name, region_start, region_end); break; case REGION_D: dump_plain_d(profile, name, region_start, region_end); break; } }
chpublichp/masspred
tools/epitope_fail-0.12/epitope_fail.c
<reponame>chpublichp/masspred<filename>tools/epitope_fail-0.12/epitope_fail.c<gh_stars>0 #include <limits.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #define DEFAULT_OUTPUT_FILE_PREFIX "ef_fail_out" #define DEFAULT_OUTPUT_FILE_NAME_SQL_SUFFIX "sql" #define DEFAULT_OUTPUT_FILE_NAME_LOAD_SUFFIX "load" #define DEFAULT_ALLELE "" #define DEFAULT_LENGTH "" #define DEFAULT_PROTEIN_ID "" #define DEFAULT_PROTEIN_REFERENCE "" #define DEFAULT_PROTEIN_FILE_NAME "" typedef enum boolean_t { FALSE = 0, TRUE = 1 } boolean_t; typedef enum model_t { MODEL_NETMHC30C, MODEL_NETMHC34A, MODEL_NETMHCII22, MODEL_NETMHCPAN20C, MODEL_NETMHCPAN24A, MODEL_NETMHCPAN28A, MODEL_NETMHCIIPAN10B, MODEL_NETMHCIIPAN20B, MODEL_NETMHCIIPAN30C, MODEL_NETMHCIIPAN31A, MODEL_UNKNOWN } model_t; #define MAX_ROW_SIZE 1024 typedef char row_t[MAX_ROW_SIZE+1]; #define ERROR(format, ...) \ do \ { \ fprintf(stderr, "Error: " format "\n", ##__VA_ARGS__); \ exit(EXIT_FAILURE); \ } \ while(FALSE) \ FILE* open_sql_file(char* output_file_prefix) { char name[PATH_MAX]; FILE* file; snprintf(name, PATH_MAX, "%s.%s", output_file_prefix, DEFAULT_OUTPUT_FILE_NAME_SQL_SUFFIX); file = fopen(name, "a"); if(file == NULL) ERROR("Cannot create output file \'%s\'", name); return file; } FILE* open_load_file(char* output_file_prefix) { char name[PATH_MAX]; FILE* file; snprintf(name, PATH_MAX, "%s.%s", output_file_prefix, DEFAULT_OUTPUT_FILE_NAME_LOAD_SUFFIX); file = fopen(name, "a"); if(file == NULL) ERROR("Cannot create output file \'%s\'", name); return file; } void dump ( FILE* output_sql, FILE* output_load, char* name, char* allele, char* length, char* protein_id, char* protein_reference, char* protein_file_name ) { if(output_sql != NULL) { fprintf ( output_sql, "INSERT INTO epitope_fail(protein_id, protein_reference, protein_file_name, type, allele, length) VALUES(\'%s\', \'%s\', \'%s\', \'%s\', \'%s\', \'%s\');\n", protein_id, protein_reference, protein_file_name, name, allele, length ); fflush(output_sql); } fprintf ( output_load, "%s\t%s\t%s\t%s\t%s\t%s\n", protein_id, protein_reference, protein_file_name, name, allele, length ); fflush(output_load); } void usage(char* name) { fprintf ( stderr, "Usage: %s [-h] -m model [-s] [-o output_file_prefix] [-p protein_id] [-r protein_reference] [-f protein_file_name]\n" " -h\tHelp\n" " -m\tModel:\n" "\t\'1-3.0c\' for netMHC-3.0c\n" "\t\'1-3.4a\' for netMHC-3.4a\n" "\t\'2-2.2\' for netMHCII-2.2\n" "\t\'pan_1-2.0c\' for netMHCpan-2.0c\n" "\t\'pan_1-2.4a\' for netMHCpan-2.4a\n" "\t\'pan_1-2.8a\' for netMHCpan-2.8a\n" "\t\'pan_2-1.0b\' for netMHCIIpan-1.0b\n" "\t\'pan_2-2.0b\' for netMHCIIpan-2.0b\n" "\t\'pan_2-3.0c\' for netMHCIIpan-3.0c\n" "\t\'pan_2-3.1a\' for netMHCIIpan-3.1a\n" " -s\tGenerate SQL\n" " -o\tOutput file prefix (default \'%s\')\n" " -a\tAllele (default \'%s\')\n" " -l\tLenth (default \'%s\')\n" " -p\tProtein ID (default \'%s\')\n" " -r\tProtein reference (default \'%s\')\n" " -f\tProtein file name (default \'%s\')\n", name, DEFAULT_OUTPUT_FILE_PREFIX, DEFAULT_ALLELE, DEFAULT_LENGTH, DEFAULT_PROTEIN_ID, DEFAULT_PROTEIN_REFERENCE, DEFAULT_PROTEIN_FILE_NAME ); exit(EXIT_FAILURE); } int main(int arguments_number, char* arguments_values[]) { int option; model_t model; boolean_t generate_sql; char* output_file_prefix; char* allele; char* length; char* protein_id; char* protein_reference; char* protein_file_name; char* input_file_name; FILE* output_sql; FILE* output_load; model = MODEL_UNKNOWN; generate_sql = FALSE; output_file_prefix = DEFAULT_OUTPUT_FILE_PREFIX; allele = DEFAULT_ALLELE; length = DEFAULT_LENGTH; protein_id = DEFAULT_PROTEIN_ID; protein_reference = DEFAULT_PROTEIN_REFERENCE; protein_file_name = DEFAULT_PROTEIN_FILE_NAME; opterr = 0; while(TRUE) { option = getopt(arguments_number, arguments_values, "hm:so:a:l:p:r:f:"); if(option == -1) break; switch(option) { case 'h': usage(arguments_values[0]); break; case 'm': if(strcasecmp(optarg, "1-3.0c") == 0) model = MODEL_NETMHC30C; else if(strcasecmp(optarg, "1-3.4a") == 0) model = MODEL_NETMHC34A; else if(strcasecmp(optarg, "2-2.2") == 0) model = MODEL_NETMHCII22; else if(strcasecmp(optarg, "pan_1-2.0c") == 0) model = MODEL_NETMHCPAN20C; else if(strcasecmp(optarg, "pan_1-2.4a") == 0) model = MODEL_NETMHCPAN24A; else if(strcasecmp(optarg, "pan_1-2.8a") == 0) model = MODEL_NETMHCPAN28A; else if(strcasecmp(optarg, "pan_2-1.0b") == 0) model = MODEL_NETMHCIIPAN10B; else if(strcasecmp(optarg, "pan_2-2.0b") == 0) model = MODEL_NETMHCIIPAN20B; else if(strcasecmp(optarg, "pan_2-3.0c") == 0) model = MODEL_NETMHCIIPAN30C; else if(strcasecmp(optarg, "pan_2-3.1a") == 0) model = MODEL_NETMHCIIPAN30C; break; case 's': generate_sql = TRUE; break; case 'o': output_file_prefix = optarg; break; case 'a': allele = optarg; break; case 'l': length = optarg; break; case 'p': protein_id = optarg; break; case 'r': protein_reference = optarg; break; case 'f': protein_file_name = optarg; break; default: usage(arguments_values[0]); } } if(optind != arguments_number) usage(arguments_values[0]); if(model == MODEL_UNKNOWN) usage(arguments_values[0]); if(generate_sql == TRUE) output_sql = open_sql_file(output_file_prefix); else output_sql = NULL; output_load = open_load_file(output_file_prefix); switch(model) { case MODEL_NETMHC30C: dump ( output_sql, output_load, "netmhc-3.0c", allele, length, protein_id, protein_reference, protein_file_name ); break; case MODEL_NETMHC34A: dump ( output_sql, output_load, "netmhc-3.0c", allele, length, protein_id, protein_reference, protein_file_name ); break; case MODEL_NETMHCII22: dump ( output_sql, output_load, "netmhcii-2.2", allele, length, protein_id, protein_reference, protein_file_name ); break; case MODEL_NETMHCPAN20C: dump ( output_sql, output_load, "netmhcpan-2.0c", allele, length, protein_id, protein_reference, protein_file_name ); break; case MODEL_NETMHCPAN24A: dump ( output_sql, output_load, "netmhcpan-2.4a", allele, length, protein_id, protein_reference, protein_file_name ); break; case MODEL_NETMHCPAN28A: dump ( output_sql, output_load, "netmhcpan-2.8a", allele, length, protein_id, protein_reference, protein_file_name ); break; case MODEL_NETMHCIIPAN10B: dump ( output_sql, output_load, "netmhciipan-1.0b", allele, length, protein_id, protein_reference, protein_file_name ); break; case MODEL_NETMHCIIPAN20B: dump ( output_sql, output_load, "netmhciipan-2.0b", allele, length, protein_id, protein_reference, protein_file_name ); break; case MODEL_NETMHCIIPAN30C: dump ( output_sql, output_load, "netmhciipan-3.0c", allele, length, protein_id, protein_reference, protein_file_name ); break; case MODEL_NETMHCIIPAN31A: dump ( output_sql, output_load, "netmhciipan-3.1a", allele, length, protein_id, protein_reference, protein_file_name ); break; } if(output_sql != NULL) fclose(output_sql); fclose(output_load); return EXIT_SUCCESS; }
chpublichp/masspred
tools/parjob-0.5/wait_all_children.c
<reponame>chpublichp/masspred<filename>tools/parjob-0.5/wait_all_children.c #include "main.h" void wait_all_children(job_data_t* job_data) { int i; boolean_t all_done; while(TRUE) { all_done = TRUE; for(i = 0; i < job_data->size; i++) if(job_data->children_data[i].used == TRUE) { all_done = FALSE; break; } if(all_done == TRUE) break; usleep(1000); } }
chpublichp/masspred
tools/region_filter-0.19/main.h
<filename>tools/region_filter-0.19/main.h #ifndef __MAIN__H__ #define __MAIN__H__ #include <limits.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include "default.h" #include "type.h" #include "prototype.i" #define STRING_RAW(x) #x #define STRING(x) STRING_RAW(x) #define ERROR(format, ...) \ do \ { \ fprintf(stderr, "Error: " format "\n", ##__VA_ARGS__); \ exit(EXIT_FAILURE); \ } \ while(FALSE) \ #define dump_plain_o(profile, name, start, end) dump_plain(profile, name, start, end, REGION_ORDER_STRING) #define dump_plain_d(profile, name, start, end) dump_plain(profile, name, start, end, REGION_DISORDER_STRING) #define dump_numeric_o(profile, name, position, lettet, value) dump_numeric(profile, name, position, lettet, value, REGION_ORDER_STRING) #define dump_numeric_d(profile, name, position, lettet, value) dump_numeric(profile, name, position, lettet, value, REGION_DISORDER_STRING) #define _FUNCTION_DECLARATION_BEGIN_ #define _FUNCTION_DECLARATION_END_ #endif
chpublichp/masspred
tools/region_filter-0.19/main.c
<filename>tools/region_filter-0.19/main.c #include "main.h" static void usage(char* name) { fprintf ( stderr, "Usage: %s [-h] -m model [-s] [-n] [-o output_file_prefix] [-p protein_id] [-r protein_reference] [-f protein_file_name] [input_file]\n" " -h\t\tHelp\n" " -m\t\tModel\n" "\t\'a\' for anchor format\n" "\t\'d\' for disopred format\n" "\t\'d1\' for disopred format - svm (only for numeric)\n" "\t\'d2\' for disopred format - smooth (only for numeric)\n" "\t\'e1\' for disembl format - coils\n" "\t\'e2\' for disembl format - rem465\n" "\t\'e3\' for disembl format - hotloops\n" "\t\'il\' for iupred long format\n" "\t\'is\' for iupred short format\n" "\t\'o\' for ond format\n" "\t\'p\' for predisorder format\n" "\t\'r\' for ronn format\n" "\t\'u\' for isunstruct format\n" "\t\'v\' for vsl2 format\n" " -s\t\tGenerate SQL\n" " -n\t\tGenerate numeric format\n" " -o\t\tOutput file prefix (default \'%s\')\n" " -p\t\tProtein ID (default \'%s\')\n" " -r\t\tProtein reference (default \'%s\')\n" " -f\t\tProtein file name (default \'%s\')\n" " input_file\tInput file (default \'%s\' aka stdin)\n", name, DEFAULT_OUTPUT_FILE_PREFIX, DEFAULT_PROTEIN_ID, DEFAULT_PROTEIN_REFERENCE, DEFAULT_PROTEIN_FILE_NAME, DEFAULT_INPUT_FILE_NAME ); exit(EXIT_FAILURE); } int main(int arguments_number, char* arguments_values[]) { int option; model_t model; boolean_t generate_sql; char* output_file_prefix; char* input_file_name; profile_t profile; model = MODEL_UNKNOWN; generate_sql = FALSE; output_file_prefix = DEFAULT_OUTPUT_FILE_PREFIX; profile.numeric = FALSE; profile.protein_id = DEFAULT_PROTEIN_ID; profile.protein_reference = DEFAULT_PROTEIN_REFERENCE; profile.protein_file_name = DEFAULT_PROTEIN_FILE_NAME; input_file_name = DEFAULT_INPUT_FILE_NAME; opterr = 0; while(TRUE) { option = getopt(arguments_number, arguments_values, "hm:sno:p:r:f:"); if(option == -1) break; switch(option) { case 'h': usage(arguments_values[0]); break; case 'm': switch(optarg[0]) { case 'a': model = MODEL_ANCHOR; break; case 'd': model = MODEL_DISOPRED; switch(optarg[1]) { case '1': model = MODEL_DISOPRED_1; break; case '2': model = MODEL_DISOPRED_2; break; } break; case 'e': switch(optarg[1]) { case '1': model = MODEL_DISEMBL_1; break; case '2': model = MODEL_DISEMBL_2; break; case '3': model = MODEL_DISEMBL_3; break; } break; case 'i': switch(optarg[1]) { case 'l': model = MODEL_IUPRED_LONG; break; case 's': model = MODEL_IUPRED_SHORT; break; } break; case 'o': model = MODEL_OND; break; case 'p': model = MODEL_PREDISORDER; break; case 'r': model = MODEL_RONN; break; case 'u': model = MODEL_ISUNSTRUCT; break; case 'v': model = MODEL_VSL2; break; } break; case 's': generate_sql = TRUE; break; case 'n': profile.numeric = TRUE; break; case 'o': output_file_prefix = optarg; break; case 'p': profile.protein_id = optarg; break; case 'r': profile.protein_reference = optarg; break; case 'f': profile.protein_file_name = optarg; break; default: usage(arguments_values[0]); } } if(optind == arguments_number-1) input_file_name = arguments_values[optind]; else if(optind != arguments_number) usage(arguments_values[0]); if ( model == MODEL_UNKNOWN || ( profile.numeric == TRUE && model == MODEL_DISOPRED ) || ( profile.numeric != TRUE && ( model == MODEL_DISOPRED_1 || model == MODEL_DISOPRED_2 ) ) ) usage(arguments_values[0]); if(strcmp(input_file_name, "-") == 0) profile.input = stdin; else { profile.input = fopen(input_file_name, "r"); if(profile.input == NULL) ERROR("Cannot open input file \'%s\'", input_file_name); } if(generate_sql == TRUE) profile.output_sql = open_file(output_file_prefix, DEFAULT_OUTPUT_FILE_NAME_SQL_SUFFIX); else profile.output_sql = NULL; profile.output_load = open_file(output_file_prefix, DEFAULT_OUTPUT_FILE_NAME_LOAD_SUFFIX); switch(model) { case MODEL_ANCHOR: work_anchor(&profile); break; case MODEL_DISEMBL_1: work_disembl(&profile, 1); break; case MODEL_DISEMBL_2: work_disembl(&profile, 2); break; case MODEL_DISEMBL_3: work_disembl(&profile, 3); break; case MODEL_DISOPRED: work_disopred(&profile, 0); break; case MODEL_DISOPRED_1: work_disopred(&profile, 1); break; case MODEL_DISOPRED_2: work_disopred(&profile, 2); break; case MODEL_ISUNSTRUCT: work_isunstruct(&profile); break; case MODEL_IUPRED_LONG: work_iupred(&profile, TRUE); break; case MODEL_IUPRED_SHORT: work_iupred(&profile, FALSE); break; case MODEL_OND: work_ond(&profile); break; case MODEL_PREDISORDER: work_predisorder(&profile); break; case MODEL_RONN: work_ronn(&profile); break; case MODEL_VSL2: work_vsl2(&profile); break; } fclose(profile.input); if(profile.output_sql != NULL) fclose(profile.output_sql); fclose(profile.output_load); return EXIT_SUCCESS; }
kaizoku-oh/pio-rfid
src/app_main.c
<gh_stars>1-10 #include <string.h> #include <esp_log.h> #include <freertos/FreeRTOS.h> #include <freertos/task.h> #include <freertos/queue.h> #include "rc522.h" #include "firestore.h" #include "app_wifi.h" #include "app_time.h" #include "app_ota.h" static void _app_main_send_data(uint8_t *); static void _app_main_tag_handler(uint8_t *); static void _app_main_firestore_task(void *); #define APP_MAIN_TAG "APP_MAIN" #define APP_MAIN_SPI_MISO_PIN 19 #define APP_MAIN_SPI_MOSI_PIN 23 #define APP_MAIN_SPI_SCK_PIN 18 #define APP_MAIN_SPI_SDA_PIN 21 #define APP_MAIN_SERIAL_NUMBER_MAX_SIZE 5 #define APP_MAIN_FIRESTORE_QUEUE_SIZE 10 #define APP_MAIN_FIRESTORE_TASK_STACK_SIZE 10240 #define APP_MAIN_FIRESTORE_TASK_PRIORITY 4 #define APP_MAIN_RC522_TASK_PRIORITY 5 #define APP_MAIN_FIRESTORE_PERIOD_MS 2500 #define APP_MAIN_FIRESTORE_DOC_MAX_SIZE 128 #define APP_MAIN_FIRESTORE_COLLECTION_ID "devices" #define APP_MAIN_FIRESTORE_DOCUMENT_ID "rfid-node" #define APP_MAIN_FIRESTORE_DOCUMENT_EXAMPLE "{" \ "\"fields\": {" \ "\"sn\": {" \ "\"stringValue\": ABCDEF1234" \ "}," \ "\"timestamp\": {" \ "\"integerValue\": 1621010203262" \ "}" \ "}" \ "}" typedef enum { TAG_DETECTED_EVENT = 0, TAG_INVALID_EVENT, }rc522_event_t; static QueueHandle_t stQueue; static uint32_t u32DocLength; static char tcDoc[APP_MAIN_FIRESTORE_DOC_MAX_SIZE]; static uint8_t tcu08SerialNumber[APP_MAIN_SERIAL_NUMBER_MAX_SIZE]; static const rc522_start_args_t stStartArgs = { .miso_io = APP_MAIN_SPI_MISO_PIN, .mosi_io = APP_MAIN_SPI_MOSI_PIN, .sck_io = APP_MAIN_SPI_SCK_PIN, .sda_io = APP_MAIN_SPI_SDA_PIN, .callback = &_app_main_tag_handler, .task_priority = APP_MAIN_RC522_TASK_PRIORITY }; static const uint8_t ttu08KnownSerialNumbers[3][5] = { {0x72, 0xEA, 0x5F, 0x06, 0xC1}, {0x29, 0x57, 0x8C, 0xBB, 0x49}, {0x76, 0x9E, 0x25, 0xF8, 0x35}, }; void app_main(void) { app_wifi_init(); app_wifi_wait(); app_ota_start(); stQueue = xQueueCreate(APP_MAIN_FIRESTORE_QUEUE_SIZE, sizeof(rc522_event_t)); xTaskCreate(_app_main_firestore_task, "firestore", APP_MAIN_FIRESTORE_TASK_STACK_SIZE, NULL, APP_MAIN_FIRESTORE_TASK_PRIORITY, NULL); } static void _app_main_tag_handler(uint8_t *pu08SN) { rc522_event_t eEvent; memcpy(tcu08SerialNumber, pu08SN, sizeof(tcu08SerialNumber)); eEvent = TAG_DETECTED_EVENT; xQueueSend(stQueue, &eEvent, portMAX_DELAY); } static void _app_main_firestore_task(void *pvParameter) { rc522_event_t eEvent; app_time_init(); firestore_init(); rc522_start(stStartArgs); while(1) { if(pdPASS == xQueueReceive(stQueue, &eEvent, portMAX_DELAY)) { switch(eEvent) { case TAG_DETECTED_EVENT: ESP_LOGI(APP_MAIN_TAG, "Detected Tag with serial-number: %X%X%X%X%X", tcu08SerialNumber[0], tcu08SerialNumber[1], tcu08SerialNumber[2], tcu08SerialNumber[3], tcu08SerialNumber[4]); if((0 == memcmp(tcu08SerialNumber, ttu08KnownSerialNumbers[0], sizeof(tcu08SerialNumber))) || (0 == memcmp(tcu08SerialNumber, ttu08KnownSerialNumbers[1], sizeof(tcu08SerialNumber))) || (0 == memcmp(tcu08SerialNumber, ttu08KnownSerialNumbers[2], sizeof(tcu08SerialNumber)))) { ESP_LOGI(APP_MAIN_TAG, "Tag is recognized"); } else { ESP_LOGW(APP_MAIN_TAG, "Tag is not recognized"); } /* Sending data anyway */ _app_main_send_data(tcu08SerialNumber); break; default: ESP_LOGW(APP_MAIN_TAG, "Unknow event"); break; } } else { ESP_LOGE(APP_MAIN_TAG, "Couldn't receive item from queue"); } } } static void _app_main_send_data(uint8_t *pu08SN) { int64_t s64Timestamp; /* Format json document */ if(ESP_OK == app_time_get_timestamp(&s64Timestamp)) { u32DocLength = snprintf(tcDoc, sizeof(tcDoc), "{\"fields\":{\"sn\":{\"stringValue\":\"%X%X%X%X%X\"},\"timestamp\":{\"integerValue\":%lld}}}", pu08SN[0], pu08SN[1], pu08SN[2], pu08SN[3], pu08SN[4], s64Timestamp); } else { ESP_LOGW(APP_MAIN_TAG, "Failed to get timestamp --> formatting data without timestamp"); u32DocLength = snprintf(tcDoc, sizeof(tcDoc), "{\"fields\":{\"sn\":{\"stringValue\":\"%X%X%X%X%X\"}}}", pu08SN[0], pu08SN[1], pu08SN[2], pu08SN[3], pu08SN[4]); } ESP_LOGD(APP_MAIN_TAG, "Document length after formatting: %d", u32DocLength); ESP_LOGD(APP_MAIN_TAG, "Document content after formatting:\r\n%.*s", u32DocLength, tcDoc); if(u32DocLength > 0) { /* Update document in firestore or create it if it doesn't already exists */ if(FIRESTORE_OK == firestore_update_document(APP_MAIN_FIRESTORE_COLLECTION_ID, APP_MAIN_FIRESTORE_DOCUMENT_ID, tcDoc, &u32DocLength)) { ESP_LOGI(APP_MAIN_TAG, "Document updated successfully"); ESP_LOGD(APP_MAIN_TAG, "Document length: %d", u32DocLength); ESP_LOGD(APP_MAIN_TAG, "Document content:\r\n%.*s", u32DocLength, tcDoc); } else { ESP_LOGE(APP_MAIN_TAG, "Couldn't update document"); } } else { ESP_LOGE(APP_MAIN_TAG, "Couldn't format document"); } }
kaizoku-oh/pio-rfid
src/app_ota.c
#include <string.h> #include <freertos/FreeRTOS.h> #include <freertos/task.h> #include <esp_system.h> #include <esp_log.h> #include <esp_http_client.h> #include <esp_https_ota.h> #include <cJSON.h> #include "app_wifi.h" #define APP_OTA_TAG "APP_OTA" #define APP_OTA_BASE_URL "https://github-ota-api.herokuapp.com" #define APP_OTA_ENDPOINT "/firmware/latest" #define APP_OTA_GITHUB_USERNAME "kaizoku-oh" #define APP_OTA_GITHUB_REPOSITORY "firestore-rfid-node" #define APP_OTA_DEVICE_CURRENT_FW_VERSION APP_VERSION #define APP_OTA_HTTP_INTERNAL_TX_BUFFER_SIZE 1024 #define APP_OTA_HTTP_INTERNAL_RX_BUFFER_SIZE 1024 #define APP_OTA_HTTP_APP_RX_BUFFER_SIZE 1024 #define APP_OTA_TASK_STACK_SIZE 8192 #define APP_OTA_TASK_PRIORITY 6 #define APP_OTA_TASK_PERIOD_MS 60*1000 static const char *pcApiUrl = APP_OTA_BASE_URL APP_OTA_ENDPOINT "?github_username="APP_OTA_GITHUB_USERNAME "&github_repository="APP_OTA_GITHUB_REPOSITORY "&device_current_fw_version="APP_OTA_DEVICE_CURRENT_FW_VERSION; /* Certificates */ /* $ openssl s_client -showcerts -verify 5 -connect github-releases.githubusercontent.com:443 < /dev/null */ extern const char tcGithubReleaseCertPemStart[] asm("_binary_github_cert_pem_start"); extern const char tcGithubReleaseCertPemEnd[] asm("_binary_github_cert_pem_end"); /* $ openssl s_client -showcerts -verify 5 -connect herokuapp.com:443 < /dev/null */ extern const char tcHerokuCertPemStart[] asm("_binary_heroku_cert_pem_start"); extern const char tcHerokuCertPemEnd[] asm("_binary_heroku_cert_pem_end"); /* HTTP receive buffer */ char tcHttpRcvBuffer[APP_OTA_HTTP_APP_RX_BUFFER_SIZE]; static esp_err_t _app_ota_http_event_handler(esp_http_client_event_t *pstEvent) { switch(pstEvent->event_id) { case HTTP_EVENT_ERROR: ESP_LOGD(APP_OTA_TAG, "HTTP error"); break; case HTTP_EVENT_ON_CONNECTED: ESP_LOGD(APP_OTA_TAG, "HTTP connected to server"); break; case HTTP_EVENT_HEADERS_SENT: ESP_LOGD(APP_OTA_TAG, "All HTTP headers are sent to server"); break; case HTTP_EVENT_ON_HEADER: ESP_LOGD(APP_OTA_TAG, "Received HTTP header from server"); printf("%.*s", pstEvent->data_len, (char*)pstEvent->data); break; case HTTP_EVENT_ON_DATA: ESP_LOGD(APP_OTA_TAG, "Received data from server, len=%d", pstEvent->data_len); if(!esp_http_client_is_chunked_response(pstEvent->client)) { strncpy(tcHttpRcvBuffer, (char*)pstEvent->data, pstEvent->data_len); } break; case HTTP_EVENT_ON_FINISH: ESP_LOGD(APP_OTA_TAG, "HTTP session is finished"); break; case HTTP_EVENT_DISCONNECTED: ESP_LOGD(APP_OTA_TAG, "HTTP connection is closed"); break; } return ESP_OK; } static char* _app_ota_get_download_url(void) { int s32HttpCode; esp_err_t s32RetVal; char* pcDownloadUrl; cJSON *pstJsonObject; cJSON *pstJsonDownloadUrl; esp_http_client_handle_t pstClient; pcDownloadUrl = NULL; esp_http_client_config_t config = { .url = pcApiUrl, .buffer_size = APP_OTA_HTTP_INTERNAL_RX_BUFFER_SIZE, .event_handler = _app_ota_http_event_handler, .cert_pem = tcHerokuCertPemStart, }; pstClient = esp_http_client_init(&config); s32RetVal = esp_http_client_perform(pstClient); if(ESP_OK == s32RetVal) { ESP_LOGD(APP_OTA_TAG, "Status = %d, content_length = %d", esp_http_client_get_status_code(pstClient), esp_http_client_get_content_length(pstClient)); s32HttpCode = esp_http_client_get_status_code(pstClient); if(204 == s32HttpCode) { ESP_LOGI(APP_OTA_TAG, "Device is already running the latest firmware"); } else if(200 == s32HttpCode) { ESP_LOGD(APP_OTA_TAG, "tcHttpRcvBuffer: %s\n", tcHttpRcvBuffer); /* parse the http json respose */ pstJsonObject = cJSON_Parse(tcHttpRcvBuffer); if(pstJsonObject == NULL) { ESP_LOGW(APP_OTA_TAG, "Response does not contain valid json, aborting..."); } else { pstJsonDownloadUrl = cJSON_GetObjectItemCaseSensitive(pstJsonObject, "download_url"); if(cJSON_IsString(pstJsonDownloadUrl) && (pstJsonDownloadUrl->valuestring != NULL)) { pcDownloadUrl = pstJsonDownloadUrl->valuestring; ESP_LOGD(APP_OTA_TAG, "download_url length: %d", strlen(pcDownloadUrl)); } else { ESP_LOGW(APP_OTA_TAG, "Unable to read the download_url, aborting..."); } } } else { ESP_LOGW(APP_OTA_TAG, "Failed to get URL with HTTP code: %d", s32HttpCode); } } esp_http_client_cleanup(pstClient); return pcDownloadUrl; } static void _app_ota_check_update_task(void *pvParameter) { char* pcDownloadUrl; while(1) { pcDownloadUrl = _app_ota_get_download_url(); if(pcDownloadUrl != NULL) { ESP_LOGD(APP_OTA_TAG, "download_url: %s", pcDownloadUrl); ESP_LOGD(APP_OTA_TAG, "Downloading and installing new firmware"); esp_http_client_config_t ota_client_config = { .url = pcDownloadUrl, .cert_pem = tcGithubReleaseCertPemStart, .buffer_size = APP_OTA_HTTP_INTERNAL_RX_BUFFER_SIZE, .buffer_size_tx = APP_OTA_HTTP_INTERNAL_TX_BUFFER_SIZE, }; esp_err_t ret = esp_https_ota(&ota_client_config); if (ret == ESP_OK) { ESP_LOGI(APP_OTA_TAG, "OTA OK, restarting..."); esp_restart(); } else { ESP_LOGE(APP_OTA_TAG, "OTA failed..."); } } else { ESP_LOGW(APP_OTA_TAG, "Could not get download url"); } ESP_LOGI(APP_OTA_TAG, "Device is running App version: %s", APP_OTA_DEVICE_CURRENT_FW_VERSION); vTaskDelay(APP_OTA_TASK_PERIOD_MS / portTICK_PERIOD_MS); } } void app_ota_start(void) { xTaskCreate(&_app_ota_check_update_task, "check_update", APP_OTA_TASK_STACK_SIZE, NULL, APP_OTA_TASK_PRIORITY, NULL); }
RangelReale/easyqrpng
src/easyqrpng.c
<reponame>RangelReale/easyqrpng<filename>src/easyqrpng.c #include "easyqrpng/easyqrpng.h" #include <qrencode.h> #include <stdlib.h> typedef struct easyqrpng_data { QRcode* qrcode; int error; } easyqrpng_data; easyqrpng_data* easyqrpng_new() { easyqrpng_data* ret = (easyqrpng_data*)malloc(sizeof(easyqrpng_data)); //memset( ret->error = 0; return ret; } void easyqrpng_free(easyqrpng_data* data) { } easyqrpng_error_t easyqrpng_encode(const char *data, int length) { //data->qrcode = QRcode_encodeString(data, 0, QR_ECLEVEL_Q, QR_MODE_8, 1); return EASYQRPNGERR_OK; } easyqrpng_error_t easyqrpng_save(easyqrpng_data* data, const char *filename) { return EASYQRPNGERR_OK; } char *easyqrpng_get_data(easyqrpng_data* data) { return NULL; } int easyqrpng_get_length(easyqrpng_data* data) { return 0; } easyqrpng_error_t easyqrpng_error(easyqrpng_data* data) { return EASYQRPNGERR_OK; } /* char *easyqrpng_errormessage(easyqrpng_data* data) { return NULL; } */
RangelReale/easyqrpng
src/errors.c
<reponame>RangelReale/easyqrpng<gh_stars>0 #include "easyqrpng/errors.h" static char *MSG_EASYQRPNGERR_OK = "OK"; static char *MSG_EASYQRPNGERR_ENCODE_ERROR = "Encode error"; static char *MSG_EASYQRPNGERR_NOT_ENCODED = "Not encoded"; static char *MSG_EASYQRPNGERR_ENCODEPNG_ERROR = "PNG encoding error"; char *easyqrpng_errormessage(easyqrpng_error_t e) { switch(e) { case EASYQRPNGERR_OK: return MSG_EASYQRPNGERR_OK; case EASYQRPNGERR_ENCODE_ERROR: return MSG_EASYQRPNGERR_ENCODE_ERROR; case EASYQRPNGERR_NOT_ENCODED: return MSG_EASYQRPNGERR_NOT_ENCODED; case EASYQRPNGERR_ENCODEPNG_ERROR: return MSG_EASYQRPNGERR_ENCODEPNG_ERROR; } return "UNKNOWN ERROR"; }
RangelReale/easyqrpng
include/easyqrpng/errors.h
#ifndef H__EASYQRPNG_ERRORS__H #define H__EASYQRPNG_ERRORS__H typedef int easyqrpng_error_t; #define EASYQRPNGERR_OK 0 #define EASYQRPNGERR_ENCODE_ERROR 1 #define EASYQRPNGERR_NOT_ENCODED 2 #define EASYQRPNGERR_ENCODEPNG_ERROR 3 #if defined(__cplusplus) extern "C" { #endif char *easyqrpng_errormessage(easyqrpng_error_t); #if defined(__cplusplus) } #endif #endif // H__EASYQRPNG_ERRORS__H
RangelReale/easyqrpng
include/easyqrpng/easyqrpngpp.h
<reponame>RangelReale/easyqrpng #ifndef H__EASYQRPNGPP__H #define H__EASYQRPNGPP__H #include <easyqrpng/errors.h> #include <string> #include <iostream> class easyqrpngImpl; class easyqrpng { public: easyqrpng(); virtual ~easyqrpng(); void setTargetWidth(int width); int getTargetWidth() const; void setMargin(int margin); int getMargin() const; easyqrpng_error_t encode(const char *data); easyqrpng_error_t encode(const std::string &data); easyqrpng_error_t save(const char *filename); easyqrpng_error_t save(const std::string &filename); easyqrpng_error_t save(std::ostream &output); easyqrpng_error_t setError(easyqrpng_error_t e); easyqrpng_error_t error(); std::string errorMessage(); private: easyqrpngImpl *_impl; }; #endif // H__EASYQRPNG__H
RangelReale/easyqrpng
include/easyqrpng/easyqrpng.h
<filename>include/easyqrpng/easyqrpng.h #ifndef H__EASYQRPNG__H #define H__EASYQRPNG__H #include <easyqrpng/errors.h> #if defined(__cplusplus) extern "C" { #endif typedef struct easyqrpng_data easyqrpng_data; easyqrpng_data* easyqrpng_new(); void easyqrpng_free(easyqrpng_data* data); easyqrpng_error_t easyqrpng_encode(const char *data, int length); easyqrpng_error_t easyqrpng_save(easyqrpng_data* data, const char *filename); char *easyqrpng_get_data(easyqrpng_data* data); int easyqrpng_get_length(easyqrpng_data* data); easyqrpng_error_t easyqrpng_error(easyqrpng_data* data); //char *easyqrpng_errormessage(easyqrpng_data* data); #if defined(__cplusplus) } #endif #endif // H__EASYQRPNG__H
CreatorWilliam/ApplicationKit
DebugKit/DebugKit.h
<gh_stars>1-10 // // DebugKit.h // DebugKit // // Created by <NAME> on 2018/10/7. // Copyright © 2018 <NAME>. All rights reserved. // #import <UIKit/UIKit.h> //! Project version number for DebugKit. FOUNDATION_EXPORT double DebugKitVersionNumber; //! Project version string for DebugKit. FOUNDATION_EXPORT const unsigned char DebugKitVersionString[]; // In this header, you should import all the public headers of your framework using statements like #import <DebugKit/PublicHeader.h>
CreatorWilliam/ApplicationKit
JPushKit/JPushKit.h
// // JPushKit.h // JPushKit // // Created by <NAME> on 2018/8/16. // Copyright © 2018 <NAME>. All rights reserved. // #import <UIKit/UIKit.h> //! Project version number for JPushKit. FOUNDATION_EXPORT double JPushKitVersionNumber; //! Project version string for JPushKit. FOUNDATION_EXPORT const unsigned char JPushKitVersionString[]; // In this header, you should import all the public headers of your framework using statements like #import <JPushKit/PublicHeader.h> #import "JPUSHService.h" #ifdef NSFoundationVersionNumber_iOS_9_x_Max #import <UserNotifications/UserNotifications.h> #endif
yamingd/AppBootstrap-iOS
Pods/Realm/include/Realm/util/config.h
/************************************************************************* * * CAUTION: DO NOT EDIT THIS FILE -- YOUR CHANGES WILL BE LOST! * * This file is generated by config.sh * *************************************************************************/ #define REALM_VERSION "0.92.2" #define REALM_INSTALL_PREFIX "/usr/local" #define REALM_INSTALL_EXEC_PREFIX "/usr/local" #define REALM_INSTALL_INCLUDEDIR "/usr/local/include" #define REALM_INSTALL_BINDIR "/usr/local/bin" #define REALM_INSTALL_LIBDIR "/usr/local/lib" #define REALM_INSTALL_LIBEXECDIR "/usr/local/libexec" #ifdef REALM_DEBUG # define REALM_MAX_BPNODE_SIZE 1000 #else # define REALM_MAX_BPNODE_SIZE 1000 #endif #if 0 # define REALM_ENABLE_ALLOC_SET_ZERO 1 #endif #if 1 # define REALM_ENABLE_ENCRYPTION 1 #endif #if 1 # define REALM_ENABLE_ASSERTIONS 1 #endif #define REALM_NULL_STRINGS 0
yamingd/AppBootstrap-iOS
AppBootstrap/AppSecurity.h
// // AppSecurity.h // AppBootstrap // // Created by Yaming on 10/2/15. // Copyright © 2015 <EMAIL>. All rights reserved. // #import <Foundation/Foundation.h> #import "TSAppSession.hh" #import "AppSession.h" @interface AppSecurity : NSObject + (instancetype)instance; + (NSString*)randomCode; + (NSString*)aes128Encrypt:(NSString*)text salt:(NSString*)salt iv:(NSString *)iv; + (NSString*)aes128Decrypt:(NSString*)text salt:(NSString*)salt iv:(NSString *)iv; @property(strong, nonatomic) NSString* cookieId; @property(strong, nonatomic) NSString* cookieSalt; -(NSDictionary*)signSession:(TSAppSession*)session; -(NSString*)signRequest:(NSString*)url; @end
yamingd/AppBootstrap-iOS
AppBootstrap/Vendor/MSCMoreOptionTableViewCell/MSCMoreOptionTableViewCell.h
// // MSCMoreOptionTableViewCell.h // MSCMoreOptionTableViewCell // // Created by <NAME> (@scheinem) on 20.08.13. // Copyright (c) 2013 <NAME> (@scheinem). All rights reserved. // // // WARNING (for iOS 8 and above): // ============================== // The functionality of this library will be disabled if 'tableView:editActionsForRowAtIndexPath:' // is implemented in the cell's tableView's delegate! For further information why this is // necessary take a look at the implementation and the comments of MSCMoreOptionTableViewCell's // 'insertSubview:atIndex:' method. // #import "MSCMoreOptionTableViewCellDelegate.h" extern const CGFloat MSCMoreOptionTableViewCellButtonWidthSizeToFit; /* * deleteConfirmationButton - Button created by UIKit, already customized using * using the 'MSCMoreOptionTableViewCellDelegate' * * moreOptionButton - Button created by MSCMoreOptionTableViewCell, already * customized using the 'MSCMoreOptionTableViewCellDelegate' * * *deleteConfirmationButtonWidth - Pointer to the width that 'deleteConfirmationButton' should * get when beeing displayed. * Overrides an eventually set frame.size.width during the * 'configurationBlock' execution. * When set to 'MSCMoreOptionTableViewCellButtonWidthSizeToFit' * the width will be calculated: 'contentSize + edgeInsets' * * *moreOptionButtonWidth - Pointer to the width that 'moreOptionButton' should * get when beeing displayed. * Overrides an eventually set frame.size.width during the * 'configurationBlock' execution. * When set to 'MSCMoreOptionTableViewCellButtonWidthSizeToFit' * the width will be calculated: 'contentSize + edgeInsets' * */ typedef void (^MSCMoreOptionTableViewCellConfigurationBlock)(UIButton *deleteConfirmationButton, UIButton *moreOptionButton, CGFloat *deleteConfirmationButtonWidth, CGFloat *moreOptionButtonWidth); @interface MSCMoreOptionTableViewCell : UITableViewCell @property (nonatomic, weak) id<MSCMoreOptionTableViewCellDelegate> delegate; @property (nonatomic, copy) MSCMoreOptionTableViewCellConfigurationBlock configurationBlock; - (void)hideDeleteConfirmation; @end
yamingd/AppBootstrap-iOS
AppBootstrap/Category/NSData+Ext.h
<gh_stars>0 // // NSData+MD5.h // iosMD5 // // Created by demeng on 11-12-26. // Copyright (c) 2011年 <EMAIL>. All rights reserved. // #import "NSData+Ext.h" @interface NSData(Ext) - (NSString *)md5; + (NSData *)dataFromBase64String:(NSString *)aString; - (NSString *)base64EncodedString; // added by <NAME> - (NSString *)base64EncodedStringWithSeparateLines:(BOOL)separateLines; - (NSString *)hexString; @end
yamingd/AppBootstrap-iOS
AppBootstrap/Controls/UITabBarController+Ext.h
<reponame>yamingd/AppBootstrap-iOS<gh_stars>0 // // UITabBarController+Ext.h // EnglishCafe // // Created by Simsion on 11/5/14. // Copyright (c) 2014 whosbean. All rights reserved. // #import <UIKit/UIKit.h> @interface UITabBarController (Ext) - (void)setTabBarHidden:(BOOL)hidden; - (void)setTabBarHidden:(BOOL)hidden animated:(BOOL)animated; @end
yamingd/AppBootstrap-iOS
AppBootstrap/Utility.h
// // Utility.h // EnglishCafe // // Created by yaming_deng on 2/5/14. // Copyright (c) 2014 whosbean. All rights reserved. // #import <Foundation/Foundation.h> #define kFullScreenHeight (CGRectGetHeight([UIScreen mainScreen].bounds)) #define kFullScreenWidth (CGRectGetWidth([UIScreen mainScreen].bounds)) @interface Utility : NSObject +(NSDictionary*) dictFromPlist:(NSString *)name; +(NSArray*) arrayFromPlist:(NSString *)name; +(NSString*)loadTxt:(NSString*)name; +(NSDictionary*) loadJsonFile:(NSString*)name; +(NSString*) asJson:(id)object; +(id) asObject:(NSString*)data; +(id) asObject2:(NSData*)data; +(NSString*)addQueryStringToUrl:(NSString *)url params:(NSDictionary *)params; +(NSString*)urlEscape:(NSString *)unencodedString; +(UIColor *)colorFromARGB:(int)argb; +(void)pframe:(CGRect)frame; +(int)random:(int)from end:(int)end; +(void)addSkipBackupAttributeToItemAtURL:(NSURL*)url; +(BOOL)mobileOK:(NSString*)mobile; +(id)toHumanSize:(long long)value; /** * 拨打电话 * * @param phone 手机号码,或者带分机号 */ + (void)callPhone:(NSString *)phone; @end
yamingd/AppBootstrap-iOS
AppBootstrap/boost.h
// // sdk.h // AppBootstrap // // Created by yaming_deng on 2/5/14. // Copyright (c) 2014 whosbean. All rights reserved. // #ifndef _boost_h #define _boost_h #define kRemoteNotificationReceived @"RemoteNotificationReceived" #define kRemoteNotificationAccepted @"RemoteNotificationAccepted" #define kNotificationNetworkError @"NotificationNetworkError" #define kNotificationServerError @"NotificationServerError" #define SHARED_INSTANCE_BLOCK(block) \ static dispatch_once_t pred = 0; \ __strong static id _sharedObject = nil; \ dispatch_once(&pred, ^{ \ _sharedObject = block(); \ }); \ return _sharedObject; \ //for log, useage:use LOG instand of NSLog #ifdef DEBUG #define LOG(fmt, ...) NSLog((@"[%s,line:%d]\n>> " fmt), __FUNCTION__, __LINE__, ##__VA_ARGS__); #else #define LOG(...); #endif #define kBG_QUEUE dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0) #define kMAIN_QUEUE dispatch_get_main_queue() #define OSVersionIsAtLeastiOS7 floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_6_1 #define ADD_DYNAMIC_PROPERTY(PROPERTY_TYPE,PROPERTY_NAME,SETTER_NAME) \ @dynamic PROPERTY_NAME ; \ static char kProperty##PROPERTY_NAME; \ - ( PROPERTY_TYPE ) PROPERTY_NAME \ { \ return ( PROPERTY_TYPE ) objc_getAssociatedObject(self, &(kProperty##PROPERTY_NAME ) ); \ } \ \ - (void) SETTER_NAME :( PROPERTY_TYPE ) PROPERTY_NAME \ { \ objc_setAssociatedObject(self, &kProperty##PROPERTY_NAME , PROPERTY_NAME , OBJC_ASSOCIATION_RETAIN); \ } \ // weakself define #define WEAKSELF_DEFINE \ __weak typeof(self) weakSelf = self; #define BUTTON_TITLE_FONT [UIFont boldSystemFontOfSize:16] //RGB转UIColor函数 #define UIColorFromRGB(r, g, b) [UIColor colorWithRed:r/255.0 green:g/255.0 \ blue:b/255.0 alpha:1.0] /** * 使用方式是UIColorHexFromRGB(0x067AB5); */ #define UIColorHexFromRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0] #define UIColorHexFromRGBAlpha(rgbValue,alp) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:alp] #define IOS7_OR_LATER ( [[[UIDevice currentDevice] systemVersion] compare:@"7.0"] != NSOrderedAscending ) #define iPhone5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) : NO) #define IS_OS_8_OR_LATER ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) #define kColor_tint UIColorFromRGB(232, 70, 90) #define kColor_tint_h UIColorFromRGB(175, 48, 66) #define kColor_tint_disable UIColorFromRGB(242, 156, 159) #define kColor_text_btn_disable UIColorFromRGB(249, 210, 212) #define kColor_line [UIColor colorWithRed:204/255.0 green:204/255.0 blue:204/255.0 alpha:1.0] #define kColor_gray UIColorFromRGB(136, 136, 136) #define kColor_lightGray UIColorFromRGB(237, 237, 237) #define kColor_text UIColorFromRGB(85, 85, 85) #define kColor_red UIColorFromRGB(232, 64, 52) #endif
yamingd/AppBootstrap-iOS
AppBootstrap/Controls/UIViewController+Ext.h
// // UIViewController+Ext.h // EnglishCafe // // Created by yaming_deng on 15/5/14. // Copyright (c) 2014 whosbean. All rights reserved. // #import <UIKit/UIKit.h> #import <objc/runtime.h> @interface UIViewController (Ext) -(void)ios7Fix; -(void)contentSizeDidChange:(NSString *)size; -(void)retinaFit; -(void)fitHeight:(UIView*)view; -(CGSize)sizeInPoint; -(CGSize)screenSize; -(BOOL)retina; /*navigation controller setting*/ -(void)setNavColor; -(void)setNavLeftButton:(NSString*)title action:(SEL)action; -(void)setNavLeftImage:(NSString*)name action:(SEL)action; -(void)setNavRightButton:(NSString*)title action:(SEL)action; -(void)setNavRightImage:(NSString*)name action:(SEL)action; -(UIButton*)setNavShareImage:(SEL)action; -(void)showLoadingCircle:(UIColor*)color; -(void)hideLoadingCircle; -(void)showLoadingCircleCenter:(UIColor*)color; -(void)hideLoadingCircleCenter; -(void)replaceWithLoadingCircle:(UIView*)view color:(UIColor*)color; -(void)reshowReplacedView:(UIView*)view; -(void)closeAction; -(void)backToPrevView; -(void)popupView:(UIViewController*)view; -(void)doActionOnTime:(NSString*)key duration:(int)duration action:(void (^)(void))action; @end
yamingd/AppBootstrap-iOS
Pods/Headers/Public/ArrayUtils/ArrayUtils.h
// // ArrayUtils.h // // Version 1.3 // // Created by <NAME> on 01/03/2012. // Copyright (c) 2011 Charcoal Design // // Distributed under the permissive zlib License // Get the latest version from here: // // https://github.com/nicklockwood/ArrayUtils // // This software is provided 'as-is', without any express or implied // warranty. In no event will the authors be held liable for any damages // arising from the use of this software. // // Permission is granted to anyone to use this software for any purpose, // including commercial applications, and to alter it and redistribute it // freely, subject to the following restrictions: // // 1. The origin of this software must not be misrepresented; you must not // claim that you wrote the original software. If you use this software // in a product, an acknowledgment in the product documentation would be // appreciated but is not required. // // 2. Altered source versions must be plainly marked as such, and must not be // misrepresented as being the original software. // // 3. This notice may not be removed or altered from any source distribution. // #import <Foundation/Foundation.h> @interface NSArray (ArrayUtils) - (NSArray *)arrayByRemovingObject:(id)object; - (NSArray *)arrayByRemovingObjectAtIndex:(NSUInteger)index; - (NSArray *)arrayByRemovingLastObject; - (NSArray *)arrayByRemovingFirstObject; - (NSArray *)arrayByInsertingObject:(id)object atIndex:(NSUInteger)index; - (NSArray *)arrayByReplacingObjectAtIndex:(NSUInteger)index withObject:(id)object; - (NSArray *)shuffledArray; - (NSArray *)mappedArrayUsingBlock:(id (^)(id object))block; - (NSArray *)reversedArray; - (NSArray *)arrayByMergingObjectsFromArray:(NSArray *)array; - (NSArray *)objectsInCommonWithArray:(NSArray *)array; - (NSArray *)uniqueObjects; @end @interface NSMutableArray (ArrayUtils) - (void)removeFirstObject; - (void)shuffle; - (void)reverse; - (void)mergeObjectsFromArray:(NSArray *)array; - (void)removeDuplicateObjects; @end
yamingd/AppBootstrap-iOS
AppBootstrap/Category/NSString+Ext.h
// // NSString+Helper.h // EnglishCafe // // Created by yaming_deng on 10/5/14. // Copyright (c) 2014 whosbean. All rights reserved. // #import <Foundation/Foundation.h> @interface NSString (Ext) -(NSString *)dateTimeAgo; -(NSString *)unescapeUnicode; -(NSString *)md5; -(NSString *)hmac:(NSString*)secret; +(NSString *)base64StringFromData:(NSData *)data length:(NSUInteger)length; @end
yamingd/AppBootstrap-iOS
AppBootstrap/XibFactory.h
<gh_stars>0 // // XibFactory.h // #import <Foundation/Foundation.h> #define kMainStoryboardName @"Main" @interface XibFactory : NSObject // return the first instance object in nib list + (id)productWithNibClass:(Class)aClass; + (id)productWithNibName:(NSString *)nibName; + (id)productWithNibName:(NSString *)nibName objectIndex:(NSInteger)index; + (id)productWithNibName:(NSString *)nibName isKindOfClass:(Class)c; // storyboard production + (id)productWithStoryboardName:(NSString *)storyboardName class:(Class)c; + (id)productWithStoryboardName:(NSString *)storyboardName identifier:(NSString *)identifier; + (id)productWithStoryboardIdentifier:(NSString *)identifier; //storyboardName is main @end
yamingd/AppBootstrap-iOS
AppBootstrap/Controls/UIViewController+SearchBar.h
// // UIViewController+SearchBar.h // k12 // // Created by Yaming on 3/16/15. // Copyright (c) 2015 <EMAIL>. All rights reserved. // #import <Foundation/Foundation.h> #import <objc/runtime.h> @interface UIViewController(SearchBar)<UISearchBarDelegate> @property UISearchBar* searchBar; @property UIButton* searchOverlayButton; -(void)doFilterOnSearch:(NSString*)keyword; -(void)hideSearchKeybard; @end
yamingd/AppBootstrap-iOS
AppBootstrap/Category/NSMutableArray+Tool.h
#import <Foundation/Foundation.h> @interface NSMutableArray(Tool) /** * insert mutable objects at index, for instance index is 0 */ - (void)insertObjects:(NSArray *)objects atIndex:(NSUInteger)index; @end
yamingd/AppBootstrap-iOS
AppBootstrap/AppSession.h
// // AppSession.h // EnglishCafe // // Created by yaming_deng on 2/5/14. // Copyright (c) 2014 whosbean. All rights reserved. // #import <Foundation/Foundation.h> #import "TSAppSession.hh" #define kRealmSession @"session" @interface AppSession : NSObject + (AppSession*)current; @property(strong, nonatomic) TSAppSession* session; @property(strong, nonatomic) NSMutableDictionary *flash; @property(strong, nonatomic) NSString* userAgent; - (instancetype)init; //是否匿名 - (BOOL)isAnonymous; - (BOOL)isSignIn; //环境参数DICT - (NSDictionary*) envdict; //API调用参数DICT - (NSDictionary*) apidict; - (NSDictionary*) header; - (void)remember; - (void)clear; - (void)load:(NSString*)appName; @end
yamingd/AppBootstrap-iOS
AppBootstrap/Controls/UIImageEdView.h
<reponame>yamingd/AppBootstrap-iOS // // UIImageEdView.h // k12 // // Created by Yaming on 3/13/15. // Copyright (c) 2015 <EMAIL>. All rights reserved. // #import <UIKit/UIKit.h> #define kUIImageViewStateThumb @"thumb" #define kUIImageViewStateFull @"full" @class UIImageEdView; @protocol UIImageEdViewDelegate <NSObject> @optional -(void)onUIImageEdViewDeleted:(id)sender; - (void)onPresentEnlargeImageView:(UIImageEdView *)imageView; - (void)onDismissEnlargeImageView:(UIImageEdView *)imageView; @end @interface UIImageEdView : UIImageView{ UIButton* _imgRemoveIcon; CGRect _originalFrame; NSString* _removeIconName; NSString* _thumbUrl; NSString* _bigUrl; BOOL _enableRemove; BOOL _enableEnlarge; } @property (nonatomic, weak) id<UIImageEdViewDelegate> delegate; @property id data; -(instancetype)setEnableEnlarge:(BOOL)able; -(instancetype)setRemoveIcon:(NSString*)iconName; -(instancetype)setImagehUrl:(NSString*)thumbUrl bigUrl:(NSString*)bigUrl holder:(NSString*)holder; -(instancetype)setImagehUrl:(NSString *)thumbUrl bigUrl:(NSString *)bigUrl holderImage:(UIImage*)holderImage; -(instancetype)setImageData:(NSData*)imgData; -(instancetype)makeRound; -(instancetype)makeCornerRound:(float)radius; -(instancetype)addBorder:(float)width color:(UIColor*)color; -(void)showFullScreen; @end
yamingd/AppBootstrap-iOS
AppBootstrap/HTTP/APIClient.h
<filename>AppBootstrap/HTTP/APIClient.h // // APIClient.h // EnglishCafe // // Created by yaming_deng on 2/5/14. // Copyright (c) 2014 whosbean. All rights reserved. // #import "AFNetworking.h" #import "TSAppResponse.hh" #import "AFProtobufResponseSerializer.h" @interface APIClient : AFHTTPSessionManager + (instancetype)shared; @property(strong, nonatomic)NSString* baseUrlString; - (instancetype)initWithApiBase:(NSString*)url; - (void) setHeaderValue:(AFHTTPRequestSerializer*)req; //用户变更时需要重置Header Value -(void) resetHeaderValue; -(void) getPath:(NSString *)urlString params:(NSDictionary *)params block:(void (^)(id response, NSError* error))block; -(void) postPath:(NSString *)urlString params:(NSDictionary *)params formBody:(void (^)(id <AFMultipartFormData> formData))formBody block:(void (^)(id response, NSError* error))block; -(void) deletePath:(NSString *)urlString params:(NSDictionary *)params block:(void (^)(id response, NSError* error))block; -(void) putPath:(NSString *)urlString params:(NSDictionary *)params block:(void (^)(id response, NSError* error))block; -(void) patchPath:(NSString *)urlString params:(NSDictionary *)params block:(void (^)(id response, NSError* error))block; -(void)test; -(NSURLSessionDownloadTask*)download:(NSString*)urlString filePath:(NSString *)filePath process:(void (^)(long long readBytes, long long totalBytes))process complete:(void (^)(BOOL successed, NSURL *filePath))complete; -(NSURLSessionDownloadTask*)downloadNSData:(NSString*)urlString process:(void (^)(long long readBytes, long long totalBytes))process complete:(void (^)(BOOL successed, NSData* data))complete; -(NSString *)formatUrl:(NSString *)url args:(NSDictionary *)args; @end
yamingd/AppBootstrap-iOS
AppBootstrap/Controls/UIViewController+ImagePicker.h
// // UIViewController+ImagePicker.h // k12 // // Created by Yaming on 3/13/15. // Copyright (c) 2015 <EMAIL>. All rights reserved. // #import <UIKit/UIKit.h> @protocol ImagePickerDelegate <NSObject> -(void)imagePickerDidSelecteImages:(NSArray*)images; @end @interface UIViewController(ImagePicker) <UINavigationControllerDelegate, UIImagePickerControllerDelegate, UIActionSheetDelegate> -(void)openImageSelectViews; - (BOOL)isHasCamera; - (NSData *)compressImageToDefaultFormat:(UIImage *)image; @end
yamingd/AppBootstrap-iOS
AppBootstrap/Controls/UIImageView+Ext.h
<filename>AppBootstrap/Controls/UIImageView+Ext.h // // UIImageView+Ext.h // EnglishCafe // // Created by yaming_deng on 14/5/14. // Copyright (c) 2014 whosbean. All rights reserved. // #import <UIKit/UIKit.h> @interface UIImageView (Ext) - (void)setImageWith:(NSString *)urlOrName placeholder:(NSString *)holderName; - (void)setImageWithHolder:(NSString *)urlOrName placeholder:(UIImage *)holder; - (void)circleCover; - (void)roundCover:(float)radius; @end
yamingd/AppBootstrap-iOS
AppBootstrap/DeviceHelper.h
<filename>AppBootstrap/DeviceHelper.h // // DeviceHelper.h // MyKingdee // // #import <Foundation/Foundation.h> @interface DeviceHelper : NSObject + (NSString *)getDeviceVersion; + (NSString *)getDeviceName; + (NSString *)getDeviceVName; + (NSString *)getDeviceUdid; + (NSString *)getAdsUdid; + (NSString*)getOSVersion; + (NSString*)getOSName; + (NSString*)getScreenSize; + (float)getScreenWith; + (float)getScreenHeight; + (NSString*)getAppName; + (NSString*)getAppVersion; + (BOOL)isIpad; + (BOOL)isIphone; + (BOOL)hasCamera; + (float)getHeight; @end
yamingd/AppBootstrap-iOS
AppBootstrap/Controls/FHSegmentedViewController.h
<gh_stars>10-100 // // KPSegmentedViewController.h // KPKuaiPai // // Created by <NAME> on 13-12-14. // Copyright (c) 2013年 <NAME>. All rights reserved. // #import <UIKit/UIKit.h> @interface FHSegmentedViewController : UIViewController @property(nonatomic, assign) UIViewController *selectedViewController; @property(nonatomic, strong) IBOutlet UISegmentedControl *segmentedControl; @property(nonatomic, strong) IBOutlet UIView *viewContainer; @property(nonatomic, assign) NSInteger selectedViewControllerIndex; - (void)setViewControllers:(NSArray *)viewControllers; - (void)setViewControllers:(NSArray *)viewControllers titles:(NSArray *)titles; - (void)setViewControllers:(NSArray *)viewControllers imagesNamed:(NSArray *)imageNames; - (void)setViewControllers:(NSArray *)viewControllers images:(NSArray *)images; - (void)pushViewController:(UIViewController *)viewController; - (void)pushViewController:(UIViewController *)viewController title:(NSString *)title; - (void)pushViewController:(UIViewController *)viewController imageNamed:(NSString *)imageName; - (void)pushViewController:(UIViewController *)viewController image:(UIImage *)image; @end
yamingd/AppBootstrap-iOS
AppBootstrap/HTTP/AFProtobufResponseSerializer.h
<reponame>yamingd/AppBootstrap-iOS<filename>AppBootstrap/HTTP/AFProtobufResponseSerializer.h // // AFProtobufResponseSerializer.h // AppBootstrap // // Created by Yaming on 10/2/15. // Copyright © 2015 <EMAIL>. All rights reserved. // #import "AFURLResponseSerialization.h" #define X_PROTOBUF @"application/x-protobuf" @interface AFProtobufResponseSerializer : AFHTTPResponseSerializer - (instancetype) init; @end
yamingd/AppBootstrap-iOS
Pods/Headers/Public/HTKDynamicResizingCell/HTKDynamicResizingCellProtocol.h
// // HTKDynamicResizingCellProtocol.h // HTKDynamicResizingCell // // Created by <NAME> on 10/31/14. // // Copyright (c) 2014 <NAME> (http://www.henrytkirk.info) // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. /** * Protocol used to implement dynamic resizing of UITableView and * UICollectionView cells. When implementing AutoLayout in your * cells, you need to make sure you complete the following: * * 1. Set ContentCompressionResistancePriority for all labels * i.e. [self.label setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisVertical]; * * 2. Set PreferredMaxLayoutWidth for all labels that will have a * auto height. This should equal width of cell minus any buffers on sides. * i.e self.label.preferredMaxLayoutWidth = defaultSize - buffers; * * 3. Set any imageView's images correctly. Remember if you don't * set a fixed width/height on a UIImageView it will use the 1x * intrinsic size of the image to calculate a constraint. So if your * image isn't sized correctly it will produce an incorrect value. */ @protocol HTKDynamicResizingCellProtocol; /** * Estimated width of the UITableViewCell accessory width. * Used to adjust preferredMaxWidth on labels. You need to * factor this in when setting max width if your accessoryType * is anything other than UITableViewCellAccessoryNone. */ static CGFloat HTKDynamicTableViewCellAccessoryWidth = 33; // appx size measured /** * Array that holds a single cell we use for "sizing" and measuring. * You use this to hold different cells you wish to calculate size * on. You don't want to create a cell each time to size with, that * would result in poor performance. * * Simply create a instance of your cell and add it to this array * to reuse. */ static NSMutableArray *cellArray; /** * Block used to setup the cell prior to measuring the size. * You will configure the cellToSetup with all of your label/image * values as needed. */ typedef id (^setupCellBlock)(id<HTKDynamicResizingCellProtocol> cellToSetup); @protocol HTKDynamicResizingCellProtocol <NSObject> /** * Class method that you pass in the default cell size. You will configure * the cell's labels (and nil images in most cases) in the block. * * The default size passed should be used to init your "sizing" cell and * assist with setting max/min sizes. */ + (CGSize)sizeForCellWithDefaultSize:(CGSize)defaultSize setupCellBlock:(setupCellBlock)block; @end
yamingd/AppBootstrap-iOS
AppBootstrap/RealmContext.h
<reponame>yamingd/AppBootstrap-iOS // // RealmHelper.h // AppBootstrap // // Created by Yaming on 10/31/14. // Copyright (c) 2014 whosbean.<EMAIL>. All rights reserved. // #import <Foundation/Foundation.h> #import <Realm/Realm.h> @interface RealmContext : NSObject +(NSString*)userFolder; @property(nonatomic, strong)NSString* name; @property(nonatomic, strong)NSArray* classes; @property int version; -(instancetype)initWith:(NSString*)name classes:(NSArray*)classes version:(int)version; -(RLMRealm*)open; -(void)erase; -(void)update:(void (^)(RLMRealm* realm))block; -(void)query:(void (^)(RLMRealm* realm))block; -(void)dealloc; @end
yamingd/AppBootstrap-iOS
AppBootstrap/Category/UIView+HUD.h
// // UIView+HUD.h // #import <UIKit/UIKit.h> #import "MBProgressHUD.h" @interface UIView(HUD) - (void)showHUD:(NSString *)text; - (void)hideHUD; - (void)showToast:(NSString *)text; - (void)showToast:(NSString *)text afterDelay:(NSTimeInterval)delay; @end
yamingd/AppBootstrap-iOS
Pods/Headers/Public/GoogleProtobuf/google/protobuf/stubs/map-util.h
<reponame>yamingd/AppBootstrap-iOS<gh_stars>0 // Protocol Buffers - Google's data interchange format // Copyright 2008 Google Inc. All rights reserved. // http://code.google.com/p/protobuf/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following disclaimer // in the documentation and/or other materials provided with the // distribution. // * Neither the name of Google Inc. nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // from google3/util/gtl/map-util.h // Author: <NAME> #ifndef GOOGLE_PROTOBUF_STUBS_MAP_UTIL_H__ #define GOOGLE_PROTOBUF_STUBS_MAP_UTIL_H__ #include <google/protobuf/stubs/common.h> namespace google { namespace protobuf { // Perform a lookup in a map or hash_map. // If the key is present in the map then the value associated with that // key is returned, otherwise the value passed as a default is returned. template <class Collection> const typename Collection::value_type::second_type& FindWithDefault(const Collection& collection, const typename Collection::value_type::first_type& key, const typename Collection::value_type::second_type& value) { typename Collection::const_iterator it = collection.find(key); if (it == collection.end()) { return value; } return it->second; } // Perform a lookup in a map or hash_map. // If the key is present a const pointer to the associated value is returned, // otherwise a NULL pointer is returned. template <class Collection> const typename Collection::value_type::second_type* FindOrNull(const Collection& collection, const typename Collection::value_type::first_type& key) { typename Collection::const_iterator it = collection.find(key); if (it == collection.end()) { return 0; } return &it->second; } // Perform a lookup in a map or hash_map, assuming that the key exists. // Crash if it does not. // // This is intended as a replacement for operator[] as an rvalue (for reading) // when the key is guaranteed to exist. // // operator[] is discouraged for several reasons: // * It has a side-effect of inserting missing keys // * It is not thread-safe (even when it is not inserting, it can still // choose to resize the underlying storage) // * It invalidates iterators (when it chooses to resize) // * It default constructs a value object even if it doesn't need to // // This version assumes the key is printable, and includes it in the fatal log // message. template <class Collection> const typename Collection::value_type::second_type& FindOrDie(const Collection& collection, const typename Collection::value_type::first_type& key) { typename Collection::const_iterator it = collection.find(key); GOOGLE_CHECK(it != collection.end()) << "Map key not found: " << key; return it->second; } // Perform a lookup in a map or hash_map whose values are pointers. // If the key is present a const pointer to the associated value is returned, // otherwise a NULL pointer is returned. // This function does not distinguish between a missing key and a key mapped // to a NULL value. template <class Collection> const typename Collection::value_type::second_type FindPtrOrNull(const Collection& collection, const typename Collection::value_type::first_type& key) { typename Collection::const_iterator it = collection.find(key); if (it == collection.end()) { return 0; } return it->second; } // Change the value associated with a particular key in a map or hash_map. // If the key is not present in the map the key and value are inserted, // otherwise the value is updated to be a copy of the value provided. // True indicates that an insert took place, false indicates an update. template <class Collection, class Key, class Value> bool InsertOrUpdate(Collection * const collection, const Key& key, const Value& value) { pair<typename Collection::iterator, bool> ret = collection->insert(typename Collection::value_type(key, value)); if (!ret.second) { // update ret.first->second = value; return false; } return true; } // Insert a new key and value into a map or hash_map. // If the key is not present in the map the key and value are // inserted, otherwise nothing happens. True indicates that an insert // took place, false indicates the key was already present. template <class Collection, class Key, class Value> bool InsertIfNotPresent(Collection * const collection, const Key& key, const Value& value) { pair<typename Collection::iterator, bool> ret = collection->insert(typename Collection::value_type(key, value)); return ret.second; } } // namespace protobuf } // namespace google #endif // GOOGLE_PROTOBUF_STUBS_MAP_UTIL_H__
yamingd/AppBootstrap-iOS
AppBootstrap/Controls/LPlaceholderTextView.h
<reponame>yamingd/AppBootstrap-iOS // // LPlaceholderTextView.h // k12 // // Created by Yaming on 3/4/15. // Copyright (c) 2015 <EMAIL>. All rights reserved. // #import <UIKit/UIKit.h> @interface LPlaceholderTextView : UITextView { UILabel *_placeholderLabel; } @property (strong, nonatomic) NSString *placeholderText; @property (strong, nonatomic) UIColor *placeholderColor; @end
yamingd/AppBootstrap-iOS
AppBootstrap/BootstrapDelegate.h
// // AppBootstrap.h // AppBootstrap // // Created by Yaming on 10/28/14. // Copyright (c) 2014 <EMAIL>. All rights reserved. // #import <Foundation/Foundation.h> @interface BootstrapDelegate : UIResponder <UIApplicationDelegate> @property (strong, nonatomic) UIWindow *window; @property (strong, nonatomic) NSDictionary *launchOptions; @property (strong, nonatomic) NSDictionary *userNotification; -(void)setRootController:(UIViewController *)vc; -(NSString*)getAppNameString; -(BOOL)shouldEnableAPNS; -(void)application:(UIApplication *)application prepareAppSession:(NSDictionary *)launchOptions; -(void)application:(UIApplication *)application prepareRootController:(NSDictionary *)launchOptions; -(void)application:(UIApplication *)application prepareOpenControllers:(NSDictionary *)launchOptions; -(void)application:(UIApplication *)application prepareDatabase:(NSDictionary *)launchOptions; -(void)application:(UIApplication *)application prepareComponents:(NSDictionary *)launchOptions; -(void)onNetworkLost; -(void)onNetworkReconnect; @end
sidhpathak19/HacktoberFestContribute
changes.c
#include<stdio.h> #include<stdlib.h> // Defining structure struct Node { int data; struct Node* next; }; typedef struct LinkedList { struct Node *head; int length; }list; void list_initialize(list *sll) { sll->head=NULL; sll->length=0; } // Push function void push(list *sll, int info) { struct Node *p=sll->head; // Allocating node struct Node* node = (struct Node*) malloc(sizeof(struct Node)); // Info into node node->data = info; // Next of new node to head node->next = p; // head points to new node (sll->head) = node; sll->length++; } void display(list *sll) { struct Node *p=sll->head; while(p!=NULL) { printf("%d\n",p->data); p=p->next; } } // Driver function int main(void) { list sll; list_initialize(&sll); // Adding elements to Linked List push(&sll, 4); push(&sll, 5); push(&sll, 7); push(&sll, 2); push(&sll, 9); push(&sll, 6); push(&sll, 1); push(&sll, 2); push(&sll, 0); push(&sll, 5); push(&sll, 5); display(&sll); if(!(sll.length %2)) { printf("Even\n"); } else { printf("Odd\n"); } return 0; }
YS-L/pgbm
src/histogram.h
#ifndef HISTOGRAM_H_ #define HISTOGRAM_H_ #include "util.h" #include <vector> #include <utility> #include <boost/archive/text_oarchive.hpp> #include <boost/archive/text_iarchive.hpp> #include <boost/serialization/split_member.hpp> #include <boost/serialization/array.hpp> #include <boost/mpi/datatype.hpp> #include <glog/logging.h> class Histogram { public: Histogram(unsigned int num_bins=10); // TODO ~Histogram(); //Histogram(Histogram const&) = delete; //Histogram& operator=(Histogram const&) = delete; class BinVal { public: double m; double y; private: friend class boost::serialization::access; template<class Archive> void serialize(Archive & ar, const unsigned int version) { ar & m; ar & y; } }; class Bin { public: double p; BinVal val; bool operator<(const Bin& rhs) const { return p < rhs.p; } private: friend class boost::serialization::access; template<class Archive> void serialize(Archive & ar, const unsigned int version) { ar & p; ar & val; } }; void Update(double x, double y); void Merge(const Histogram& hist); BinVal Interpolate(double x) const; BinVal InterpolateInf() const; std::vector<double> Uniform(int N) const; unsigned int get_num_bins() const { return bins_.size(); }; const Vector<Bin>& get_bins() const { return bins_; } private: friend class boost::serialization::access; template<class Archive> void serialize(Archive & ar, const unsigned int version) { ar & max_num_bins_; ar & bins_; } /* template<class Archive> void serialize(Archive & ar, const unsigned int version) { ar & max_num_bins_; // Note that bins_ and bins_.size() are not available during loading if (Archive::is_saving::value) { bins_pod_size_ = bins_.size(); } ar & bins_pod_size_; if (bins_pod_ != 0) { delete [] bins_pod_; bins_pod_ = 0; } bins_pod_ = new Bin[bins_pod_size_]; if (Archive::is_saving::value) { for (unsigned int i = 0; i < bins_.size(); ++i) { bins_pod_[i] = bins_[i]; } LOG(INFO) << "HOY ----> Saving archive: bins_pending_pod: " << bins_pending_pod_; } else { //ar & bins_pending_pod_; //bins_pending_pod_ = true; bins_pending_pod_ = true; LOG(INFO) << "HEY ----> Loading archive: bins_pending_pod: " << bins_pending_pod_; } //ar & bins_pending_pod_; //if (Archive::is_saving::value) { //bins_pending_pod_ = false; //} ar & boost::serialization::make_array<Bin>(bins_pod_, bins_pod_size_); } */ /* template<class Archive> void save(Archive & ar, const unsigned int version) const { ar << max_num_bins_; //ar << bins_; bins_pod_size_ = bins_.size(); ar << bins_pod_size_; //for (unsigned int i = 0; i < bins_.size(); ++i) { //bins_pod_[i] = bins_[i]; //} //ar << boost::serialization::make_array<Bin>(bins_pod_, bins_pod_size_); for (unsigned int i = 0 ; i < bins_.size(); ++i) { ar << bins_[i]; } } template<class Archive> void load(Archive & ar, const unsigned int version) { ar >> max_num_bins_; //ar >> bins_; bins_pending_pod_ = true; ar >> bins_pod_size_; //boost::serialization::array<Bin> tmp_array; //ar >> tmp_array; for (unsigned int i = 0; i < bins_pod_size_; ++i) { ar >> bins_pod_[i]; } } BOOST_SERIALIZATION_SPLIT_MEMBER(); */ typedef Vector<Bin> HistogramType; typedef HistogramType::iterator HistogramTypeIter; typedef HistogramType::const_iterator HistogramTypeConstIter; void Trim(); void PrecomputeCumsums() const; void SyncPodBins() const; unsigned int max_num_bins_; mutable HistogramType bins_; //mutable Bin* bins_pod_; boost::array<Bin, 1> bins_pod_; mutable unsigned int bins_pod_size_; mutable bool bins_pending_pod_; mutable bool dirty_; mutable std::vector<BinVal> cumsums_; }; BOOST_IS_MPI_DATATYPE(Histogram::BinVal); BOOST_IS_MPI_DATATYPE(Histogram::Bin); //BOOST_IS_MPI_DATATYPE(Histogram); #endif
YS-L/pgbm
src/loss.h
#ifndef LOSS_H_ #define LOSS_H_ #include <vector> class Loss { public: virtual ~Loss() {}; // Computes the negative gradients virtual void Gradient(const std::vector<double>& targets, const std::vector<double>& current_response, std::vector<double>& gradients) const = 0; virtual double Baseline(const std::vector<double>& targets) const = 0; virtual void Output(const std::vector<double>& responses, std::vector<double>& transformed) const; virtual const char* Name() = 0; }; class TwoClassLogisticRegression: public Loss { public: virtual void Gradient(const std::vector<double>& targets, const std::vector<double>& current_response, std::vector<double>& gradients) const; virtual double Baseline(const std::vector<double>& targets) const; virtual void Output(const std::vector<double>& responses, std::vector<double>& transformed) const; virtual const char* Name(); }; #endif
YS-L/pgbm
src/eval.h
<reponame>YS-L/pgbm #ifndef EVAL_H_ #define EVAL_H_ #include <vector> class DataMatrix; class Metric { public: virtual ~Metric() { }; virtual double Evaluate(const std::vector<double>& predictions, const DataMatrix& data) const = 0; virtual const char* Name() const = 0; }; class Accuracy: public Metric { public: virtual double Evaluate(const std::vector<double>& predictions, const DataMatrix& data) const; virtual const char* Name() const { return "Accuracy"; } }; #endif
YS-L/pgbm
src/util.h
<gh_stars>1-10 #include <cstdio> #include <vector> #include <iostream> #define PEEK_VECTOR(v, n) {\ printf("Peeking vector [%s]: [", #v);\ for (unsigned int i = 0; i < v.size(); ++i) {\ printf("%f ", v[i]);\ if (n > 0 && n < v.size() && i >= n-1) {\ printf(" ... (%d more)", (int)v.size()-i-1);\ break;\ }\ }\ printf("]\n");\ }; #define LOG_STATS(key, value) {\ std::cout << "STATS " << "rank -1 " << key << " " << value << std::endl;\ }; #define LOG_STATS_TAGGED(tag, key, value) {\ std::cout << "STATS " << "rank " << tag << " " << key << " " << value << std::endl;\ }; #define USE_FBVECTOR 0 #if USE_FBVECTOR #include <folly/FBVector.h> template <typename T> using Vector = folly::fbvector<T>; #else template <typename T> using Vector = std::vector<T>; #endif
YS-L/pgbm
src/boosting.h
#ifndef BOOSTING_H_ #define BOOSTING_H_ #include "tree.h" #include "loss.h" #include "eval.h" #include <vector> #include <memory> class DataMatrix; class Booster { public: Booster(unsigned int n_iter, double shrinkage, unsigned int max_depth=6, unsigned int num_bins=50, unsigned int num_split_candidates=50, double subsampling=1.0, unsigned int eval_frequency=1); void Train(const DataMatrix& data); void Train(const DataMatrix& data, const DataMatrix& data_monitor); std::vector<double> Predict(const DataMatrix& data) const; void Describe(); private: void BoostSingleIteration(const DataMatrix& data); void UpdateCachedResponse(unsigned int model_index, const DataMatrix& data, std::vector<double>& response) const; unsigned int n_iter_; double shrinkage_; unsigned int max_depth_; unsigned int num_bins_; unsigned int num_split_candidates_; std::vector<Tree> models_; double base_response_; std::vector<double> cached_response_; std::vector<double> cached_response_monitor_; std::shared_ptr<Loss> loss_function_; std::shared_ptr<Metric> metric_; double subsampling_; unsigned int eval_frequency_; }; #endif
YS-L/pgbm
src/tree.h
#ifndef TREE_H_ #define TREE_H_ #include "histogram.h" #include "data.h" #include <vector> #include <queue> #include <boost/archive/text_oarchive.hpp> #include <boost/archive/text_iarchive.hpp> #include <boost/mpi/datatype.hpp> class Tree { public: struct Node { // ID of the current node unsigned int id; // Indices of the samples reaching the tree std::vector<unsigned int> samples; // Feature used for splitting unsigned int feature_index; // Threshold feature value for splitting double threshold; // Target value double label; // Is the node a leaf? bool is_leaf; // ID of the left node unsigned int left_id; // ID of the right node unsigned int right_id; // Current depth unsigned int depth; }; Tree(unsigned int max_depth=3, unsigned int n_bins=40, unsigned int n_splits=20, unsigned int current_tree_index=0, double subsampling=1.0); void Train(const DataMatrix& data); void Train(const DataMatrix& data, const std::vector<double>& targets); std::vector<double> Predict(const DataMatrix& data) const; double Predict(const DataMatrix::SamplePoint& sample) const; private: class HistogramsPerFeature { public: std::vector<Histogram> histograms; unsigned int feature_index; private: friend class boost::serialization::access; template<class Archive> void serialize(Archive & ar, const unsigned int version) { ar & histograms; ar & feature_index; } }; // Result of splitting on a single feature optimally class SplitResult { public: double cost; double threshold; double label_left; double label_right; double label_self; // When can_split is false bool can_split; unsigned int id_left; unsigned int id_right; unsigned int feature_index; private: friend class boost::serialization::access; template<class Archive> void serialize(Archive & ar, const unsigned int version) { ar & cost; ar & threshold; ar & label_left; ar & label_right; ar & label_self; ar & can_split; ar & id_left; ar & id_right; ar & feature_index; } }; void ProcessCurrentNodes(const DataMatrix& data, const std::vector<double>& targets); void InitializeRootNode(const DataMatrix& data); void InitializeWantedSampleIndices(unsigned int n); void FinalizeAndSplitNode(const DataMatrix& data, const SplitResult& result, Node& parent); SplitResult FindBestSplit(const Histogram& histogram) const; Histogram ComputeHistogram( const std::vector<DataMatrix::FeaturePoint>& column, const std::vector<double>& targets, const std::vector<unsigned int>& samples) const; double TraverseTree(const DataMatrix::SamplePoint& sample) const; void MPI_PullHistograms(std::vector<std::vector<Histogram> >& histograms) const; void MPI_PushHistograms(const std::vector<std::vector<Histogram> >& histograms) const; void MPI_PushBestSplits(std::vector<SplitResult>& best_splits_by_nodes) const; void MPI_PullBestSplits(std::vector<SplitResult>& best_splits_by_nodes) const; int MPI_TagBestSplits() const; void SnapshotHistogram(const Histogram& histogram) const; unsigned int max_depth_; unsigned int n_bins_; unsigned int n_splits_; std::vector<Node> nodes_; unsigned int current_node_id_; std::vector<unsigned int> current_queue_; std::vector<unsigned int> next_queue_; unsigned int current_depth_; unsigned int current_tree_index_; double subsampling_; std::vector<unsigned int> sample_indices_wanted_; }; BOOST_IS_MPI_DATATYPE(Tree::SplitResult); #endif
YS-L/pgbm
src/mpi_util.h
#include <boost/mpi.hpp> namespace mpi = boost::mpi; class MPIHandle { public: static MPIHandle& Get() { static MPIHandle instance; // Guaranteed to be destroyed. // Instantiated on first use. return instance; } mpi::environment env; mpi::communicator world; private: MPIHandle() {}; // Dont forget to declare these two. You want to make sure they // are unaccessable otherwise you may accidently get copies of // your singleton appearing. MPIHandle(MPIHandle const&); // Don't Implement void operator=(MPIHandle const&); // Don't implement };
YS-L/pgbm
src/data.h
<gh_stars>1-10 #ifndef DATA_H_ #define DATA_H_ #include <vector> #include <map> class DataMatrix { public: DataMatrix(); struct FeaturePoint { unsigned int sample_index; double value; }; struct SamplePoint { std::map<unsigned int, double> features; }; int Load(const char *filename, int skips=0, int max_num_samples=-1); void SetTargets(const std::vector<double>& targets); const SamplePoint& GetRow(unsigned int index) const; const std::vector<SamplePoint>& GetRows() const; const std::vector<FeaturePoint>& GetColumn(unsigned int index) const; const std::map<unsigned int, std::vector<FeaturePoint> >& GetColumns() const; const std::vector<double>& GetTargets() const; std::vector<unsigned int> GetFeatureKeys() const; unsigned int Size() const; unsigned int Dimension() const; private: std::map<unsigned int, std::vector<FeaturePoint> > column_data_; std::vector<SamplePoint> row_data_; std::vector<double> targets_; }; #endif
alto-rlk/sorbet
resolver/resolver.h
#ifndef SORBET_RESOLVER_RESOLVER_H #define SORBET_RESOLVER_RESOLVER_H #include "ast/ast.h" #include "common/concurrency/WorkerPool.h" #include <memory> namespace sorbet::resolver { class Resolver final { public: static ast::ParsedFilesOrCancelled run(core::GlobalState &gs, std::vector<ast::ParsedFile> trees, WorkerPool &workers); Resolver() = delete; /** Only runs tree passes, used for incremental changes that do not affect global state. Assumes that `run` was * called on a tree that contains same definitions before (LSP uses heuristics that should only have false negatives * to find this) */ static ast::ParsedFilesOrCancelled runIncremental(core::GlobalState &gs, std::vector<ast::ParsedFile> trees); // used by autogen only static std::vector<ast::ParsedFile> runConstantResolution(core::GlobalState &gs, std::vector<ast::ParsedFile> trees, WorkerPool &workers); private: static void finalizeAncestors(core::GlobalState &gs); static void finalizeSymbols(core::GlobalState &gs); static void computeLinearization(core::GlobalState &gs); static ast::ParsedFilesOrCancelled resolveSigs(core::GlobalState &gs, std::vector<ast::ParsedFile> trees, WorkerPool &workers); static void sanityCheck(const core::GlobalState &gs, std::vector<ast::ParsedFile> &trees); }; } // namespace sorbet::resolver #endif
alto-rlk/sorbet
main/lsp/AbstractRenamer.h
#ifndef SORBET_LSP_CALL_SITES_H #define SORBET_LSP_CALL_SITES_H #include "core/lsp/QueryResponse.h" #include "main/lsp/LSPConfiguration.h" #include "main/lsp/json_types.h" namespace sorbet::realmain::lsp { class AbstractRenamer { public: class UniqueSymbolQueue { public: bool tryEnqueue(core::SymbolRef s); core::SymbolRef pop(); private: std::deque<core::SymbolRef> symbols; UnorderedSet<core::SymbolRef> set; }; AbstractRenamer(const core::GlobalState &gs, const sorbet::realmain::lsp::LSPConfiguration &config, const std::string oldName, const std::string newName) : gs(gs), config(config), oldName(oldName), newName(newName), invalid(false){}; virtual ~AbstractRenamer() = default; virtual void rename(std::unique_ptr<core::lsp::QueryResponse> &response) = 0; std::variant<JSONNullObject, std::unique_ptr<WorkspaceEdit>> buildEdit(); virtual void addSymbol(const core::SymbolRef) = 0; bool getInvalid(); std::string getError(); std::shared_ptr<UniqueSymbolQueue> getQueue(); protected: const core::GlobalState &gs; const LSPConfiguration &config; std::string oldName; std::string newName; UnorderedMap<core::Loc, std::string> edits; bool invalid; std::shared_ptr<UniqueSymbolQueue> symbolQueue = std::make_shared<UniqueSymbolQueue>(); std::string error; static void addSubclassRelatedMethods(const core::GlobalState &gs, core::MethodRef symbol, std::shared_ptr<UniqueSymbolQueue> methods); static void addDispatchRelatedMethods(const core::GlobalState &gs, const core::DispatchResult *dispatchResult, std::shared_ptr<UniqueSymbolQueue> methods); }; } // namespace sorbet::realmain::lsp #endif // SORBET_LSP_CALL_SITES_H
alto-rlk/sorbet
main/lsp/requests/code_action.h
<reponame>alto-rlk/sorbet #ifndef RUBY_TYPER_LSP_REQUESTS_CODE_ACTION_H #define RUBY_TYPER_LSP_REQUESTS_CODE_ACTION_H #include "main/lsp/LSPTask.h" namespace sorbet::realmain::lsp { class CodeActionParams; class CodeActionTask final : public LSPRequestTask { std::unique_ptr<CodeActionParams> params; public: CodeActionTask(const LSPConfiguration &config, MessageId id, std::unique_ptr<CodeActionParams> params); std::unique_ptr<ResponseMessage> runRequest(LSPTypecheckerInterface &typechecker) override; bool canUseStaleData() const override; }; } // namespace sorbet::realmain::lsp #endif
Walikhan007/simple_c_projects
FileCount.c
#include <stdio.h> #define IN 1 #define OUT 0 void file(void); int charcount(char ch); int linecount(char ch); int spacecount(char ch); int wordcount(char ch, int state); int main() { file(); } void file(void) { char ch; int charc, linec, spacec, word, state = OUT; FILE *fl; fl = fopen("Lorem.txt", "r"); while ((ch = fgetc(fl)) != EOF) { charcount(ch); if (charcount(ch) == 1) { ++charc; } linecount(ch); if (linecount(ch) == 1) { ++linec; } spacecount(ch); if (spacecount(ch) == 1) { ++spacec; } wordcount(ch, state); if (wordcount(ch, state) == 0) { state = OUT; } else if (wordcount(ch, state) == 1) { state = IN; ++word; } } printf("Char cout : %d\n", charc); printf("Space cout : %d\n", spacec); printf("Line cout : %d\n", linec); printf("Word Count : %d\n", word); } int charcount(char ch) { int charc; if (ch != ' ' && ch != '\n' && ch != '.' && ch != '\t' && ch != ',') { return 1; } } int spacecount(char ch) { int space; if (ch == ' ') { return 1; } } int linecount(char ch) { int line; if (ch == '\n') { return 1; } } wordcount(char ch, int state){ if (ch == ' ' || ch == '\n' || ch == '\t' || ch == '.'){ return 0; } else if (state == OUT) { return 1; } }
kimhyuntak/gles3jni
app/src/main/cpp/external/image/image.h
<reponame>kimhyuntak/gles3jni #include <string> #include <png.h> class PNG { public: PNG(const std::string& file_name); ~PNG(); unsigned int get_width(); unsigned int get_height(); bool has_alpha(); unsigned char* get_data(); private: const std::string file_name_; unsigned char* data_; png_uint_32 width_, height_; int bit_depth_, color_type_, interlace_type_; int compression_type_, filter_method_; };
kimhyuntak/gles3jni
app/src/main/cpp/Shader.h
#ifndef __SHADER_H__ #define __SHADER_H__ #include <GLES3/gl3.h> class Shader { GLuint mProgram; public: Shader(const char* vtxSrc, const char* fragSrc); GLuint program() const { return mProgram; } }; #endif // __SHADER_H__
kimhyuntak/gles3jni
app/src/main/cpp/DrawObject.h
// // Created by <NAME> on 15/04/2019. // #ifndef GLES3JNI_DRAWOBJECT_H #define GLES3JNI_DRAWOBJECT_H #include <cstring> #include "glcommon.h" struct DrawVtx { GLfloat coord[2]; GLfloat pos[4]; }; struct DrawObject { float mPositionX; // centerX float mPositionY; // centerY // float mVectorX; // float mVectorY; float mWidth; float mHeight; float mCoordX; float mCoordY; float mCoordWidth; float mCoordHeight; float mTextureWidth; float mTextureHeight; float mTransform[4] = {0,0,0,0}; void setTexcoordTransform(float* buf) { buf[0] = static_cast<float>(mCoordWidth) / mTextureWidth; buf[1] = 0; buf[2] = 0; buf[3] = static_cast<float>(mCoordHeight) / mTextureHeight; } void setTexcoordOffset(float* buf) { buf[0] = static_cast<float>(mCoordX) / mTextureWidth; buf[1] = static_cast<float>(mCoordY) / mTextureHeight; } void setPositionTransform(float* buf, int screenX, int screenY) { buf[0] = mWidth / screenX; buf[1] = 0; buf[2] = 0; buf[3] = mHeight / screenY; } void setPositionOffset(float* buf, int screenX, int screenY) { buf[0] = (2 * mPositionX - screenX) / (screenX); buf[1] = (2 * mPositionY - screenY) / (screenY); } }; #endif //GLES3JNI_DRAWOBJECT_H
kimhyuntak/gles3jni
app/src/main/cpp/glcommon.h
#ifndef __GLCOMMON_H__ #define __GLCOMMON_H__ #if DYNAMIC_ES3 #include "gl3stub.h" #else // Include the latest possible header file( GL version header ) #if __ANDROID_API__ >= 24 #include <GLES3/gl32.h> #elif __ANDROID_API__ >= 21 #include <GLES3/gl31.h> #else #include <GLES3/gl3.h> #endif #endif struct Vertex { GLfloat pos[2]; GLubyte rgba[4]; }; // returns true if a GL error occurred bool checkGlError(const char* funcName); void printGlString(const char* name, GLenum s); #endif // __GLCOMMON_H__
kimhyuntak/gles3jni
app/src/main/cpp/logger.h
<reponame>kimhyuntak/gles3jni #ifndef __LOGGER_H__ #define __LOGGER_H__ #include <android/log.h> #define DEBUG 1 #define LOG_TAG "GLES3JNI" #define ALOGE(...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__) #if DEBUG #define ALOGV(...) __android_log_print(ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__) #else #define ALOGV(...) #endif #endif // __LOGGER_H__
kimhyuntak/gles3jni
app/src/main/cpp/Renderer.h
<gh_stars>1-10 #ifndef __RENDERER_H__ #define __RENDERER_H__ #include <math.h> #include "glcommon.h" // ---------------------------------------------------------------------------- // Interface to the ES2 and ES3 renderers, used by JNI code. extern const Vertex QUAD[4]; // ---------------------------------------------------------------------------- // Types, functions, and data used by both ES2 and ES3 renderers. // Defined in gles3jni.cpp. #define MAX_INSTANCES_PER_SIDE 16 #define MAX_INSTANCES (MAX_INSTANCES_PER_SIDE * MAX_INSTANCES_PER_SIDE) #define TWO_PI (2.0 * M_PI) #define MAX_ROT_SPEED (0.3 * TWO_PI) // This demo uses three coordinate spaces: // - The model (a quad) is in a [-1 .. 1]^2 space // - Scene space is either // landscape: [-1 .. 1] x [-1/(2*w/h) .. 1/(2*w/h)] // portrait: [-1/(2*h/w) .. 1/(2*h/w)] x [-1 .. 1] // - Clip space in OpenGL is [-1 .. 1]^2 // // Conceptually, the quads are rotated in model space, then scaled (uniformly) // and translated to place them in scene space. Scene space is then // non-uniformly scaled to clip space. In practice the transforms are combined // so vertices go directly from model to clip space. class Renderer { public: virtual ~Renderer(); void resize(int w, int h); void render(); protected: Renderer(); // return a pointer to a buffer of MAX_INSTANCES * sizeof(vec2). // the buffer is filled with per-instance offsets, then unmapped. virtual float* mapOffsetBuf() = 0; virtual void unmapOffsetBuf() = 0; // return a pointer to a buffer of MAX_INSTANCES * sizeof(vec4). // the buffer is filled with per-instance scale and rotation transforms. virtual float* mapTransformBuf() = 0; virtual void unmapTransformBuf() = 0; virtual void draw(unsigned int numInstances) = 0; virtual void onStep(); float deltaTime() const { return mDeltaTime; } int screenWidth() const { return mWidth; } int screenHeight() const { return mHeight; } private: void calcSceneParams(unsigned int w, unsigned int h, float* offsets); unsigned int mNumInstances; float mScale[2]; float mAngularVelocity[MAX_INSTANCES]; uint64_t mLastFrameNs; float mAngles[MAX_INSTANCES]; float mDeltaTime; int mWidth; int mHeight; }; extern Renderer* createES2Renderer(); extern Renderer* createES3Renderer(); extern Renderer* createTextureRenderer(); #endif // __RENDERER_H__
brahmiboudjema/CVE-2020-25637-libvirt-double-free
Code/info1.c
/ * * * section: Informations * synopsis: Extraire des informations sur le domaine Xen 0 * objectif: démontrer l'utilisation de base de la bibliothèque pour se connecter au * hyperviseur et extraire les informations de domaine. * utilisation: info1 * test: info1 * copie: voir Copyright pour l'état de ce logiciel. * / # include < stdio.h > # include < stdlib.h > # inclure < libvirt / libvirt.h > / * * * getDomainInfo: * @name: le nom du domaine * * extraire les informations du domaine 0 * / vide statique getDomainInfo ( const char * uri, const char * nom) { virConnectPtr conn = NULL ; / * la connexion hyperviseur * / virDomainPtr dom = NULL ; / * le domaine en cours de vérification * / virDomainInfo info; / * les informations récupérées * / int ret; conn = virConnectOpen (uri); if (conn == NULL ) { fprintf (stderr, " Impossible de se connecter à l'hyperviseur \ n " ); erreur goto ; } / * Trouver le domaine du nom donné * / dom = virDomainLookupByName (conn, nom); si (dom == NULL ) { fprintf (stderr, " Impossible de trouver le domaine % s \ n " , nom); erreur goto ; } / * Obtenir les informations * / ret = virDomainGetInfo (dom, & info); if (ret < 0 ) { fprintf (stderr, " Impossible d'obtenir les informations pour le domaine % s \ n " , nom); erreur goto ; } / * Obtenir des informations Iface * / virDomainInterfacePtr * ifaces = NULL ; int ifaces_count = 0 ; taille_t i, j; if ((ifaces_count = virDomainInterfaceAddresses (dom, & ifaces, VIR_DOMAIN_INTERFACE_ADDRESSES_SRC_AGENT, 0 )) < 0 ) goto cleanup; pour (i = 0 ; i <ifaces_count; i ++) { printf ( " nom: % s " , ifaces [i] -> nom ); if (ifaces [i] -> hwaddr ) printf ( " hwaddr: % s " , ifaces [i] -> hwaddr ); pour (j = 0 ; j <ifaces [i] -> naddrs ; j ++) { virDomainIPAddressPtr ip_addr = ifaces [i] -> addrs + j; printf ( " [addr: % s préfixe: % d type: % d ] " , ip_addr-> addr , ip_addr-> prefix , ip_addr-> type ); } printf ( " \ n " ); } nettoyer: if (ifaces && ifaces_count> 0 ) pour (i = 0 ; i <ifaces_count; i ++) virDomainInterfaceFree (ifaces [i]); gratuit (ifaces); printf ( " Domaine % s : % d CPU \ n " , nom, info. nrVirtCpu ); Erreur: si (dom! = NULL ) virDomainFree (dom); si (conn! = NULL ) virConnectClose (conn); } int main ( int argc, char ** argv) { si (argc! = 3 ) { fprintf (stderr, " syntaxe: % s : NOM URI \ n " , argv [ 0 ]); return 1 ; } getDomainInfo (argv [ 1 ], argv [ 2 ]); return 0 ; }
tonyp7/in-12-driver
SerialNixieDriver.h
/* Copyright (c) 2019 <NAME> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @file SerialNixieDriver.h @author <NAME> @brief Arduino library to easily communicated with daisy-chained Nixie tubes. @see https://idyl.io @see https://github.com/tonyp7/SerialNixieDriver */ #ifndef SerialNixieDriver_h #define SerialNixieDriver_h #include <SPI.h> class SerialNixieDriver { public: SerialNixieDriver(); ~SerialNixieDriver(); /** @brief Initialize the driver * this should be called in the "setup" part of an Arduino program or outside a loop otherwise. * If hardwareSPI is set to true, the pins specified must be the correct SPI pins of the board being used. * Output Enable is optional and can be set to 0 if not used. * @param rckPin The pin used as a "chip select". Technically the latch register clock. * @param clkPin The pin used for serial clock. * @param dataPin The pin used to transmit data. In the case of hardware SPI this is the MOSI pin. * @param useHardwareSPI If set to true, Arduino SPI library will be used. Otherwise, software serial will be used via the shiftOut function. */ void begin( int rckPin, int clkPin, int dataPin, int outputEnablePin = 0, bool useHardwareSPI = false); /** @brief Enable/disable output * Please note that as Output Enable pin uses reverse logic, setting "true" will actually pull the output enable pin LOW. */ void outputEnable( bool value ); /** @brief kills the driver. If software serial is used this servers no purpose */ void end(); /** @brief Sends an array of data over daisy-chained nixie tube * @param data an array containing numbers to display * @param size the size of the array */ void send(const uint8_t *data, const uint8_t size); /** @brief Sends a single digit over to a nixie tube * @param data the digit value to display */ void send(const uint8_t data); private: bool _useHardwareSPI = true; int _rckPin = 0; int _clkPin = 0; int _dataPin = 0; int _outputEnablePin = 0; uint16_t decode(const uint8_t digit); void pushData(const uint8_t data); }; #endif
Eastze/clang_api
clang_api/Classes/clang_api.h
<reponame>Eastze/clang_api // // clang_api.h // // Created by dyf on 15/8/14. // Copyright (c) 2015 dyf. // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. // #import <UIKit/UIKit.h> #import <Foundation/Foundation.h> /** * 比较同类型对象是否相等 * * @param obj1 对象1 * @param obj2 对象2 * * @return YES or NO */ FOUNDATION_EXPORT BOOL clang_equal(id obj1, id obj2); /** * 比较字符串是否相等 * * @param str1 字符串1 * @param str2 字符串2 * * @return YES or NO */ FOUNDATION_EXPORT BOOL clang_equal_to_string(NSString *str1, NSString *str2); /** * 选择器运行相应的方法 * * @param target 目标对象 * @param sel SEL对象 */ FOUNDATION_EXPORT void clang_perform_selector(id target, SEL sel); /** * 选择器运行相应的方法 * * @param target 目标对象 * @param sel SEL对象 * @param obj 参数对象 */ FOUNDATION_EXPORT void clang_perform_selector_v2(id target, SEL sel, id obj); /** * 选择器延时运行相应的方法 * * @param target 目标对象 * @param sel SEL对象 * @param ti 延时时间 */ FOUNDATION_EXPORT void clang_delay_perform_selector(id target, SEL sel, double ti); /** * 选择器延时运行相应的方法 * * @param target 目标对象 * @param sel SEL对象 * @param obj 参数对象 * @param ti 延时时间 */ FOUNDATION_EXPORT void clang_delay_perform_selector_v2(id target, SEL sel, id obj, double ti); /** * 返回图片(Main Bundle) * * @param imgName 图片名称 * * @return An `UIImage` object */ UIKIT_EXTERN UIImage *clang_load_image(NSString *imgName); /** * 返回图片 * * @param imgName 图片名称 * @param inDir 图片所在目录 * @param bundleName 不带扩展名的bundle名称, 如果bundleName为nil, 那么返回Main Bundle中的图片 * * @return An `UIImage` object */ UIKIT_EXTERN UIImage *clang_load_image_from_bundle(NSString *imgName, NSString *inDir, NSString *bundleName); /** * 返回图片且数据不缓存内存, 如果找不到相应倍数(1x, 2x, 3x)的图片, 那么返回nil * * @param imgName 图片名称 * @param ext 图片扩展名, 如果ext为nil, 那么ext默认为png * @param inDir 图片所在目录 * @param bundleName 不带扩展名的bundle名称, 如果bundleName为nil, 那么返回Main Bundle中的图片 * * @return An `UIImage` object */ UIKIT_EXTERN UIImage *clang_image_with_contents_of_file(NSString *imgName, NSString *ext, NSString *inDir, NSString *bundleName); /** * 获取资源文件路径 * * @param name 文件名称 * @param ext 文件扩展名 * @param inDir 文件所在目录 * @param bundleName 不带扩展名的bundle名称 * * @return An `NSString` object */ FOUNDATION_EXPORT NSString *clang_path_for_resource_from_bundle(NSString *name, NSString *ext, NSString *inDir, NSString *bundleName); /** * 读取本地化字符串 * * @param key 字段 * @param tbl strings文件名称, 如果文件名为Localizable.strings, 那么tbl为nil * @param language 系统使用的语言 * @param inDir 文件所在目录 * @param bundleName 不带扩展名的bundle名称, 如果bundleName为nil, 那么从Main Bundle中读取内容 * * @return An `NSString` object */ FOUNDATION_EXPORT NSString *clang_localized_string(NSString *key, NSString *tbl, NSString *language, NSString *inDir, NSString *bundleName); /** * 读取对象(UserDefaults) * * @param key 字段 * * @return An `id` object */ FOUNDATION_EXPORT id clang_read_object(NSString *key); /** * 存储对象(UserDefaults) * * @param key 字段 * @param value 对象 * @param synchronized 是否同步 */ FOUNDATION_EXPORT void clang_store_object(NSString *key, id value, BOOL synchronized); /** * 移除对象(UserDefaults) * * @param key 字段 * @param synchronized 是否同步 */ FOUNDATION_EXPORT void clang_remove_object(NSString *key, BOOL synchronized); /** * 添加通知观察者 * * @param observer 观察者 * @param sel SEL对象 * @param name 通知名称 * @param object 参数对象 */ FOUNDATION_EXPORT void clang_add_observer(id observer, SEL sel, NSString *name, id object); /** * 移除通知观察者 * * @param observer 观察者 */ FOUNDATION_EXPORT void clang_remove_observer(id observer); /** * 移除通知观察者 * * @param observer 观察者 * @param name 通知名称 * @param object 参数对象 */ FOUNDATION_EXPORT void clang_remove_observer_v2(id observer, NSString *name, id object); /** * 发送通知 * * @param name 通知名称 * @param object 参数对象 */ FOUNDATION_EXPORT void clang_post_notification_name(NSString *name, id object); /** * 发送通知 * * @param name 通知名称 * @param object 参数对象 * @param userInfo 参数字典 */ FOUNDATION_EXPORT void clang_post_notification_name_v2(NSString *name, id object, NSDictionary *userInfo);
kthyng/octant
external/gridutils/xy2ij.c
/****************************************************************************** * * File: xy2ij.c * * Created 22/01/2002 * * Author: <NAME> * CSIRO Marine Research * * Purpose: Given a numerical grid, converts point coordinates from * (X,Y) to (I,J) space * * Revisions: none. * *****************************************************************************/ #include <stdio.h> #include <stdlib.h> #include <stdarg.h> #include <string.h> #include <math.h> #include <errno.h> #include "gridmap.h" #include "gucommon.h" #include "gridnodes.h" #define BUFSIZE 10240 static int reverse = 0; static int force = 0; static NODETYPE nt = NT_DD; static void version() { printf("xy2ij/libgu version %s\n", gu_version); exit(0); } static void quit(char* format, ...) { va_list args; fflush(stdout); fprintf(stderr, "error: "); va_start(args, format); vfprintf(stderr, format, args); va_end(args); exit(1); } static void usage() { printf("Usage: xy2ij [-i {DD|CO}] [-f] [-r] [-v] -g <grid file> -o <point file>\n"); printf("Try \"xy2ij -h\" for more information\n"); exit(0); } static void info() { printf("Usage: xy2ij [options] -g <grid file> -o <point file>\n"); printf("Where:\n"); printf(" <grid file> -- text file with node coordinates (see remarks below)\n"); printf(" (use \"stdin\" or \"-\" for standard input)\n"); printf(" <point file> -- text file with coordinates to be converted (first two\n"); printf(" columns used as point coordinates) (use \"stdin\" or \"-\" for standard input)\n"); printf("Options:\n"); printf(" -f -- do not exit with error for points outside grid\n"); printf(" -i <node type> -- input node type\n"); printf(" -r -- Make convertion from index to physical space\n"); printf(" -v -- Verbose / version\n"); printf("Node types:\n"); printf(" DD -- double density nodes (default) \n"); printf(" CO -- cell corner nodes\n"); printf("Description:\n"); printf(" `xy2ij' reads grid nodes from a file. After that, it reads points from\n"); printf(" standard input, converts them from (X,Y) to (I,J) space or vice versa,\n"); printf(" and writes results to the standard output.\n"); printf("Remarks:\n"); printf(" 1. The input file must contain header describing the node array dimension:\n"); printf(" ## <nx> x <ny>\n"); printf(" where for double density nodes nx = nce1 * 2 + 1, ny = nce2 * 2 + 1;\n"); printf(" for corner nodes nx = nce1 + 1, ny = nce2 + 1; and for center nodes\n"); printf(" nx = nce1, ny = nce2.\n"); printf(" 2. After the header, the grid file must contain (nx * ny) lines with X and\n"); printf(" Y node coordinates.\n"); printf(" 3. An empty or commented line in the input grid file as well as NaNs for\n"); printf(" node coordinates indicate an invalid node.\n"); printf(" 4. A grid cell is valid if all corner nodes are valid (not NaNs). Only\n"); printf(" points in valid cells may be converted between physical and index\n"); printf(" space.\n"); printf(" 5. The grid (union of all valid grid cells) must be simpy connected both in\n"); printf(" physical and index space.\n"); exit(0); } static void parse_commandline(int argc, char* argv[], char** gfname, char** ofname) { int i; if (argc < 2) usage(); i = 1; while (i < argc) { if (argv[i][0] != '-') usage(); else { switch (argv[i][1]) { case 'i': i++; if (i == argc) quit("no node type found after \"-i\"\n"); if (strcasecmp("dd", argv[i]) == 0) nt = NT_DD; else if (strcasecmp("ce", argv[i]) == 0) quit("cell centre node type is not supported by xy2ij\n"); else if (strcasecmp("co", argv[i]) == 0) nt = NT_COR; else quit("input node type \"%s\" not recognised\n", argv[i]); i++; break; case 'f': i++; force = 1; break; case 'g': i++; *gfname = argv[i]; i++; break; case 'h': info(); break; case 'o': i++; *ofname = argv[i]; i++; break; case 'r': i++; reverse = 1; break; case 'v': i++; gu_verbose = 1; break; default: usage(); break; } } } if (gu_verbose && argc == 2) version(); if (*gfname == NULL || *ofname == NULL) usage(); } int main(int argc, char* argv[]) { char* gfname = NULL; char* ofname = NULL; FILE* of = NULL; gridnodes* gn = NULL; gridmap* map = NULL; char buf[BUFSIZE]; parse_commandline(argc, argv, &gfname, &ofname); if (nt == NT_DD) { gridnodes* gndd = gridnodes_read(gfname, NT_DD); gridnodes_validate(gndd); gn = gridnodes_transform(gndd, NT_COR); gridnodes_destroy(gndd); } else { gn = gridnodes_read(gfname, NT_COR); gridnodes_validate(gn); } /* * build grid map */ map = gridmap_build(gridnodes_getnce1(gn), gridnodes_getnce2(gn), gridnodes_getx(gn), gridnodes_gety(gn)); if (strcmp(ofname, "stdin") == 0 || strcmp(ofname, "-") == 0) of = stdin; else of = gu_fopen(ofname, "r"); /* * read points to be mapped, do the mapping and write results to stdout */ while (fgets(buf, BUFSIZE, of) != NULL) { char rem[BUFSIZE] = ""; double xc, yc, ic, jc; if (sscanf(buf, "%lf %lf %[^\n]", &xc, &yc, rem) >= 2) { if ((!reverse && gridmap_xy2fij(map, xc, yc, &ic, &jc)) || (reverse && gridmap_fij2xy(map, xc, yc, &ic, &jc))) { if (!isnan(ic)) printf("%.15g %.15g %s\n", ic, jc, rem); else printf("NaN NaN %s\n", rem); } else { if (!force) quit("could not convert (%.15g, %.15g) from %s to %s space\n", xc, yc, (reverse) ? "index" : "physical", (reverse) ? "physical" : "index"); else printf("NaN NaN %s\n", rem); } } else printf("%s", buf); } if (of != stdin) fclose(of); gridmap_destroy(map); gridnodes_destroy(gn); return 0; }
kthyng/octant
octant/src/gridgen/csa.h
/****************************************************************************** * * File: csa.h * * Created: 16/10/2002 * * Author: <NAME> * CSIRO Marine Research * * Purpose: A header for csa library (2D data approximation with * bivariate C1 cubic spline) * * Revisions: None * *****************************************************************************/ #if !defined(_CSA_H) #define _CSA_H #if !defined(_POINT_STRUCT) #define _POINT_STRUCT typedef struct { double x; double y; double z; } point; #endif extern int csa_verbose; extern char* csa_version; struct csa; typedef struct csa csa; csa* csa_create(); void csa_destroy(csa* a); void csa_addpoints(csa* a, int n, point points[]); void csa_addstd(csa* a, int n, double variance[]); void csa_calculatespline(csa* a); void csa_approximatepoint(csa* a, point* p); void csa_approximatepoints(csa* a, int n, point* points); void csa_setnpmin(csa* a, int npmin); void csa_setnpmax(csa* a, int npmax); void csa_setk(csa* a, int k); void csa_setnppc(csa* a, int nppc); #endif
kthyng/octant
external/csa/version.h
<filename>external/csa/version.h<gh_stars>1-10 /****************************************************************************** * * File: version.h * * Created: 16/10/2002 * * Author: <NAME> * CSIRO Marine Research * * Purpose: Version string for csa library * *****************************************************************************/ #if !defined(_VERSION_H) #define _VERSION_H char* csa_version = "1.16"; #endif
kthyng/octant
octant/src/gridgen/nnbathy.c
/****************************************************************************** * * File: nnbathy.c * * Created: 04/08/2000 * * Author: <NAME> * CSIRO Marine Research * * Purpose: Interpolate scalar 2D data in specified points using * Natural Neighbours interpolation. * * Description: See usage(). * * The default version of nnbathy allocates the whole output * grid in memory before interpolating; the compilier flag * NN_SERIAL compiles a bit more sophisticated version of that * interpolates in output points on one-by-one basis. * * Revisions: 29/05/2006: introduced NN_SERIAL, see the description above * 01/06/2006: moved flags and other command-line input into * structure "specs" * *****************************************************************************/ #include <stdio.h> #include <stdlib.h> #include <stdarg.h> #include <string.h> #include <limits.h> #include <float.h> #include <math.h> #include <errno.h> #include "config.h" #include "nan.h" #include "minell.h" #include "nn.h" #if defined(NN_SERIAL) #include "preader.h" #endif #if !defined(NN_SERIAL) #define NMAX 4096 #endif #define STRBUFSIZE 64 typedef struct { int generate_points; int thin; int nointerp; int linear; int invariant; int square; char* fin; char* fout; int nx; int ny; int nxd; int nyd; double rmax; double wmin; double zoom; double xmin; double xmax; double ymin; double ymax; #if defined(NN_SERIAL) int npoints; #endif } specs; static void version() { // printf(" nnbathy/nn version %s\n", nn_version); exit(0); } static void usage() { printf("Usage: nnbathy -i <XYZ file>\n"); printf(" -o <XY file> | -n <nx>x<ny> [-c|-s] [-z <zoom>]\n"); printf(" [-x <xmin xmax>] [-xmin <xmin>] [-xmax <xmax>]\n"); printf(" [-y <ymin ymax>] [-ymin <ymin>] [-ymax <ymax>]\n"); printf(" [-v|-T <vertex id>|-V]\n"); printf(" [-D [<nx>x<ny>]]\n"); printf(" [-L <dist>]\n"); printf(" [-N]\n"); printf(" [-P alg={l|nn|ns}]\n"); printf(" [-W <min weight>]\n"); #if defined(NN_SERIAL) printf(" [-%% [npoints]]\n"); #endif printf("Options:\n"); printf(" -c -- scale internally so that the enclosing minimal ellipse\n"); printf(" turns into a circle (this produces results invariant to\n"); printf(" affine transformations)\n"); printf(" -i <XYZ file> -- three-column file with points to interpolate from\n"); printf(" (use \"-i stdin\" or \"-i -\" for standard input)\n"); printf(" -n <nx>x<ny> -- generate <nx>x<ny> output rectangular grid\n"); printf(" -o <XY file> -- two-column file with points to interpolate in\n"); printf(" (use \"-o stdin\" or \"-o -\" for standard input)\n"); printf(" -s -- scale internally so that Xmax - Xmin = Ymax - Ymin\n"); printf(" -x <xmin> <xmax> -- set Xmin and Xmax for the output grid\n"); printf(" -xmin <xmin> -- set Xmin for the output grid\n"); printf(" -xmax <xmax> -- set Xmin for the output grid\n"); printf(" -y <ymin> <ymax> -- set Ymin and Ymax for the output grid\n"); printf(" -ymin <ymin> -- set Ymin for the output grid\n"); printf(" -ymax <ymax> -- set Ymin for the output grid\n"); printf(" -v -- verbose / version\n"); printf(" -z <zoom> -- zoom in (if <zoom> < 1) or out (<zoom> > 1) (activated\n"); printf(" only when used in conjunction with -n)\n"); printf(" -D [<nx>x<ny>] -- thin input data by averaging X, Y and Z values within\n"); printf(" every cell of the rectangular <nx>x<ny> grid (size\n"); printf(" optional with -n)\n"); printf(" -L <dist> -- thin input data by averaging X, Y and Z values within\n"); printf(" clusters of consequitive input points such that the\n"); printf(" sum of distances between points within each cluster\n"); printf(" does not exceed the specified maximum value\n"); printf(" -N -- do not interpolate, only pre-process\n"); printf(" -P alg=<l|nn|ns> -- use the following algorithm:\n"); printf(" l -- linear interpolation\n"); printf(" nn -- Sibson interpolation (default)\n"); printf(" ns -- Non-Sibsonian interpolation\n"); printf(" -T <vertex id> -- verbose; in weights output print weights associated\n"); printf(" with this vertex only\n"); printf(" -V -- very verbose / version\n"); printf(" -W <min weight> -- restricts extrapolation by assigning minimal allowed\n"); printf(" weight for a vertex (normally \"-1\" or so; lower\n"); printf(" values correspond to lower reliability; \"0\" means\n"); printf(" no extrapolation)\n"); #if defined(NN_SERIAL) printf(" -%% [npoints] -- print percent of the work done to standard error;\n"); printf(" npoints -- total number of points to be done (optional\n"); printf(" with -n)\n"); #endif printf("Description:\n"); printf(" `nnbathy' interpolates scalar 2D data in specified points using Natural\n"); printf(" Neighbours interpolation. The interpolated values are written to standard\n"); printf(" output.\n"); exit(0); } static void quit(char* format, ...) { va_list args; fflush(stdout); /* just in case, to have exit message last */ fprintf(stderr, " error: "); va_start(args, format); vfprintf(stderr, format, args); va_end(args); exit(1); } static double str2double(char* token, char* option) { char* end = NULL; double value = NaN; if (token != NULL) value = strtod(token, &end); if (token == NULL || end == token) { fprintf(stderr, " error: command-line option \"%s\": could not convert \"%s\" to double\n", option, (token != NULL) ? token : "NULL"); exit(1); } return value; } static specs* specs_create(void) { specs* s = malloc(sizeof(specs)); s->generate_points = 0; s->thin = 0; s->nointerp = 0; s->linear = 0; s->invariant = 0; s->square = 0; s->fin = NULL; s->fout = NULL; s->nx = -1; s->ny = -1; s->nxd = -1; s->nyd = -1; s->rmax = NaN; s->wmin = -DBL_MAX; s->zoom = 1.0; s->xmin = NaN; s->xmax = NaN; s->ymin = NaN; s->ymax = NaN; #if defined(NN_SERIAL) s->npoints = 0; #endif return s; } void specs_destroy(specs * s) { free(s); } static void parse_commandline(int argc, char* argv[], specs * s) { int i; if (argc < 2) usage(); i = 1; while (i < argc) { if (argv[i][0] != '-') usage(); switch (argv[i][1]) { case 'c': i++; s->square = 0; s->invariant = 1; break; case 'i': i++; if (i >= argc) quit("no file name found after -i\n"); s->fin = argv[i]; i++; break; case 'l': i++; s->linear = 1; break; case 'n': i++; s->fout = NULL; s->generate_points = 1; if (i >= argc) quit("no grid dimensions found after -n\n"); if (sscanf(argv[i], "%dx%d", &s->nx, &s->ny) != 2) quit("could not read grid dimensions after \"-n\"\n"); #if defined(NN_SERIAL) if (s->nx <= 0 || s->ny <= 0) #else if (s->nx <= 0 || s->nx > NMAX || s->ny <= 0 || s->ny > NMAX) #endif quit("invalid size for output grid\n"); i++; break; case 'o': i++; if (i >= argc) quit("no file name found after -o\n"); s->fout = argv[i]; i++; break; case 's': i++; s->square = 1; s->invariant = 0; break; case 'x': if (argv[i][2] == 0) { i++; if (i >= argc) quit("no xmin value found after -x\n"); s->xmin = str2double(argv[i], "-x"); i++; if (i >= argc) quit("no xmax value found after -x\n"); s->xmax = str2double(argv[i], "-x"); i++; } else if (strcmp(argv[i], "-xmin") == 0) { i++; if (i >= argc) quit("no value found after -xmin\n"); s->xmin = str2double(argv[i], "-xmin"); i++; } else if (strcmp(argv[i], "-xmax") == 0) { i++; if (i >= argc) quit("no value found after -xmax\n"); s->xmax = str2double(argv[i], "-xmax"); i++; } else usage(); break; case 'y': if (argv[i][2] == 0) { i++; if (i >= argc) quit("no ymin value found after -y\n"); s->ymin = str2double(argv[i], "-y"); i++; if (i >= argc) quit("no ymax value found after -y\n"); s->ymax = str2double(argv[i], "-y"); i++; } else if (strcmp(argv[i], "-ymin") == 0) { i++; if (i >= argc) quit("no value found after -ymin\n"); s->ymin = str2double(argv[i], "-ymin"); i++; } else if (strcmp(argv[i], "-ymax") == 0) { i++; if (i >= argc) quit("no value found after -ymax\n"); s->ymax = str2double(argv[i], "-ymax"); i++; } else usage(); break; case 'v': i++; nn_verbose = 1; break; case 'z': i++; if (i >= argc) quit("no zoom value found after -z\n"); s->zoom = str2double(argv[i], "-z"); i++; break; case 'D': i++; s->thin = 1; if (argc > i && argv[i][0] != '-') { if (sscanf(argv[i], "%dx%d", &s->nxd, &s->nyd) != 2) quit("could not read grid dimensions after \"-D\"\n"); if (s->nxd <= 0 || s->nyd <= 0) quit("invalid value for nx = %d or ny = %d after -D option\n", s->nxd, s->nyd); #if !defined(NN_SERIAL) if (s->nxd > NMAX || s->nyd > NMAX) quit("too big value after -D option (expected < %d)\n", NMAX); #endif i++; } break; case 'L': i++; s->thin = 2; if (i >= argc) quit("no value found after -L\n"); s->rmax = str2double(argv[i], "-L"); i++; break; case 'N': i++; s->nointerp = 1; break; case 'P':{ char delim[] = "="; char prmstr[STRBUFSIZE] = ""; char* token; i++; if (i >= argc) quit("no input found after -P\n"); if (strlen(argv[i]) >= STRBUFSIZE) quit("could not interpret \"%s\" after -P option\n", argv[i]); strcpy(prmstr, argv[i]); token = strtok(prmstr, delim); if (token == NULL) quit("could not interpret \"%s\" after -P option\n", argv[i]); if (strcmp(token, "alg") == 0) { token = strtok(NULL, delim); if (token == NULL) quit("could not interpret \"%s\" after -P option\n", argv[i]); if (strcmp(token, "nn") == 0) { nn_rule = SIBSON; s->linear = 0; } else if (strcmp(token, "ns") == 0) { nn_rule = NON_SIBSONIAN; s->linear = 0; } else if (strcmp(token, "l") == 0) { s->linear = 1; } else usage(); } i++; break; } case 'W': i++; if (i >= argc) quit("no minimal allowed weight found after -W\n"); s->wmin = str2double(argv[i], "-W"); i++; break; case 'T': i++; if (i >= argc) quit("no vertex id found after -T\n"); nn_test_vertice = atoi(argv[i]); nn_verbose = 1; i++; break; case 'V': i++; nn_verbose = 2; break; #if defined(NN_SERIAL) case '%': i++; if (i < argc && argv[i][0] != '-') { s->npoints = atoi(argv[i]); i++; } else s->npoints = 1; break; #endif default: usage(); break; } } if (nn_verbose && argc == 2) version(); if (s->thin) { if (s->nxd == -1) s->nxd = s->nx; if (s->nyd == -1) s->nyd = s->ny; if (s->nxd <= 0 || s->nyd <= 0) quit("invalid grid size for thinning\n"); } #if defined(NN_SERIAL) if (s->npoints == 1) { if (s->nx <= 0) s->npoints = 0; else s->npoints = s->nx * s->ny; } #endif } static void points_write(int n, point* points) { int i; for (i = 0; i < n; ++i) { point* p = &points[i]; if (isnan(p->z)) printf("%.15g %.15g NaN\n", p->x, p->y); else printf("%.15g %.15g %.15g\n", p->x, p->y, p->z); } } #if !defined(NN_SERIAL) /* A simpler version of nnbathy that allocates the whole output grid in memory */ int main(int argc, char* argv[]) { specs* s = specs_create(); int nin = 0; point* pin = NULL; minell* me = NULL; int nout = 0; point* pout = NULL; double k = NaN; parse_commandline(argc, argv, s); if (s->fin == NULL) quit("no input data\n"); if (!s->generate_points && s->fout == NULL && !s->nointerp) quit("no output grid specified\n"); points_read(s->fin, 3, &nin, &pin); if (nin < 3) return 0; if (s->thin == 1) points_thingrid(&nin, &pin, s->nxd, s->nyd); else if (s->thin == 2) points_thinlin(&nin, &pin, s->rmax); if (s->nointerp) { points_write(nin, pin); specs_destroy(s); free(pin); return 0; } if (s->generate_points) { /* * points_getrange() only writes the proper values to those arguments * which do not point to NaNs */ points_getrange(nin, pin, s->zoom, &s->xmin, &s->xmax, &s->ymin, &s->ymax); points_generate(s->xmin, s->xmax, s->ymin, s->ymax, s->nx, s->ny, &nout, &pout); } else points_read(s->fout, 2, &nout, &pout); if (s->invariant) { me = minell_build(nin, pin); minell_scalepoints(me, nin, pin); minell_scalepoints(me, nout, pout); } else if (s->square) { k = points_scaletosquare(nin, pin); points_scale(nout, pout, k); } if (s->linear) lpi_interpolate_points(nin, pin, nout, pout); else nnpi_interpolate_points(nin, pin, s->wmin, nout, pout); if (s->invariant) minell_rescalepoints(me, nout, pout); else if (s->square) points_scale(nout, pout, 1.0 / k); points_write(nout, pout); if (me != NULL) minell_destroy(me); specs_destroy(s); free(pin); free(pout); return 0; } #else /* NN_SERIAL */ /* A version of nnbathy that interpolates output points serially. Can save a * bit of memory for large output grids. */ int main(int argc, char* argv[]) { specs* s = specs_create(); int nin = 0; point* pin = NULL; minell* me = NULL; point* pout = NULL; double k = NaN; preader* pr = NULL; delaunay* d = NULL; void* interpolator = NULL; int ndone = 0; parse_commandline(argc, argv, s); if (s->fin == NULL) quit("no input data\n"); if (!s->generate_points && s->fout == NULL && !s->nointerp) quit("no output grid specified\n"); points_read(s->fin, 3, &nin, &pin); if (nin < 3) return 0; if (s->thin == 1) points_thingrid(&nin, &pin, s->nxd, s->nyd); else if (s->thin == 2) points_thinlin(&nin, &pin, s->rmax); if (s->nointerp) { points_write(nin, pin); specs_destroy(s); free(pin); return 0; } if (s->generate_points) { points_getrange(nin, pin, s->zoom, &s->xmin, &s->xmax, &s->ymin, &s->ymax); pr = preader_create1(s->xmin, s->xmax, s->ymin, s->ymax, s->nx, s->ny); } else pr = preader_create2(s->fout); if (s->invariant) { me = minell_build(nin, pin); minell_scalepoints(me, nin, pin); } else if (s->square) k = points_scaletosquare(nin, pin); d = delaunay_build(nin, pin, 0, NULL, 0, NULL); if (s->linear) interpolator = lpi_build(d); else { interpolator = nnpi_create(d); nnpi_setwmin(interpolator, s->wmin); } while ((pout = preader_getpoint(pr)) != NULL) { if (s->invariant) minell_scalepoints(me, 1, pout); else if (s->square) points_scale(1, pout, k); if (s->linear) lpi_interpolate_point(interpolator, pout); else nnpi_interpolate_point(interpolator, pout); if (s->invariant) minell_rescalepoints(me, 1, pout); else if (s->square) points_scale(1, pout, 1.0 / k); points_write(1, pout); ndone++; if (s->npoints > 0) fprintf(stderr, " %5.2f%% done\r", 100.0 * ndone / s->npoints); } if (s->npoints > 0) fprintf(stderr, " \r"); if (me != NULL) minell_destroy(me); if (s->linear) lpi_destroy(interpolator); else nnpi_destroy(interpolator); delaunay_destroy(d); preader_destroy(pr); specs_destroy(s); free(pin); return 0; } #endif
kthyng/octant
external/gridutils/getnodes.c
<filename>external/gridutils/getnodes.c /****************************************************************************** * * File: getnodes.c * * Created 22/01/2002 * * Author: <NAME> * CSIRO Marine Research * * Purpose: Post-processes gridgen output grid file: * (i) reads input double density grid nodes * (ii) filters out nodes for partially defined cells * (iii) writes either all or center nodes * Also, can convert grid nodes of one type into another * * Revisions: none. * *****************************************************************************/ #include <stdio.h> #include <stdlib.h> #include <stdarg.h> #include <string.h> #include <math.h> #include "nan.h" #include "gucommon.h" #include "gridnodes.h" static void version() { printf("getnodes/libgu version %s\n", gu_version); exit(0); } static void quit(char* format, ...) { va_list args; fflush(stdout); fprintf(stderr, "error: "); va_start(args, format); vfprintf(stderr, format, args); va_end(args); exit(1); } static void usage() { printf("Usage: getnodes <grid file> [-i <node type>] [-o <node type>]\n"); printf(" [-m <mask file>] [-x|-y] [-v]\n"); printf("Try \"getnodes -h\" for more information\n"); exit(0); } static void info() { printf("Usage: getnodes <grid file> [-i <node type>] [-o <node type>]\n"); printf(" [-m <mask file>] [-v] [-x|-y]\n"); printf("Where:\n"); printf(" <grid file> -- text file with node coordinates (see remarks below)\n"); printf(" (use \"stdin\" or \"-\" for standard input)\n"); printf("Options:\n"); printf(" -i <node type> -- input node type\n"); printf(" -m <mask file> -- text file with nce1 x nce2 lines containing \"0\" or \"1\"\n"); printf(" (use \"stdin\" or \"-\" for standard input)\n"); printf(" -o <node type> -- output node type\n"); printf(" -p -- tweak a bi- or tri- polar grid to a representation that can be\n"); printf(" mapped (xy <-> ij) by using gridmap structure (node coordinates\n"); printf(" are assumed to be in degrees)\n"); printf(" -v -- verbose / version\n"); printf(" -x -- print X coordinates only\n"); printf(" -y -- print Y coordinates only\n"); printf("Node types:\n"); printf(" DD -- double density nodes (default) \n"); printf(" CE -- cell center nodes\n"); printf(" CO -- cell corner nodes\n"); printf("Description:\n"); printf(" `getnodes' (i) reads input grid nodes in \"X Y\" format;\n"); printf(" (ii) validates them (sets node values for empty cells to NaNs);\n"); printf(" (iii) if necessary, converts the nodes to a specified node type;\n"); printf(" (iv) prints the requested nodes.\n"); printf("Remarks:\n"); printf(" 1. The grid file must contain header describing the node array dimension:\n"); printf(" ## <nx> x <ny>\n"); printf(" where for double density nodes nx = nce1 * 2 + 1, ny = nce2 * 2 + 1;\n"); printf(" for corner nodes nx = nce1 + 1, ny = nce2 + 1; and for center nodes\n"); printf(" nx = nce1, ny = nce2.\n"); printf(" 2. After the header, the grid file must contain (nx * ny) lines with X and Y\n"); printf(" node coordinates.\n"); printf(" 3. An empty or commented line in the input grid file as well as NaNs for\n"); printf(" node coordinates indicate an invalid node.\n"); printf(" 4. An optional mask file is a file with nce1 x nce2 lines containing \"1\" for\n"); printf(" valid cells and \"0\" for invalid cells.\n"); printf(" 5. A grid cell is valid if all four corner nodes are valid (not NaNs).\n"); printf(" If a cell mask was specified, then a valid corner node must also have\n"); printf(" at least one valid neigbour cell.\n"); printf(" 6. The grid (union of all valid grid cells) must be simpy connected.\n"); exit(0); } static void parse_commandline(int argc, char* argv[], char** gridfname, char** maskfname, NODETYPE* ntin, NODETYPE* ntout, COORDTYPE* ct, int* tweaknpolar) { int i; if (argc < 2) usage(); i = 1; while (i < argc) { if (argv[i][0] != '-') { *gridfname = argv[i]; i++; } else { switch (argv[i][1]) { case 0: *gridfname = argv[i]; i++; break; case 'i': i++; if (i == argc) quit("no node type found after \"-i\"\n"); if (strcasecmp("dd", argv[i]) == 0) *ntin = NT_DD; else if (strcasecmp("ce", argv[i]) == 0) *ntin = NT_CEN; else if (strcasecmp("co", argv[i]) == 0) *ntin = NT_COR; else quit("input node type \"%s\" not recognised\n", argv[i]); i++; break; case 'h': info(); break; case 'm': i++; if (i == argc) quit("no file name found after \"-m\"\n"); *maskfname = argv[i]; i++; break; case 'o': i++; if (i == argc) quit("no node type found after \"-o\"\n"); if (strcasecmp("dd", argv[i]) == 0) *ntout = NT_DD; else if (strcasecmp("ce", argv[i]) == 0) *ntout = NT_CEN; else if (strcasecmp("co", argv[i]) == 0) *ntout = NT_COR; else quit("input node type \"%s\" not recognised\n", argv[i]); i++; break; case 'p': i++; *tweaknpolar = 1; break; case 'x': i++; *ct = CT_X; break; case 'y': i++; *ct = CT_Y; break; case 'v': i++; gu_verbose = 1; break; default: usage(); break; } } } if (gu_verbose && argc == 2) version(); if (*gridfname == NULL) usage(); } static void gridnodes_tweaknpolar(gridnodes* gn) { int nx = gridnodes_getnx(gn); int ny = gridnodes_getny(gn); double** gx = gridnodes_getx(gn); double** gy = gridnodes_gety(gn); int i, j; for (i = 0; i < nx; ++i) for (j = 1; j < ny; ++j) if (fabs(gx[j][i] - gx[j - 1][i]) > 180.0) gx[j][i] += 360.0; for (j = 0; j < ny; ++j) for (i = 1; i < nx; ++i) if (fabs(gx[j][i] - gx[j][i - 1]) > 180.0) { gx[j][i - 1] = NaN; gy[j][i - 1] = NaN; } for (j = 0; j < ny; ++j) for (i = 1; i < nx; ++i) if (fabs(gy[j][i] - gy[j][i - 1]) > 90.0) { gx[j][i - 1] = NaN; gy[j][i - 1] = NaN; } } int main(int argc, char* argv[]) { char* gridfname = NULL; char* maskfname = NULL; NODETYPE ntin = NT_DD; NODETYPE ntout = NT_DD; COORDTYPE ct = CT_XY; int tweaknpolar = 0; gridnodes* gn = NULL; parse_commandline(argc, argv, &gridfname, &maskfname, &ntin, &ntout, &ct, &tweaknpolar); gn = gridnodes_read(gridfname, ntin); gridnodes_validate(gn); if (ntin != ntout) { gridnodes* gnnew = gridnodes_transform(gn, ntout); gridnodes_destroy(gn); gn = gnnew; } if (maskfname != NULL) { int nx = gridnodes_getnce1(gn); int ny = gridnodes_getnce2(gn); int** mask = gu_readmask(maskfname, nx, ny); gridnodes_applymask(gn, mask); gu_free2d(mask); } if (tweaknpolar) gridnodes_tweaknpolar(gn); if (gu_verbose) gridnodes_calcstats(gn); gridnodes_write(gn, "stdout", ct); gridnodes_destroy(gn); return 0; }
kthyng/octant
external/gridgen/version.h
/****************************************************************************** * * File: version.h * * Created: 18/10/2001 * * Author: <NAME> * CSIRO Marine Research * * Purpose: Contains version string * * Description: None * * Revisions: None * *****************************************************************************/ #if !defined(_VERSION_H) #define _VERSION_H static char* gridgen_version = "1.42"; #endif
kthyng/octant
external/nn/version.h
/****************************************************************************** * * File: version.h * * Created: 18/10/2001 * * Author: <NAME> * CSIRO Marine Research * * Purpose: Contains version string * *****************************************************************************/ #if !defined(_VERSION_H) #define _VERSION_H char* nn_version = "1.71"; #endif
kthyng/octant
octant/src/gridgen/broyden.c
<reponame>kthyng/octant /****************************************************************************** * * File: broyden.c * * Created: 24/02/2000 * * Author: <NAME> * CSIRO Marine Research * * Purpose: Nonlinear solver. * * Revisions: None. * * Description: None. * *****************************************************************************/ #include <stdlib.h> #include <assert.h> #include "broyden.h" /* Makes one iteration of the Gauss-Newton nonlinear solver with Broyden * update. * @param F Function * @param n System dimension * @param x Argument [n] (input/output) * @param f F(x) [n] (input/output) * @param W Negative inverse Jacobian approximation [n^2] (input/output) * @param p Custom data; will be passed to `F' * * Broyden method: * xnew = x + W f * fnew = F(xnew) * Wnew = W - (W fnew) (s^T W) / s^T W (fnew - f), * where * s = xnew - x (= Wf) */ void broyden_update(func F, int n, double* x, double* f, double* W, void* custom) { double* fnew = calloc(n * 4, sizeof(double)); double* s = &fnew[n]; double* stw = &fnew[n * 2]; double* wf1 = &fnew[n * 3]; double denom; double* wij; int i, j; for (j = 0, wij = W; j < n; ++j) { for (i = 0; i < n; ++i, ++wij) s[j] += wij[0] * f[i]; x[j] += s[j]; } F(x, fnew, custom); for (j = 0, wij = W; j < n; ++j) { double sj = s[j]; for (i = 0; i < n; ++i, ++wij) stw[i] += sj * wij[0]; } for (i = 0, denom = 0.0; i < n; ++i) denom += stw[i] * (fnew[i] - f[i]); for (j = 0, wij = W; j < n; ++j) for (i = 0; i < n; ++i, ++wij) wf1[j] += wij[0] * fnew[i]; for (j = 0, wij = W; j < n; ++j) { wf1[j] /= denom; for (i = 0; i < n; ++i, ++wij) wij[0] -= wf1[j] * stw[i]; } for (i = 0; i < n; ++i) f[i] = fnew[i]; free(fnew); } #if defined(TEST_BROYDEN) #include <math.h> #include <stdio.h> #define N 5 #define COUNT_MAX 100 double d[] = { 3.0, 2.0, 1.5, 1.0, 0.5 }; double c = 0.01; static void F(double* x, double* f, void* p) { int i; for (i = 0; i < 5; ++i) f[i] = -x[i] * (d[i] + c * x[i] * x[i]); } int simple = 1; int main(int argc, char* argv[]) { int count = 0; double x[N] = { 1.0, 1.0, 1.0, 1.0, 1.0 }; double y[N]; double w[N * N]; double error; int i; for (i = 0; i < N * N; ++i) w[i] = 0.0; for (i = 0; i < N; ++i) w[i * N + i] = 1.0; printf(" iteration: log10(error)\n"); do { if (count == 0) F(x, y, NULL); else broyden_update(F, N, x, y, w, NULL); for (i = 0, error = 0.0; i < N; ++i) error += y[i] * y[i]; error = log10(error) / 2.0; printf(" %d: %.3g\n", count, error); count++; } while (error > -7.0 && count < COUNT_MAX); return 0; } #endif /* TEST_BROYDEN */
kthyng/octant
octant/src/gridgen/triangle.c
<reponame>kthyng/octant<filename>octant/src/gridgen/triangle.c # 1 "triangle.c" # 1 "<built-in>" # 1 "<command line>" # 1 "triangle.c" # 344 "triangle.c" # 1 "/usr/include/stdio.h" 1 3 4 # 28 "/usr/include/stdio.h" 3 4 # 1 "/usr/include/features.h" 1 3 4 # 329 "/usr/include/features.h" 3 4 # 1 "/usr/include/sys/cdefs.h" 1 3 4 # 313 "/usr/include/sys/cdefs.h" 3 4 # 1 "/usr/include/bits/wordsize.h" 1 3 4 # 314 "/usr/include/sys/cdefs.h" 2 3 4 # 330 "/usr/include/features.h" 2 3 4 # 352 "/usr/include/features.h" 3 4 # 1 "/usr/include/gnu/stubs.h" 1 3 4 # 1 "/usr/include/bits/wordsize.h" 1 3 4 # 5 "/usr/include/gnu/stubs.h" 2 3 4 # 1 "/usr/include/gnu/stubs-64.h" 1 3 4 # 10 "/usr/include/gnu/stubs.h" 2 3 4 # 353 "/usr/include/features.h" 2 3 4 # 29 "/usr/include/stdio.h" 2 3 4 # 1 "/usr/lib/gcc/x86_64-redhat-linux/4.1.2/include/stddef.h" 1 3 4 # 214 "/usr/lib/gcc/x86_64-redhat-linux/4.1.2/include/stddef.h" 3 4 typedef long unsigned int size_t; # 35 "/usr/include/stdio.h" 2 3 4 # 1 "/usr/include/bits/types.h" 1 3 4 # 28 "/usr/include/bits/types.h" 3 4 # 1 "/usr/include/bits/wordsize.h" 1 3 4 # 29 "/usr/include/bits/types.h" 2 3 4 # 1 "/usr/lib/gcc/x86_64-redhat-linux/4.1.2/include/stddef.h" 1 3 4 # 32 "/usr/include/bits/types.h" 2 3 4 typedef unsigned char __u_char; typedef unsigned short int __u_short; typedef unsigned int __u_int; typedef unsigned long int __u_long; typedef signed char __int8_t; typedef unsigned char __uint8_t; typedef signed short int __int16_t; typedef unsigned short int __uint16_t; typedef signed int __int32_t; typedef unsigned int __uint32_t; typedef signed long int __int64_t; typedef unsigned long int __uint64_t; typedef long int __quad_t; typedef unsigned long int __u_quad_t; # 134 "/usr/include/bits/types.h" 3 4 # 1 "/usr/include/bits/typesizes.h" 1 3 4 # 135 "/usr/include/bits/types.h" 2 3 4 typedef unsigned long int __dev_t; typedef unsigned int __uid_t; typedef unsigned int __gid_t; typedef unsigned long int __ino_t; typedef unsigned long int __ino64_t; typedef unsigned int __mode_t; typedef unsigned long int __nlink_t; typedef long int __off_t; typedef long int __off64_t; typedef int __pid_t; typedef struct { int __val[2]; } __fsid_t; typedef long int __clock_t; typedef unsigned long int __rlim_t; typedef unsigned long int __rlim64_t; typedef unsigned int __id_t; typedef long int __time_t; typedef unsigned int __useconds_t; typedef long int __suseconds_t; typedef int __daddr_t; typedef long int __swblk_t; typedef int __key_t; typedef int __clockid_t; typedef void * __timer_t; typedef long int __blksize_t; typedef long int __blkcnt_t; typedef long int __blkcnt64_t; typedef unsigned long int __fsblkcnt_t; typedef unsigned long int __fsblkcnt64_t; typedef unsigned long int __fsfilcnt_t; typedef unsigned long int __fsfilcnt64_t; typedef long int __ssize_t; typedef __off64_t __loff_t; typedef __quad_t *__qaddr_t; typedef char *__caddr_t; typedef long int __intptr_t; typedef unsigned int __socklen_t; # 37 "/usr/include/stdio.h" 2 3 4 typedef struct _IO_FILE FILE; # 62 "/usr/include/stdio.h" 3 4 typedef struct _IO_FILE __FILE; # 72 "/usr/include/stdio.h" 3 4 # 1 "/usr/include/libio.h" 1 3 4 # 32 "/usr/include/libio.h" 3 4 # 1 "/usr/include/_G_config.h" 1 3 4 # 14 "/usr/include/_G_config.h" 3 4 # 1 "/usr/lib/gcc/x86_64-redhat-linux/4.1.2/include/stddef.h" 1 3 4 # 326 "/usr/lib/gcc/x86_64-redhat-linux/4.1.2/include/stddef.h" 3 4 typedef int wchar_t; # 355 "/usr/lib/gcc/x86_64-redhat-linux/4.1.2/include/stddef.h" 3 4 typedef unsigned int wint_t; # 15 "/usr/include/_G_config.h" 2 3 4 # 24 "/usr/include/_G_config.h" 3 4 # 1 "/usr/include/wchar.h" 1 3 4 # 48 "/usr/include/wchar.h" 3 4 # 1 "/usr/lib/gcc/x86_64-redhat-linux/4.1.2/include/stddef.h" 1 3 4 # 49 "/usr/include/wchar.h" 2 3 4 # 1 "/usr/include/bits/wchar.h" 1 3 4 # 51 "/usr/include/wchar.h" 2 3 4 # 76 "/usr/include/wchar.h" 3 4 typedef struct { int __count; union { wint_t __wch; char __wchb[4]; } __value; } __mbstate_t; # 25 "/usr/include/_G_config.h" 2 3 4 typedef struct { __off_t __pos; __mbstate_t __state; } _G_fpos_t; typedef struct { __off64_t __pos; __mbstate_t __state; } _G_fpos64_t; # 44 "/usr/include/_G_config.h" 3 4 # 1 "/usr/include/gconv.h" 1 3 4 # 28 "/usr/include/gconv.h" 3 4 # 1 "/usr/include/wchar.h" 1 3 4 # 48 "/usr/include/wchar.h" 3 4 # 1 "/usr/lib/gcc/x86_64-redhat-linux/4.1.2/include/stddef.h" 1 3 4 # 49 "/usr/include/wchar.h" 2 3 4 # 29 "/usr/include/gconv.h" 2 3 4 # 1 "/usr/lib/gcc/x86_64-redhat-linux/4.1.2/include/stddef.h" 1 3 4 # 32 "/usr/include/gconv.h" 2 3 4 enum { __GCONV_OK = 0, __GCONV_NOCONV, __GCONV_NODB, __GCONV_NOMEM, __GCONV_EMPTY_INPUT, __GCONV_FULL_OUTPUT, __GCONV_ILLEGAL_INPUT, __GCONV_INCOMPLETE_INPUT, __GCONV_ILLEGAL_DESCRIPTOR, __GCONV_INTERNAL_ERROR }; enum { __GCONV_IS_LAST = 0x0001, __GCONV_IGNORE_ERRORS = 0x0002 }; struct __gconv_step; struct __gconv_step_data; struct __gconv_loaded_object; struct __gconv_trans_data; typedef int (*__gconv_fct) (struct __gconv_step *, struct __gconv_step_data *, __const unsigned char **, __const unsigned char *, unsigned char **, size_t *, int, int); typedef wint_t (*__gconv_btowc_fct) (struct __gconv_step *, unsigned char); typedef int (*__gconv_init_fct) (struct __gconv_step *); typedef void (*__gconv_end_fct) (struct __gconv_step *); typedef int (*__gconv_trans_fct) (struct __gconv_step *, struct __gconv_step_data *, void *, __const unsigned char *, __const unsigned char **, __const unsigned char *, unsigned char **, size_t *); typedef int (*__gconv_trans_context_fct) (void *, __const unsigned char *, __const unsigned char *, unsigned char *, unsigned char *); typedef int (*__gconv_trans_query_fct) (__const char *, __const char ***, size_t *); typedef int (*__gconv_trans_init_fct) (void **, const char *); typedef void (*__gconv_trans_end_fct) (void *); struct __gconv_trans_data { __gconv_trans_fct __trans_fct; __gconv_trans_context_fct __trans_context_fct; __gconv_trans_end_fct __trans_end_fct; void *__data; struct __gconv_trans_data *__next; }; struct __gconv_step { struct __gconv_loaded_object *__shlib_handle; __const char *__modname; int __counter; char *__from_name; char *__to_name; __gconv_fct __fct; __gconv_btowc_fct __btowc_fct; __gconv_init_fct __init_fct; __gconv_end_fct __end_fct; int __min_needed_from; int __max_needed_from; int __min_needed_to; int __max_needed_to; int __stateful; void *__data; }; struct __gconv_step_data { unsigned char *__outbuf; unsigned char *__outbufend; int __flags; int __invocation_counter; int __internal_use; __mbstate_t *__statep; __mbstate_t __state; struct __gconv_trans_data *__trans; }; typedef struct __gconv_info { size_t __nsteps; struct __gconv_step *__steps; __extension__ struct __gconv_step_data __data []; } *__gconv_t; # 45 "/usr/include/_G_config.h" 2 3 4 typedef union { struct __gconv_info __cd; struct { struct __gconv_info __cd; struct __gconv_step_data __data; } __combined; } _G_iconv_t; typedef int _G_int16_t __attribute__ ((__mode__ (__HI__))); typedef int _G_int32_t __attribute__ ((__mode__ (__SI__))); typedef unsigned int _G_uint16_t __attribute__ ((__mode__ (__HI__))); typedef unsigned int _G_uint32_t __attribute__ ((__mode__ (__SI__))); # 33 "/usr/include/libio.h" 2 3 4 # 53 "/usr/include/libio.h" 3 4 # 1 "/usr/lib/gcc/x86_64-redhat-linux/4.1.2/include/stdarg.h" 1 3 4 # 43 "/usr/lib/gcc/x86_64-redhat-linux/4.1.2/include/stdarg.h" 3 4 typedef __builtin_va_list __gnuc_va_list; # 54 "/usr/include/libio.h" 2 3 4 # 167 "/usr/include/libio.h" 3 4 struct _IO_jump_t; struct _IO_FILE; # 177 "/usr/include/libio.h" 3 4 typedef void _IO_lock_t; struct _IO_marker { struct _IO_marker *_next; struct _IO_FILE *_sbuf; int _pos; # 200 "/usr/include/libio.h" 3 4 }; enum __codecvt_result { __codecvt_ok, __codecvt_partial, __codecvt_error, __codecvt_noconv }; # 268 "/usr/include/libio.h" 3 4 struct _IO_FILE { int _flags; char* _IO_read_ptr; char* _IO_read_end; char* _IO_read_base; char* _IO_write_base; char* _IO_write_ptr; char* _IO_write_end; char* _IO_buf_base; char* _IO_buf_end; char *_IO_save_base; char *_IO_backup_base; char *_IO_save_end; struct _IO_marker *_markers; struct _IO_FILE *_chain; int _fileno; int _flags2; __off_t _old_offset; unsigned short _cur_column; signed char _vtable_offset; char _shortbuf[1]; _IO_lock_t *_lock; # 316 "/usr/include/libio.h" 3 4 __off64_t _offset; # 325 "/usr/include/libio.h" 3 4 void *__pad1; void *__pad2; void *__pad3; void *__pad4; size_t __pad5; int _mode; char _unused2[15 * sizeof (int) - 4 * sizeof (void *) - sizeof (size_t)]; }; typedef struct _IO_FILE _IO_FILE; struct _IO_FILE_plus; extern struct _IO_FILE_plus _IO_2_1_stdin_; extern struct _IO_FILE_plus _IO_2_1_stdout_; extern struct _IO_FILE_plus _IO_2_1_stderr_; # 361 "/usr/include/libio.h" 3 4 typedef __ssize_t __io_read_fn (void *__cookie, char *__buf, size_t __nbytes); typedef __ssize_t __io_write_fn (void *__cookie, __const char *__buf, size_t __n); typedef int __io_seek_fn (void *__cookie, __off64_t *__pos, int __w); typedef int __io_close_fn (void *__cookie); # 413 "/usr/include/libio.h" 3 4 extern int __underflow (_IO_FILE *); extern int __uflow (_IO_FILE *); extern int __overflow (_IO_FILE *, int); extern wint_t __wunderflow (_IO_FILE *); extern wint_t __wuflow (_IO_FILE *); extern wint_t __woverflow (_IO_FILE *, wint_t); # 451 "/usr/include/libio.h" 3 4 extern int _IO_getc (_IO_FILE *__fp); extern int _IO_putc (int __c, _IO_FILE *__fp); extern int _IO_feof (_IO_FILE *__fp) __attribute__ ((__nothrow__)); extern int _IO_ferror (_IO_FILE *__fp) __attribute__ ((__nothrow__)); extern int _IO_peekc_locked (_IO_FILE *__fp); extern void _IO_flockfile (_IO_FILE *) __attribute__ ((__nothrow__)); extern void _IO_funlockfile (_IO_FILE *) __attribute__ ((__nothrow__)); extern int _IO_ftrylockfile (_IO_FILE *) __attribute__ ((__nothrow__)); # 481 "/usr/include/libio.h" 3 4 extern int _IO_vfscanf (_IO_FILE * __restrict, const char * __restrict, __gnuc_va_list, int *__restrict); extern int _IO_vfprintf (_IO_FILE *__restrict, const char *__restrict, __gnuc_va_list); extern __ssize_t _IO_padn (_IO_FILE *, int, __ssize_t); extern size_t _IO_sgetn (_IO_FILE *, void *, size_t); extern __off64_t _IO_seekoff (_IO_FILE *, __off64_t, int, int); extern __off64_t _IO_seekpos (_IO_FILE *, __off64_t, int); extern void _IO_free_backup_area (_IO_FILE *) __attribute__ ((__nothrow__)); # 73 "/usr/include/stdio.h" 2 3 4 # 86 "/usr/include/stdio.h" 3 4 typedef _G_fpos_t fpos_t; # 138 "/usr/include/stdio.h" 3 4 # 1 "/usr/include/bits/stdio_lim.h" 1 3 4 # 139 "/usr/include/stdio.h" 2 3 4 extern struct _IO_FILE *stdin; extern struct _IO_FILE *stdout; extern struct _IO_FILE *stderr; extern int remove (__const char *__filename) __attribute__ ((__nothrow__)); extern int rename (__const char *__old, __const char *__new) __attribute__ ((__nothrow__)); extern FILE *tmpfile (void); # 185 "/usr/include/stdio.h" 3 4 extern char *tmpnam (char *__s) __attribute__ ((__nothrow__)); extern char *tmpnam_r (char *__s) __attribute__ ((__nothrow__)); # 203 "/usr/include/stdio.h" 3 4 extern char *tempnam (__const char *__dir, __const char *__pfx) __attribute__ ((__nothrow__)) __attribute__ ((__malloc__)); extern int fclose (FILE *__stream); extern int fflush (FILE *__stream); # 228 "/usr/include/stdio.h" 3 4 extern int fflush_unlocked (FILE *__stream); # 242 "/usr/include/stdio.h" 3 4 extern FILE *fopen (__const char *__restrict __filename, __const char *__restrict __modes); extern FILE *freopen (__const char *__restrict __filename, __const char *__restrict __modes, FILE *__restrict __stream); # 269 "/usr/include/stdio.h" 3 4 # 280 "/usr/include/stdio.h" 3 4 extern FILE *fdopen (int __fd, __const char *__modes) __attribute__ ((__nothrow__)); # 300 "/usr/include/stdio.h" 3 4 extern void setbuf (FILE *__restrict __stream, char *__restrict __buf) __attribute__ ((__nothrow__)); extern int setvbuf (FILE *__restrict __stream, char *__restrict __buf, int __modes, size_t __n) __attribute__ ((__nothrow__)); extern void setbuffer (FILE *__restrict __stream, char *__restrict __buf, size_t __size) __attribute__ ((__nothrow__)); extern void setlinebuf (FILE *__stream) __attribute__ ((__nothrow__)); extern int fprintf (FILE *__restrict __stream, __const char *__restrict __format, ...); extern int printf (__const char *__restrict __format, ...); extern int sprintf (char *__restrict __s, __const char *__restrict __format, ...) __attribute__ ((__nothrow__)); extern int vfprintf (FILE *__restrict __s, __const char *__restrict __format, __gnuc_va_list __arg); extern int vprintf (__const char *__restrict __format, __gnuc_va_list __arg); extern int vsprintf (char *__restrict __s, __const char *__restrict __format, __gnuc_va_list __arg) __attribute__ ((__nothrow__)); extern int snprintf (char *__restrict __s, size_t __maxlen, __const char *__restrict __format, ...) __attribute__ ((__nothrow__)) __attribute__ ((__format__ (__printf__, 3, 4))); extern int vsnprintf (char *__restrict __s, size_t __maxlen, __const char *__restrict __format, __gnuc_va_list __arg) __attribute__ ((__nothrow__)) __attribute__ ((__format__ (__printf__, 3, 0))); # 394 "/usr/include/stdio.h" 3 4 extern int fscanf (FILE *__restrict __stream, __const char *__restrict __format, ...) ; extern int scanf (__const char *__restrict __format, ...) ; extern int sscanf (__const char *__restrict __s, __const char *__restrict __format, ...) __attribute__ ((__nothrow__)); # 436 "/usr/include/stdio.h" 3 4 extern int fgetc (FILE *__stream); extern int getc (FILE *__stream); extern int getchar (void); # 460 "/usr/include/stdio.h" 3 4 extern int getc_unlocked (FILE *__stream); extern int getchar_unlocked (void); # 471 "/usr/include/stdio.h" 3 4 extern int fgetc_unlocked (FILE *__stream); extern int fputc (int __c, FILE *__stream); extern int putc (int __c, FILE *__stream); extern int putchar (int __c); # 504 "/usr/include/stdio.h" 3 4 extern int fputc_unlocked (int __c, FILE *__stream); extern int putc_unlocked (int __c, FILE *__stream); extern int putchar_unlocked (int __c); extern int getw (FILE *__stream); extern int putw (int __w, FILE *__stream); extern char *fgets (char *__restrict __s, int __n, FILE *__restrict __stream) ; extern char *gets (char *__s) ; # 585 "/usr/include/stdio.h" 3 4 extern int fputs (__const char *__restrict __s, FILE *__restrict __stream); extern int puts (__const char *__s); extern int ungetc (int __c, FILE *__stream); extern size_t fread (void *__restrict __ptr, size_t __size, size_t __n, FILE *__restrict __stream) ; extern size_t fwrite (__const void *__restrict __ptr, size_t __size, size_t __n, FILE *__restrict __s) ; # 638 "/usr/include/stdio.h" 3 4 extern size_t fread_unlocked (void *__restrict __ptr, size_t __size, size_t __n, FILE *__restrict __stream) ; extern size_t fwrite_unlocked (__const void *__restrict __ptr, size_t __size, size_t __n, FILE *__restrict __stream) ; extern int fseek (FILE *__stream, long int __off, int __whence); extern long int ftell (FILE *__stream) ; extern void rewind (FILE *__stream); # 674 "/usr/include/stdio.h" 3 4 extern int fseeko (FILE *__stream, __off_t __off, int __whence); extern __off_t ftello (FILE *__stream) ; # 693 "/usr/include/stdio.h" 3 4 extern int fgetpos (FILE *__restrict __stream, fpos_t *__restrict __pos); extern int fsetpos (FILE *__stream, __const fpos_t *__pos); # 716 "/usr/include/stdio.h" 3 4 # 725 "/usr/include/stdio.h" 3 4 extern void clearerr (FILE *__stream) __attribute__ ((__nothrow__)); extern int feof (FILE *__stream) __attribute__ ((__nothrow__)) ; extern int ferror (FILE *__stream) __attribute__ ((__nothrow__)) ; extern void clearerr_unlocked (FILE *__stream) __attribute__ ((__nothrow__)); extern int feof_unlocked (FILE *__stream) __attribute__ ((__nothrow__)) ; extern int ferror_unlocked (FILE *__stream) __attribute__ ((__nothrow__)) ; extern void perror (__const char *__s); # 1 "/usr/include/bits/sys_errlist.h" 1 3 4 # 27 "/usr/include/bits/sys_errlist.h" 3 4 extern int sys_nerr; extern __const char *__const sys_errlist[]; # 755 "/usr/include/stdio.h" 2 3 4 extern int fileno (FILE *__stream) __attribute__ ((__nothrow__)) ; extern int fileno_unlocked (FILE *__stream) __attribute__ ((__nothrow__)) ; # 774 "/usr/include/stdio.h" 3 4 extern FILE *popen (__const char *__command, __const char *__modes) ; extern int pclose (FILE *__stream); extern char *ctermid (char *__s) __attribute__ ((__nothrow__)); # 814 "/usr/include/stdio.h" 3 4 extern void flockfile (FILE *__stream) __attribute__ ((__nothrow__)); extern int ftrylockfile (FILE *__stream) __attribute__ ((__nothrow__)) ; extern void funlockfile (FILE *__stream) __attribute__ ((__nothrow__)); # 844 "/usr/include/stdio.h" 3 4 # 345 "triangle.c" 2 # 1 "/usr/include/stdlib.h" 1 3 4 # 33 "/usr/include/stdlib.h" 3 4 # 1 "/usr/lib/gcc/x86_64-redhat-linux/4.1.2/include/stddef.h" 1 3 4 # 34 "/usr/include/stdlib.h" 2 3 4 # 96 "/usr/include/stdlib.h" 3 4 typedef struct { int quot; int rem; } div_t; typedef struct { long int quot; long int rem; } ldiv_t; # 140 "/usr/include/stdlib.h" 3 4 extern size_t __ctype_get_mb_cur_max (void) __attribute__ ((__nothrow__)) ; extern double atof (__const char *__nptr) __attribute__ ((__nothrow__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1))) ; extern int atoi (__const char *__nptr) __attribute__ ((__nothrow__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1))) ; extern long int atol (__const char *__nptr) __attribute__ ((__nothrow__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1))) ; __extension__ extern long long int atoll (__const char *__nptr) __attribute__ ((__nothrow__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1))) ; extern double strtod (__const char *__restrict __nptr, char **__restrict __endptr) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))) ; # 182 "/usr/include/stdlib.h" 3 4 extern long int strtol (__const char *__restrict __nptr, char **__restrict __endptr, int __base) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))) ; extern unsigned long int strtoul (__const char *__restrict __nptr, char **__restrict __endptr, int __base) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))) ; __extension__ extern long long int strtoq (__const char *__restrict __nptr, char **__restrict __endptr, int __base) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))) ; __extension__ extern unsigned long long int strtouq (__const char *__restrict __nptr, char **__restrict __endptr, int __base) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))) ; __extension__ extern long long int strtoll (__const char *__restrict __nptr, char **__restrict __endptr, int __base) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))) ; __extension__ extern unsigned long long int strtoull (__const char *__restrict __nptr, char **__restrict __endptr, int __base) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))) ; # 279 "/usr/include/stdlib.h" 3 4 extern double __strtod_internal (__const char *__restrict __nptr, char **__restrict __endptr, int __group) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))) ; extern float __strtof_internal (__const char *__restrict __nptr, char **__restrict __endptr, int __group) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))) ; extern long double __strtold_internal (__const char *__restrict __nptr, char **__restrict __endptr, int __group) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))) ; extern long int __strtol_internal (__const char *__restrict __nptr, char **__restrict __endptr, int __base, int __group) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))) ; extern unsigned long int __strtoul_internal (__const char *__restrict __nptr, char **__restrict __endptr, int __base, int __group) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))) ; __extension__ extern long long int __strtoll_internal (__const char *__restrict __nptr, char **__restrict __endptr, int __base, int __group) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))) ; __extension__ extern unsigned long long int __strtoull_internal (__const char * __restrict __nptr, char **__restrict __endptr, int __base, int __group) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))) ; # 429 "/usr/include/stdlib.h" 3 4 extern char *l64a (long int __n) __attribute__ ((__nothrow__)) ; extern long int a64l (__const char *__s) __attribute__ ((__nothrow__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1))) ; # 1 "/usr/include/sys/types.h" 1 3 4 # 29 "/usr/include/sys/types.h" 3 4 typedef __u_char u_char; typedef __u_short u_short; typedef __u_int u_int; typedef __u_long u_long; typedef __quad_t quad_t; typedef __u_quad_t u_quad_t; typedef __fsid_t fsid_t; typedef __loff_t loff_t; typedef __ino_t ino_t; # 62 "/usr/include/sys/types.h" 3 4 typedef __dev_t dev_t; typedef __gid_t gid_t; typedef __mode_t mode_t; typedef __nlink_t nlink_t; typedef __uid_t uid_t; typedef __off_t off_t; # 100 "/usr/include/sys/types.h" 3 4 typedef __pid_t pid_t; typedef __id_t id_t; typedef __ssize_t ssize_t; typedef __daddr_t daddr_t; typedef __caddr_t caddr_t; typedef __key_t key_t; # 133 "/usr/include/sys/types.h" 3 4 # 1 "/usr/include/time.h" 1 3 4 # 75 "/usr/include/time.h" 3 4 typedef __time_t time_t; # 93 "/usr/include/time.h" 3 4 typedef __clockid_t clockid_t; # 105 "/usr/include/time.h" 3 4 typedef __timer_t timer_t; # 134 "/usr/include/sys/types.h" 2 3 4 # 147 "/usr/include/sys/types.h" 3 4 # 1 "/usr/lib/gcc/x86_64-redhat-linux/4.1.2/include/stddef.h" 1 3 4 # 148 "/usr/include/sys/types.h" 2 3 4 typedef unsigned long int ulong; typedef unsigned short int ushort; typedef unsigned int uint; # 195 "/usr/include/sys/types.h" 3 4 typedef int int8_t __attribute__ ((__mode__ (__QI__))); typedef int int16_t __attribute__ ((__mode__ (__HI__))); typedef int int32_t __attribute__ ((__mode__ (__SI__))); typedef int int64_t __attribute__ ((__mode__ (__DI__))); typedef unsigned int u_int8_t __attribute__ ((__mode__ (__QI__))); typedef unsigned int u_int16_t __attribute__ ((__mode__ (__HI__))); typedef unsigned int u_int32_t __attribute__ ((__mode__ (__SI__))); typedef unsigned int u_int64_t __attribute__ ((__mode__ (__DI__))); typedef int register_t __attribute__ ((__mode__ (__word__))); # 217 "/usr/include/sys/types.h" 3 4 # 1 "/usr/include/endian.h" 1 3 4 # 37 "/usr/include/endian.h" 3 4 # 1 "/usr/include/bits/endian.h" 1 3 4 # 38 "/usr/include/endian.h" 2 3 4 # 218 "/usr/include/sys/types.h" 2 3 4 # 1 "/usr/include/sys/select.h" 1 3 4 # 31 "/usr/include/sys/select.h" 3 4 # 1 "/usr/include/bits/select.h" 1 3 4 # 32 "/usr/include/sys/select.h" 2 3 4 # 1 "/usr/include/bits/sigset.h" 1 3 4 # 23 "/usr/include/bits/sigset.h" 3 4 typedef int __sig_atomic_t; typedef struct { unsigned long int __val[(1024 / (8 * sizeof (unsigned long int)))]; } __sigset_t; # 35 "/usr/include/sys/select.h" 2 3 4 typedef __sigset_t sigset_t; # 1 "/usr/include/time.h" 1 3 4 # 121 "/usr/include/time.h" 3 4 struct timespec { __time_t tv_sec; long int tv_nsec; }; # 45 "/usr/include/sys/select.h" 2 3 4 # 1 "/usr/include/bits/time.h" 1 3 4 # 69 "/usr/include/bits/time.h" 3 4 struct timeval { __time_t tv_sec; __suseconds_t tv_usec; }; # 47 "/usr/include/sys/select.h" 2 3 4 typedef __suseconds_t suseconds_t; typedef long int __fd_mask; # 67 "/usr/include/sys/select.h" 3 4 typedef struct { __fd_mask __fds_bits[1024 / (8 * sizeof (__fd_mask))]; } fd_set; typedef __fd_mask fd_mask; # 99 "/usr/include/sys/select.h" 3 4 # 109 "/usr/include/sys/select.h" 3 4 extern int select (int __nfds, fd_set *__restrict __readfds, fd_set *__restrict __writefds, fd_set *__restrict __exceptfds, struct timeval *__restrict __timeout); # 121 "/usr/include/sys/select.h" 3 4 extern int pselect (int __nfds, fd_set *__restrict __readfds, fd_set *__restrict __writefds, fd_set *__restrict __exceptfds, const struct timespec *__restrict __timeout, const __sigset_t *__restrict __sigmask); # 221 "/usr/include/sys/types.h" 2 3 4 # 1 "/usr/include/sys/sysmacros.h" 1 3 4 # 29 "/usr/include/sys/sysmacros.h" 3 4 __extension__ extern __inline unsigned int gnu_dev_major (unsigned long long int __dev) __attribute__ ((__nothrow__)); __extension__ extern __inline unsigned int gnu_dev_minor (unsigned long long int __dev) __attribute__ ((__nothrow__)); __extension__ extern __inline unsigned long long int gnu_dev_makedev (unsigned int __major, unsigned int __minor) __attribute__ ((__nothrow__)); __extension__ extern __inline unsigned int __attribute__ ((__nothrow__)) gnu_dev_major (unsigned long long int __dev) { return ((__dev >> 8) & 0xfff) | ((unsigned int) (__dev >> 32) & ~0xfff); } __extension__ extern __inline unsigned int __attribute__ ((__nothrow__)) gnu_dev_minor (unsigned long long int __dev) { return (__dev & 0xff) | ((unsigned int) (__dev >> 12) & ~0xff); } __extension__ extern __inline unsigned long long int __attribute__ ((__nothrow__)) gnu_dev_makedev (unsigned int __major, unsigned int __minor) { return ((__minor & 0xff) | ((__major & 0xfff) << 8) | (((unsigned long long int) (__minor & ~0xff)) << 12) | (((unsigned long long int) (__major & ~0xfff)) << 32)); } # 224 "/usr/include/sys/types.h" 2 3 4 # 235 "/usr/include/sys/types.h" 3 4 typedef __blkcnt_t blkcnt_t; typedef __fsblkcnt_t fsblkcnt_t; typedef __fsfilcnt_t fsfilcnt_t; # 270 "/usr/include/sys/types.h" 3 4 # 1 "/usr/include/bits/pthreadtypes.h" 1 3 4 # 23 "/usr/include/bits/pthreadtypes.h" 3 4 # 1 "/usr/include/bits/wordsize.h" 1 3 4 # 24 "/usr/include/bits/pthreadtypes.h" 2 3 4 # 50 "/usr/include/bits/pthreadtypes.h" 3 4 typedef unsigned long int pthread_t; typedef union { char __size[56]; long int __align; } pthread_attr_t; typedef struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __pthread_list_t; # 76 "/usr/include/bits/pthreadtypes.h" 3 4 typedef union { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; int __spins; __pthread_list_t __list; # 101 "/usr/include/bits/pthreadtypes.h" 3 4 } __data; char __size[40]; long int __align; } pthread_mutex_t; typedef union { char __size[4]; int __align; } pthread_mutexattr_t; typedef union { struct { int __lock; unsigned int __futex; __extension__ unsigned long long int __total_seq; __extension__ unsigned long long int __wakeup_seq; __extension__ unsigned long long int __woken_seq; void *__mutex; unsigned int __nwaiters; unsigned int __broadcast_seq; } __data; char __size[48]; __extension__ long long int __align; } pthread_cond_t; typedef union { char __size[4]; int __align; } pthread_condattr_t; typedef unsigned int pthread_key_t; typedef int pthread_once_t; typedef union { struct { int __lock; unsigned int __nr_readers; unsigned int __readers_wakeup; unsigned int __writer_wakeup; unsigned int __nr_readers_queued; unsigned int __nr_writers_queued; int __writer; int __pad1; unsigned long int __pad2; unsigned long int __pad3; unsigned int __flags; } __data; # 184 "/usr/include/bits/pthreadtypes.h" 3 4 char __size[56]; long int __align; } pthread_rwlock_t; typedef union { char __size[8]; long int __align; } pthread_rwlockattr_t; typedef volatile int pthread_spinlock_t; typedef union { char __size[32]; long int __align; } pthread_barrier_t; typedef union { char __size[4]; int __align; } pthread_barrierattr_t; # 271 "/usr/include/sys/types.h" 2 3 4 # 439 "/usr/include/stdlib.h" 2 3 4 extern long int random (void) __attribute__ ((__nothrow__)); extern void srandom (unsigned int __seed) __attribute__ ((__nothrow__)); extern char *initstate (unsigned int __seed, char *__statebuf, size_t __statelen) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (2))); extern char *setstate (char *__statebuf) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))); struct random_data { int32_t *fptr; int32_t *rptr; int32_t *state; int rand_type; int rand_deg; int rand_sep; int32_t *end_ptr; }; extern int random_r (struct random_data *__restrict __buf, int32_t *__restrict __result) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1, 2))); extern int srandom_r (unsigned int __seed, struct random_data *__buf) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (2))); extern int initstate_r (unsigned int __seed, char *__restrict __statebuf, size_t __statelen, struct random_data *__restrict __buf) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (2, 4))); extern int setstate_r (char *__restrict __statebuf, struct random_data *__restrict __buf) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1, 2))); extern int rand (void) __attribute__ ((__nothrow__)); extern void srand (unsigned int __seed) __attribute__ ((__nothrow__)); extern int rand_r (unsigned int *__seed) __attribute__ ((__nothrow__)); extern double drand48 (void) __attribute__ ((__nothrow__)); extern double erand48 (unsigned short int __xsubi[3]) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))); extern long int lrand48 (void) __attribute__ ((__nothrow__)); extern long int nrand48 (unsigned short int __xsubi[3]) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))); extern long int mrand48 (void) __attribute__ ((__nothrow__)); extern long int jrand48 (unsigned short int __xsubi[3]) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))); extern void srand48 (long int __seedval) __attribute__ ((__nothrow__)); extern unsigned short int *seed48 (unsigned short int __seed16v[3]) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))); extern void lcong48 (unsigned short int __param[7]) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))); struct drand48_data { unsigned short int __x[3]; unsigned short int __old_x[3]; unsigned short int __c; unsigned short int __init; unsigned long long int __a; }; extern int drand48_r (struct drand48_data *__restrict __buffer, double *__restrict __result) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1, 2))); extern int erand48_r (unsigned short int __xsubi[3], struct drand48_data *__restrict __buffer, double *__restrict __result) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1, 2))); extern int lrand48_r (struct drand48_data *__restrict __buffer, long int *__restrict __result) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1, 2))); extern int nrand48_r (unsigned short int __xsubi[3], struct drand48_data *__restrict __buffer, long int *__restrict __result) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1, 2))); extern int mrand48_r (struct drand48_data *__restrict __buffer, long int *__restrict __result) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1, 2))); extern int jrand48_r (unsigned short int __xsubi[3], struct drand48_data *__restrict __buffer, long int *__restrict __result) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1, 2))); extern int srand48_r (long int __seedval, struct drand48_data *__buffer) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (2))); extern int seed48_r (unsigned short int __seed16v[3], struct drand48_data *__buffer) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1, 2))); extern int lcong48_r (unsigned short int __param[7], struct drand48_data *__buffer) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1, 2))); extern void *malloc (size_t __size) __attribute__ ((__nothrow__)) __attribute__ ((__malloc__)) ; extern void *calloc (size_t __nmemb, size_t __size) __attribute__ ((__nothrow__)) __attribute__ ((__malloc__)) ; extern void *realloc (void *__ptr, size_t __size) __attribute__ ((__nothrow__)) __attribute__ ((__malloc__)) __attribute__ ((__warn_unused_result__)); extern void free (void *__ptr) __attribute__ ((__nothrow__)); extern void cfree (void *__ptr) __attribute__ ((__nothrow__)); # 1 "/usr/include/alloca.h" 1 3 4 # 25 "/usr/include/alloca.h" 3 4 # 1 "/usr/lib/gcc/x86_64-redhat-linux/4.1.2/include/stddef.h" 1 3 4 # 26 "/usr/include/alloca.h" 2 3 4 extern void *alloca (size_t __size) __attribute__ ((__nothrow__)); # 613 "/usr/include/stdlib.h" 2 3 4 extern void *valloc (size_t __size) __attribute__ ((__nothrow__)) __attribute__ ((__malloc__)) ; extern int posix_memalign (void **__memptr, size_t __alignment, size_t __size) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))) ; extern void abort (void) __attribute__ ((__nothrow__)) __attribute__ ((__noreturn__)); extern int atexit (void (*__func) (void)) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))); extern int on_exit (void (*__func) (int __status, void *__arg), void *__arg) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))); extern void exit (int __status) __attribute__ ((__nothrow__)) __attribute__ ((__noreturn__)); # 658 "/usr/include/stdlib.h" 3 4 extern char *getenv (__const char *__name) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))) ; extern char *__secure_getenv (__const char *__name) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))) ; extern int putenv (char *__string) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))); extern int setenv (__const char *__name, __const char *__value, int __replace) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (2))); extern int unsetenv (__const char *__name) __attribute__ ((__nothrow__)); extern int clearenv (void) __attribute__ ((__nothrow__)); # 698 "/usr/include/stdlib.h" 3 4 extern char *mktemp (char *__template) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))) ; # 709 "/usr/include/stdlib.h" 3 4 extern int mkstemp (char *__template) __attribute__ ((__nonnull__ (1))) ; # 729 "/usr/include/stdlib.h" 3 4 extern char *mkdtemp (char *__template) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))) ; extern int system (__const char *__command) ; # 756 "/usr/include/stdlib.h" 3 4 extern char *realpath (__const char *__restrict __name, char *__restrict __resolved) __attribute__ ((__nothrow__)) ; typedef int (*__compar_fn_t) (__const void *, __const void *); extern void *bsearch (__const void *__key, __const void *__base, size_t __nmemb, size_t __size, __compar_fn_t __compar) __attribute__ ((__nonnull__ (1, 2, 5))) ; extern void qsort (void *__base, size_t __nmemb, size_t __size, __compar_fn_t __compar) __attribute__ ((__nonnull__ (1, 4))); extern int abs (int __x) __attribute__ ((__nothrow__)) __attribute__ ((__const__)) ; extern long int labs (long int __x) __attribute__ ((__nothrow__)) __attribute__ ((__const__)) ; extern div_t div (int __numer, int __denom) __attribute__ ((__nothrow__)) __attribute__ ((__const__)) ; extern ldiv_t ldiv (long int __numer, long int __denom) __attribute__ ((__nothrow__)) __attribute__ ((__const__)) ; # 821 "/usr/include/stdlib.h" 3 4 extern char *ecvt (double __value, int __ndigit, int *__restrict __decpt, int *__restrict __sign) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (3, 4))) ; extern char *fcvt (double __value, int __ndigit, int *__restrict __decpt, int *__restrict __sign) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (3, 4))) ; extern char *gcvt (double __value, int __ndigit, char *__buf) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (3))) ; extern char *qecvt (long double __value, int __ndigit, int *__restrict __decpt, int *__restrict __sign) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (3, 4))) ; extern char *qfcvt (long double __value, int __ndigit, int *__restrict __decpt, int *__restrict __sign) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (3, 4))) ; extern char *qgcvt (long double __value, int __ndigit, char *__buf) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (3))) ; extern int ecvt_r (double __value, int __ndigit, int *__restrict __decpt, int *__restrict __sign, char *__restrict __buf, size_t __len) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (3, 4, 5))); extern int fcvt_r (double __value, int __ndigit, int *__restrict __decpt, int *__restrict __sign, char *__restrict __buf, size_t __len) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (3, 4, 5))); extern int qecvt_r (long double __value, int __ndigit, int *__restrict __decpt, int *__restrict __sign, char *__restrict __buf, size_t __len) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (3, 4, 5))); extern int qfcvt_r (long double __value, int __ndigit, int *__restrict __decpt, int *__restrict __sign, char *__restrict __buf, size_t __len) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (3, 4, 5))); extern int mblen (__const char *__s, size_t __n) __attribute__ ((__nothrow__)) ; extern int mbtowc (wchar_t *__restrict __pwc, __const char *__restrict __s, size_t __n) __attribute__ ((__nothrow__)) ; extern int wctomb (char *__s, wchar_t __wchar) __attribute__ ((__nothrow__)) ; extern size_t mbstowcs (wchar_t *__restrict __pwcs, __const char *__restrict __s, size_t __n) __attribute__ ((__nothrow__)); extern size_t wcstombs (char *__restrict __s, __const wchar_t *__restrict __pwcs, size_t __n) __attribute__ ((__nothrow__)); extern int rpmatch (__const char *__response) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))) ; # 926 "/usr/include/stdlib.h" 3 4 extern int posix_openpt (int __oflag) ; # 961 "/usr/include/stdlib.h" 3 4 extern int getloadavg (double __loadavg[], int __nelem) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))); # 977 "/usr/include/stdlib.h" 3 4 # 346 "triangle.c" 2 # 1 "/usr/include/string.h" 1 3 4 # 28 "/usr/include/string.h" 3 4 # 1 "/usr/lib/gcc/x86_64-redhat-linux/4.1.2/include/stddef.h" 1 3 4 # 34 "/usr/include/string.h" 2 3 4 extern void *memcpy (void *__restrict __dest, __const void *__restrict __src, size_t __n) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1, 2))); extern void *memmove (void *__dest, __const void *__src, size_t __n) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1, 2))); extern void *memccpy (void *__restrict __dest, __const void *__restrict __src, int __c, size_t __n) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1, 2))); extern void *memset (void *__s, int __c, size_t __n) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))); extern int memcmp (__const void *__s1, __const void *__s2, size_t __n) __attribute__ ((__nothrow__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2))); extern void *memchr (__const void *__s, int __c, size_t __n) __attribute__ ((__nothrow__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1))); # 82 "/usr/include/string.h" 3 4 extern char *strcpy (char *__restrict __dest, __const char *__restrict __src) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1, 2))); extern char *strncpy (char *__restrict __dest, __const char *__restrict __src, size_t __n) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1, 2))); extern char *strcat (char *__restrict __dest, __const char *__restrict __src) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1, 2))); extern char *strncat (char *__restrict __dest, __const char *__restrict __src, size_t __n) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1, 2))); extern int strcmp (__const char *__s1, __const char *__s2) __attribute__ ((__nothrow__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2))); extern int strncmp (__const char *__s1, __const char *__s2, size_t __n) __attribute__ ((__nothrow__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2))); extern int strcoll (__const char *__s1, __const char *__s2) __attribute__ ((__nothrow__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2))); extern size_t strxfrm (char *__restrict __dest, __const char *__restrict __src, size_t __n) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (2))); # 130 "/usr/include/string.h" 3 4 extern char *strdup (__const char *__s) __attribute__ ((__nothrow__)) __attribute__ ((__malloc__)) __attribute__ ((__nonnull__ (1))); # 165 "/usr/include/string.h" 3 4 extern char *strchr (__const char *__s, int __c) __attribute__ ((__nothrow__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1))); extern char *strrchr (__const char *__s, int __c) __attribute__ ((__nothrow__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1))); # 181 "/usr/include/string.h" 3 4 extern size_t strcspn (__const char *__s, __const char *__reject) __attribute__ ((__nothrow__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2))); extern size_t strspn (__const char *__s, __const char *__accept) __attribute__ ((__nothrow__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2))); extern char *strpbrk (__const char *__s, __const char *__accept) __attribute__ ((__nothrow__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2))); extern char *strstr (__const char *__haystack, __const char *__needle) __attribute__ ((__nothrow__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2))); extern char *strtok (char *__restrict __s, __const char *__restrict __delim) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (2))); extern char *__strtok_r (char *__restrict __s, __const char *__restrict __delim, char **__restrict __save_ptr) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (2, 3))); extern char *strtok_r (char *__restrict __s, __const char *__restrict __delim, char **__restrict __save_ptr) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (2, 3))); # 240 "/usr/include/string.h" 3 4 extern size_t strlen (__const char *__s) __attribute__ ((__nothrow__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1))); # 254 "/usr/include/string.h" 3 4 extern char *strerror (int __errnum) __attribute__ ((__nothrow__)); # 270 "/usr/include/string.h" 3 4 extern int strerror_r (int __errnum, char *__buf, size_t __buflen) __asm__ ("" "__xpg_strerror_r") __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (2))); # 288 "/usr/include/string.h" 3 4 extern void __bzero (void *__s, size_t __n) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))); extern void bcopy (__const void *__src, void *__dest, size_t __n) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1, 2))); extern void bzero (void *__s, size_t __n) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))); extern int bcmp (__const void *__s1, __const void *__s2, size_t __n) __attribute__ ((__nothrow__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2))); extern char *index (__const char *__s, int __c) __attribute__ ((__nothrow__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1))); extern char *rindex (__const char *__s, int __c) __attribute__ ((__nothrow__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1))); extern int ffs (int __i) __attribute__ ((__nothrow__)) __attribute__ ((__const__)); # 325 "/usr/include/string.h" 3 4 extern int strcasecmp (__const char *__s1, __const char *__s2) __attribute__ ((__nothrow__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2))); extern int strncasecmp (__const char *__s1, __const char *__s2, size_t __n) __attribute__ ((__nothrow__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2))); # 348 "/usr/include/string.h" 3 4 extern char *strsep (char **__restrict __stringp, __const char *__restrict __delim) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1, 2))); # 426 "/usr/include/string.h" 3 4 # 347 "triangle.c" 2 # 1 "/usr/include/math.h" 1 3 4 # 30 "/usr/include/math.h" 3 4 # 1 "/usr/include/bits/huge_val.h" 1 3 4 # 35 "/usr/include/math.h" 2 3 4 # 47 "/usr/include/math.h" 3 4 # 1 "/usr/include/bits/mathdef.h" 1 3 4 # 48 "/usr/include/math.h" 2 3 4 # 71 "/usr/include/math.h" 3 4 # 1 "/usr/include/bits/mathcalls.h" 1 3 4 # 53 "/usr/include/bits/mathcalls.h" 3 4 extern double acos (double __x) __attribute__ ((__nothrow__)); extern double __acos (double __x) __attribute__ ((__nothrow__)); extern double asin (double __x) __attribute__ ((__nothrow__)); extern double __asin (double __x) __attribute__ ((__nothrow__)); extern double atan (double __x) __attribute__ ((__nothrow__)); extern double __atan (double __x) __attribute__ ((__nothrow__)); extern double atan2 (double __y, double __x) __attribute__ ((__nothrow__)); extern double __atan2 (double __y, double __x) __attribute__ ((__nothrow__)); extern double cos (double __x) __attribute__ ((__nothrow__)); extern double __cos (double __x) __attribute__ ((__nothrow__)); extern double sin (double __x) __attribute__ ((__nothrow__)); extern double __sin (double __x) __attribute__ ((__nothrow__)); extern double tan (double __x) __attribute__ ((__nothrow__)); extern double __tan (double __x) __attribute__ ((__nothrow__)); extern double cosh (double __x) __attribute__ ((__nothrow__)); extern double __cosh (double __x) __attribute__ ((__nothrow__)); extern double sinh (double __x) __attribute__ ((__nothrow__)); extern double __sinh (double __x) __attribute__ ((__nothrow__)); extern double tanh (double __x) __attribute__ ((__nothrow__)); extern double __tanh (double __x) __attribute__ ((__nothrow__)); # 87 "/usr/include/bits/mathcalls.h" 3 4 extern double acosh (double __x) __attribute__ ((__nothrow__)); extern double __acosh (double __x) __attribute__ ((__nothrow__)); extern double asinh (double __x) __attribute__ ((__nothrow__)); extern double __asinh (double __x) __attribute__ ((__nothrow__)); extern double atanh (double __x) __attribute__ ((__nothrow__)); extern double __atanh (double __x) __attribute__ ((__nothrow__)); extern double exp (double __x) __attribute__ ((__nothrow__)); extern double __exp (double __x) __attribute__ ((__nothrow__)); extern double frexp (double __x, int *__exponent) __attribute__ ((__nothrow__)); extern double __frexp (double __x, int *__exponent) __attribute__ ((__nothrow__)); extern double ldexp (double __x, int __exponent) __attribute__ ((__nothrow__)); extern double __ldexp (double __x, int __exponent) __attribute__ ((__nothrow__)); extern double log (double __x) __attribute__ ((__nothrow__)); extern double __log (double __x) __attribute__ ((__nothrow__)); extern double log10 (double __x) __attribute__ ((__nothrow__)); extern double __log10 (double __x) __attribute__ ((__nothrow__)); extern double modf (double __x, double *__iptr) __attribute__ ((__nothrow__)); extern double __modf (double __x, double *__iptr) __attribute__ ((__nothrow__)); # 127 "/usr/include/bits/mathcalls.h" 3 4 extern double expm1 (double __x) __attribute__ ((__nothrow__)); extern double __expm1 (double __x) __attribute__ ((__nothrow__)); extern double log1p (double __x) __attribute__ ((__nothrow__)); extern double __log1p (double __x) __attribute__ ((__nothrow__)); extern double logb (double __x) __attribute__ ((__nothrow__)); extern double __logb (double __x) __attribute__ ((__nothrow__)); # 152 "/usr/include/bits/mathcalls.h" 3 4 extern double pow (double __x, double __y) __attribute__ ((__nothrow__)); extern double __pow (double __x, double __y) __attribute__ ((__nothrow__)); extern double sqrt (double __x) __attribute__ ((__nothrow__)); extern double __sqrt (double __x) __attribute__ ((__nothrow__)); extern double hypot (double __x, double __y) __attribute__ ((__nothrow__)); extern double __hypot (double __x, double __y) __attribute__ ((__nothrow__)); extern double cbrt (double __x) __attribute__ ((__nothrow__)); extern double __cbrt (double __x) __attribute__ ((__nothrow__)); extern double ceil (double __x) __attribute__ ((__nothrow__)) __attribute__ ((__const__)); extern double __ceil (double __x) __attribute__ ((__nothrow__)) __attribute__ ((__const__)); extern double fabs (double __x) __attribute__ ((__nothrow__)) __attribute__ ((__const__)); extern double __fabs (double __x) __attribute__ ((__nothrow__)) __attribute__ ((__const__)); extern double floor (double __x) __attribute__ ((__nothrow__)) __attribute__ ((__const__)); extern double __floor (double __x) __attribute__ ((__nothrow__)) __attribute__ ((__const__)); extern double fmod (double __x, double __y) __attribute__ ((__nothrow__)); extern double __fmod (double __x, double __y) __attribute__ ((__nothrow__)); extern int __isinf (double __value) __attribute__ ((__nothrow__)) __attribute__ ((__const__)); extern int __finite (double __value) __attribute__ ((__nothrow__)) __attribute__ ((__const__)); extern int isinf (double __value) __attribute__ ((__nothrow__)) __attribute__ ((__const__)); extern int finite (double __value) __attribute__ ((__nothrow__)) __attribute__ ((__const__)); extern double drem (double __x, double __y) __attribute__ ((__nothrow__)); extern double __drem (double __x, double __y) __attribute__ ((__nothrow__)); extern double significand (double __x) __attribute__ ((__nothrow__)); extern double __significand (double __x) __attribute__ ((__nothrow__)); extern double copysign (double __x, double __y) __attribute__ ((__nothrow__)) __attribute__ ((__const__)); extern double __copysign (double __x, double __y) __attribute__ ((__nothrow__)) __attribute__ ((__const__)); # 231 "/usr/include/bits/mathcalls.h" 3 4 extern int __isnan (double __value) __attribute__ ((__nothrow__)) __attribute__ ((__const__)); extern int isnan (double __value) __attribute__ ((__nothrow__)) __attribute__ ((__const__)); extern double j0 (double) __attribute__ ((__nothrow__)); extern double __j0 (double) __attribute__ ((__nothrow__)); extern double j1 (double) __attribute__ ((__nothrow__)); extern double __j1 (double) __attribute__ ((__nothrow__)); extern double jn (int, double) __attribute__ ((__nothrow__)); extern double __jn (int, double) __attribute__ ((__nothrow__)); extern double y0 (double) __attribute__ ((__nothrow__)); extern double __y0 (double) __attribute__ ((__nothrow__)); extern double y1 (double) __attribute__ ((__nothrow__)); extern double __y1 (double) __attribute__ ((__nothrow__)); extern double yn (int, double) __attribute__ ((__nothrow__)); extern double __yn (int, double) __attribute__ ((__nothrow__)); extern double erf (double) __attribute__ ((__nothrow__)); extern double __erf (double) __attribute__ ((__nothrow__)); extern double erfc (double) __attribute__ ((__nothrow__)); extern double __erfc (double) __attribute__ ((__nothrow__)); extern double lgamma (double) __attribute__ ((__nothrow__)); extern double __lgamma (double) __attribute__ ((__nothrow__)); # 265 "/usr/include/bits/mathcalls.h" 3 4 extern double gamma (double) __attribute__ ((__nothrow__)); extern double __gamma (double) __attribute__ ((__nothrow__)); extern double lgamma_r (double, int *__signgamp) __attribute__ ((__nothrow__)); extern double __lgamma_r (double, int *__signgamp) __attribute__ ((__nothrow__)); extern double rint (double __x) __attribute__ ((__nothrow__)); extern double __rint (double __x) __attribute__ ((__nothrow__)); extern double nextafter (double __x, double __y) __attribute__ ((__nothrow__)) __attribute__ ((__const__)); extern double __nextafter (double __x, double __y) __attribute__ ((__nothrow__)) __attribute__ ((__const__)); extern double remainder (double __x, double __y) __attribute__ ((__nothrow__)); extern double __remainder (double __x, double __y) __attribute__ ((__nothrow__)); extern double scalbn (double __x, int __n) __attribute__ ((__nothrow__)); extern double __scalbn (double __x, int __n) __attribute__ ((__nothrow__)); extern int ilogb (double __x) __attribute__ ((__nothrow__)); extern int __ilogb (double __x) __attribute__ ((__nothrow__)); # 359 "/usr/include/bits/mathcalls.h" 3 4 extern double scalb (double __x, double __n) __attribute__ ((__nothrow__)); extern double __scalb (double __x, double __n) __attribute__ ((__nothrow__)); # 72 "/usr/include/math.h" 2 3 4 # 94 "/usr/include/math.h" 3 4 # 1 "/usr/include/bits/mathcalls.h" 1 3 4 # 53 "/usr/include/bits/mathcalls.h" 3 4 extern float acosf (float __x) __attribute__ ((__nothrow__)); extern float __acosf (float __x) __attribute__ ((__nothrow__)); extern float asinf (float __x) __attribute__ ((__nothrow__)); extern float __asinf (float __x) __attribute__ ((__nothrow__)); extern float atanf (float __x) __attribute__ ((__nothrow__)); extern float __atanf (float __x) __attribute__ ((__nothrow__)); extern float atan2f (float __y, float __x) __attribute__ ((__nothrow__)); extern float __atan2f (float __y, float __x) __attribute__ ((__nothrow__)); extern float cosf (float __x) __attribute__ ((__nothrow__)); extern float __cosf (float __x) __attribute__ ((__nothrow__)); extern float sinf (float __x) __attribute__ ((__nothrow__)); extern float __sinf (float __x) __attribute__ ((__nothrow__)); extern float tanf (float __x) __attribute__ ((__nothrow__)); extern float __tanf (float __x) __attribute__ ((__nothrow__)); extern float coshf (float __x) __attribute__ ((__nothrow__)); extern float __coshf (float __x) __attribute__ ((__nothrow__)); extern float sinhf (float __x) __attribute__ ((__nothrow__)); extern float __sinhf (float __x) __attribute__ ((__nothrow__)); extern float tanhf (float __x) __attribute__ ((__nothrow__)); extern float __tanhf (float __x) __attribute__ ((__nothrow__)); # 87 "/usr/include/bits/mathcalls.h" 3 4 extern float acoshf (float __x) __attribute__ ((__nothrow__)); extern float __acoshf (float __x) __attribute__ ((__nothrow__)); extern float asinhf (float __x) __attribute__ ((__nothrow__)); extern float __asinhf (float __x) __attribute__ ((__nothrow__)); extern float atanhf (float __x) __attribute__ ((__nothrow__)); extern float __atanhf (float __x) __attribute__ ((__nothrow__)); extern float expf (float __x) __attribute__ ((__nothrow__)); extern float __expf (float __x) __attribute__ ((__nothrow__)); extern float frexpf (float __x, int *__exponent) __attribute__ ((__nothrow__)); extern float __frexpf (float __x, int *__exponent) __attribute__ ((__nothrow__)); extern float ldexpf (float __x, int __exponent) __attribute__ ((__nothrow__)); extern float __ldexpf (float __x, int __exponent) __attribute__ ((__nothrow__)); extern float logf (float __x) __attribute__ ((__nothrow__)); extern float __logf (float __x) __attribute__ ((__nothrow__)); extern float log10f (float __x) __attribute__ ((__nothrow__)); extern float __log10f (float __x) __attribute__ ((__nothrow__)); extern float modff (float __x, float *__iptr) __attribute__ ((__nothrow__)); extern float __modff (float __x, float *__iptr) __attribute__ ((__nothrow__)); # 127 "/usr/include/bits/mathcalls.h" 3 4 extern float expm1f (float __x) __attribute__ ((__nothrow__)); extern float __expm1f (float __x) __attribute__ ((__nothrow__)); extern float log1pf (float __x) __attribute__ ((__nothrow__)); extern float __log1pf (float __x) __attribute__ ((__nothrow__)); extern float logbf (float __x) __attribute__ ((__nothrow__)); extern float __logbf (float __x) __attribute__ ((__nothrow__)); # 152 "/usr/include/bits/mathcalls.h" 3 4 extern float powf (float __x, float __y) __attribute__ ((__nothrow__)); extern float __powf (float __x, float __y) __attribute__ ((__nothrow__)); extern float sqrtf (float __x) __attribute__ ((__nothrow__)); extern float __sqrtf (float __x) __attribute__ ((__nothrow__)); extern float hypotf (float __x, float __y) __attribute__ ((__nothrow__)); extern float __hypotf (float __x, float __y) __attribute__ ((__nothrow__)); extern float cbrtf (float __x) __attribute__ ((__nothrow__)); extern float __cbrtf (float __x) __attribute__ ((__nothrow__)); extern float ceilf (float __x) __attribute__ ((__nothrow__)) __attribute__ ((__const__)); extern float __ceilf (float __x) __attribute__ ((__nothrow__)) __attribute__ ((__const__)); extern float fabsf (float __x) __attribute__ ((__nothrow__)) __attribute__ ((__const__)); extern float __fabsf (float __x) __attribute__ ((__nothrow__)) __attribute__ ((__const__)); extern float floorf (float __x) __attribute__ ((__nothrow__)) __attribute__ ((__const__)); extern float __floorf (float __x) __attribute__ ((__nothrow__)) __attribute__ ((__const__)); extern float fmodf (float __x, float __y) __attribute__ ((__nothrow__)); extern float __fmodf (float __x, float __y) __attribute__ ((__nothrow__)); extern int __isinff (float __value) __attribute__ ((__nothrow__)) __attribute__ ((__const__)); extern int __finitef (float __value) __attribute__ ((__nothrow__)) __attribute__ ((__const__)); extern int isinff (float __value) __attribute__ ((__nothrow__)) __attribute__ ((__const__)); extern int finitef (float __value) __attribute__ ((__nothrow__)) __attribute__ ((__const__)); extern float dremf (float __x, float __y) __attribute__ ((__nothrow__)); extern float __dremf (float __x, float __y) __attribute__ ((__nothrow__)); extern float significandf (float __x) __attribute__ ((__nothrow__)); extern float __significandf (float __x) __attribute__ ((__nothrow__)); extern float copysignf (float __x, float __y) __attribute__ ((__nothrow__)) __attribute__ ((__const__)); extern float __copysignf (float __x, float __y) __attribute__ ((__nothrow__)) __attribute__ ((__const__)); # 231 "/usr/include/bits/mathcalls.h" 3 4 extern int __isnanf (float __value) __attribute__ ((__nothrow__)) __attribute__ ((__const__)); extern int isnanf (float __value) __attribute__ ((__nothrow__)) __attribute__ ((__const__)); extern float j0f (float) __attribute__ ((__nothrow__)); extern float __j0f (float) __attribute__ ((__nothrow__)); extern float j1f (float) __attribute__ ((__nothrow__)); extern float __j1f (float) __attribute__ ((__nothrow__)); extern float jnf (int, float) __attribute__ ((__nothrow__)); extern float __jnf (int, float) __attribute__ ((__nothrow__)); extern float y0f (float) __attribute__ ((__nothrow__)); extern float __y0f (float) __attribute__ ((__nothrow__)); extern float y1f (float) __attribute__ ((__nothrow__)); extern float __y1f (float) __attribute__ ((__nothrow__)); extern float ynf (int, float) __attribute__ ((__nothrow__)); extern float __ynf (int, float) __attribute__ ((__nothrow__)); extern float erff (float) __attribute__ ((__nothrow__)); extern float __erff (float) __attribute__ ((__nothrow__)); extern float erfcf (float) __attribute__ ((__nothrow__)); extern float __erfcf (float) __attribute__ ((__nothrow__)); extern float lgammaf (float) __attribute__ ((__nothrow__)); extern float __lgammaf (float) __attribute__ ((__nothrow__)); # 265 "/usr/include/bits/mathcalls.h" 3 4 extern float gammaf (float) __attribute__ ((__nothrow__)); extern float __gammaf (float) __attribute__ ((__nothrow__)); extern float lgammaf_r (float, int *__signgamp) __attribute__ ((__nothrow__)); extern float __lgammaf_r (float, int *__signgamp) __attribute__ ((__nothrow__)); extern float rintf (float __x) __attribute__ ((__nothrow__)); extern float __rintf (float __x) __attribute__ ((__nothrow__)); extern float nextafterf (float __x, float __y) __attribute__ ((__nothrow__)) __attribute__ ((__const__)); extern float __nextafterf (float __x, float __y) __attribute__ ((__nothrow__)) __attribute__ ((__const__)); extern float remainderf (float __x, float __y) __attribute__ ((__nothrow__)); extern float __remainderf (float __x, float __y) __attribute__ ((__nothrow__)); extern float scalbnf (float __x, int __n) __attribute__ ((__nothrow__)); extern float __scalbnf (float __x, int __n) __attribute__ ((__nothrow__)); extern int ilogbf (float __x) __attribute__ ((__nothrow__)); extern int __ilogbf (float __x) __attribute__ ((__nothrow__)); # 359 "/usr/include/bits/mathcalls.h" 3 4 extern float scalbf (float __x, float __n) __attribute__ ((__nothrow__)); extern float __scalbf (float __x, float __n) __attribute__ ((__nothrow__)); # 95 "/usr/include/math.h" 2 3 4 # 141 "/usr/include/math.h" 3 4 # 1 "/usr/include/bits/mathcalls.h" 1 3 4 # 53 "/usr/include/bits/mathcalls.h" 3 4 extern long double acosl (long double __x) __attribute__ ((__nothrow__)); extern long double __acosl (long double __x) __attribute__ ((__nothrow__)); extern long double asinl (long double __x) __attribute__ ((__nothrow__)); extern long double __asinl (long double __x) __attribute__ ((__nothrow__)); extern long double atanl (long double __x) __attribute__ ((__nothrow__)); extern long double __atanl (long double __x) __attribute__ ((__nothrow__)); extern long double atan2l (long double __y, long double __x) __attribute__ ((__nothrow__)); extern long double __atan2l (long double __y, long double __x) __attribute__ ((__nothrow__)); extern long double cosl (long double __x) __attribute__ ((__nothrow__)); extern long double __cosl (long double __x) __attribute__ ((__nothrow__)); extern long double sinl (long double __x) __attribute__ ((__nothrow__)); extern long double __sinl (long double __x) __attribute__ ((__nothrow__)); extern long double tanl (long double __x) __attribute__ ((__nothrow__)); extern long double __tanl (long double __x) __attribute__ ((__nothrow__)); extern long double coshl (long double __x) __attribute__ ((__nothrow__)); extern long double __coshl (long double __x) __attribute__ ((__nothrow__)); extern long double sinhl (long double __x) __attribute__ ((__nothrow__)); extern long double __sinhl (long double __x) __attribute__ ((__nothrow__)); extern long double tanhl (long double __x) __attribute__ ((__nothrow__)); extern long double __tanhl (long double __x) __attribute__ ((__nothrow__)); # 87 "/usr/include/bits/mathcalls.h" 3 4 extern long double acoshl (long double __x) __attribute__ ((__nothrow__)); extern long double __acoshl (long double __x) __attribute__ ((__nothrow__)); extern long double asinhl (long double __x) __attribute__ ((__nothrow__)); extern long double __asinhl (long double __x) __attribute__ ((__nothrow__)); extern long double atanhl (long double __x) __attribute__ ((__nothrow__)); extern long double __atanhl (long double __x) __attribute__ ((__nothrow__)); extern long double expl (long double __x) __attribute__ ((__nothrow__)); extern long double __expl (long double __x) __attribute__ ((__nothrow__)); extern long double frexpl (long double __x, int *__exponent) __attribute__ ((__nothrow__)); extern long double __frexpl (long double __x, int *__exponent) __attribute__ ((__nothrow__)); extern long double ldexpl (long double __x, int __exponent) __attribute__ ((__nothrow__)); extern long double __ldexpl (long double __x, int __exponent) __attribute__ ((__nothrow__)); extern long double logl (long double __x) __attribute__ ((__nothrow__)); extern long double __logl (long double __x) __attribute__ ((__nothrow__)); extern long double log10l (long double __x) __attribute__ ((__nothrow__)); extern long double __log10l (long double __x) __attribute__ ((__nothrow__)); extern long double modfl (long double __x, long double *__iptr) __attribute__ ((__nothrow__)); extern long double __modfl (long double __x, long double *__iptr) __attribute__ ((__nothrow__)); # 127 "/usr/include/bits/mathcalls.h" 3 4 extern long double expm1l (long double __x) __attribute__ ((__nothrow__)); extern long double __expm1l (long double __x) __attribute__ ((__nothrow__)); extern long double log1pl (long double __x) __attribute__ ((__nothrow__)); extern long double __log1pl (long double __x) __attribute__ ((__nothrow__)); extern long double logbl (long double __x) __attribute__ ((__nothrow__)); extern long double __logbl (long double __x) __attribute__ ((__nothrow__)); # 152 "/usr/include/bits/mathcalls.h" 3 4 extern long double powl (long double __x, long double __y) __attribute__ ((__nothrow__)); extern long double __powl (long double __x, long double __y) __attribute__ ((__nothrow__)); extern long double sqrtl (long double __x) __attribute__ ((__nothrow__)); extern long double __sqrtl (long double __x) __attribute__ ((__nothrow__)); extern long double hypotl (long double __x, long double __y) __attribute__ ((__nothrow__)); extern long double __hypotl (long double __x, long double __y) __attribute__ ((__nothrow__)); extern long double cbrtl (long double __x) __attribute__ ((__nothrow__)); extern long double __cbrtl (long double __x) __attribute__ ((__nothrow__)); extern long double ceill (long double __x) __attribute__ ((__nothrow__)) __attribute__ ((__const__)); extern long double __ceill (long double __x) __attribute__ ((__nothrow__)) __attribute__ ((__const__)); extern long double fabsl (long double __x) __attribute__ ((__nothrow__)) __attribute__ ((__const__)); extern long double __fabsl (long double __x) __attribute__ ((__nothrow__)) __attribute__ ((__const__)); extern long double floorl (long double __x) __attribute__ ((__nothrow__)) __attribute__ ((__const__)); extern long double __floorl (long double __x) __attribute__ ((__nothrow__)) __attribute__ ((__const__)); extern long double fmodl (long double __x, long double __y) __attribute__ ((__nothrow__)); extern long double __fmodl (long double __x, long double __y) __attribute__ ((__nothrow__)); extern int __isinfl (long double __value) __attribute__ ((__nothrow__)) __attribute__ ((__const__)); extern int __finitel (long double __value) __attribute__ ((__nothrow__)) __attribute__ ((__const__)); extern int isinfl (long double __value) __attribute__ ((__nothrow__)) __attribute__ ((__const__)); extern int finitel (long double __value) __attribute__ ((__nothrow__)) __attribute__ ((__const__)); extern long double dreml (long double __x, long double __y) __attribute__ ((__nothrow__)); extern long double __dreml (long double __x, long double __y) __attribute__ ((__nothrow__)); extern long double significandl (long double __x) __attribute__ ((__nothrow__)); extern long double __significandl (long double __x) __attribute__ ((__nothrow__)); extern long double copysignl (long double __x, long double __y) __attribute__ ((__nothrow__)) __attribute__ ((__const__)); extern long double __copysignl (long double __x, long double __y) __attribute__ ((__nothrow__)) __attribute__ ((__const__)); # 231 "/usr/include/bits/mathcalls.h" 3 4 extern int __isnanl (long double __value) __attribute__ ((__nothrow__)) __attribute__ ((__const__)); extern int isnanl (long double __value) __attribute__ ((__nothrow__)) __attribute__ ((__const__)); extern long double j0l (long double) __attribute__ ((__nothrow__)); extern long double __j0l (long double) __attribute__ ((__nothrow__)); extern long double j1l (long double) __attribute__ ((__nothrow__)); extern long double __j1l (long double) __attribute__ ((__nothrow__)); extern long double jnl (int, long double) __attribute__ ((__nothrow__)); extern long double __jnl (int, long double) __attribute__ ((__nothrow__)); extern long double y0l (long double) __attribute__ ((__nothrow__)); extern long double __y0l (long double) __attribute__ ((__nothrow__)); extern long double y1l (long double) __attribute__ ((__nothrow__)); extern long double __y1l (long double) __attribute__ ((__nothrow__)); extern long double ynl (int, long double) __attribute__ ((__nothrow__)); extern long double __ynl (int, long double) __attribute__ ((__nothrow__)); extern long double erfl (long double) __attribute__ ((__nothrow__)); extern long double __erfl (long double) __attribute__ ((__nothrow__)); extern long double erfcl (long double) __attribute__ ((__nothrow__)); extern long double __erfcl (long double) __attribute__ ((__nothrow__)); extern long double lgammal (long double) __attribute__ ((__nothrow__)); extern long double __lgammal (long double) __attribute__ ((__nothrow__)); # 265 "/usr/include/bits/mathcalls.h" 3 4 extern long double gammal (long double) __attribute__ ((__nothrow__)); extern long double __gammal (long double) __attribute__ ((__nothrow__)); extern long double lgammal_r (long double, int *__signgamp) __attribute__ ((__nothrow__)); extern long double __lgammal_r (long double, int *__signgamp) __attribute__ ((__nothrow__)); extern long double rintl (long double __x) __attribute__ ((__nothrow__)); extern long double __rintl (long double __x) __attribute__ ((__nothrow__)); extern long double nextafterl (long double __x, long double __y) __attribute__ ((__nothrow__)) __attribute__ ((__const__)); extern long double __nextafterl (long double __x, long double __y) __attribute__ ((__nothrow__)) __attribute__ ((__const__)); extern long double remainderl (long double __x, long double __y) __attribute__ ((__nothrow__)); extern long double __remainderl (long double __x, long double __y) __attribute__ ((__nothrow__)); extern long double scalbnl (long double __x, int __n) __attribute__ ((__nothrow__)); extern long double __scalbnl (long double __x, int __n) __attribute__ ((__nothrow__)); extern int ilogbl (long double __x) __attribute__ ((__nothrow__)); extern int __ilogbl (long double __x) __attribute__ ((__nothrow__)); # 359 "/usr/include/bits/mathcalls.h" 3 4 extern long double scalbl (long double __x, long double __n) __attribute__ ((__nothrow__)); extern long double __scalbl (long double __x, long double __n) __attribute__ ((__nothrow__)); # 142 "/usr/include/math.h" 2 3 4 # 157 "/usr/include/math.h" 3 4 extern int signgam; # 284 "/usr/include/math.h" 3 4 typedef enum { _IEEE_ = -1, _SVID_, _XOPEN_, _POSIX_, _ISOC_ } _LIB_VERSION_TYPE; extern _LIB_VERSION_TYPE _LIB_VERSION; # 309 "/usr/include/math.h" 3 4 struct exception { int type; char *name; double arg1; double arg2; double retval; }; extern int matherr (struct exception *__exc); # 465 "/usr/include/math.h" 3 4 # 348 "triangle.c" 2 # 1 "config.h" 1 # 349 "triangle.c" 2 # 1 "/usr/include/sys/time.h" 1 3 4 # 27 "/usr/include/sys/time.h" 3 4 # 1 "/usr/include/time.h" 1 3 4 # 28 "/usr/include/sys/time.h" 2 3 4 # 1 "/usr/include/bits/time.h" 1 3 4 # 30 "/usr/include/sys/time.h" 2 3 4 # 39 "/usr/include/sys/time.h" 3 4 # 57 "/usr/include/sys/time.h" 3 4 struct timezone { int tz_minuteswest; int tz_dsttime; }; typedef struct timezone *__restrict __timezone_ptr_t; # 73 "/usr/include/sys/time.h" 3 4 extern int gettimeofday (struct timeval *__restrict __tv, __timezone_ptr_t __tz) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))); extern int settimeofday (__const struct timeval *__tv, __const struct timezone *__tz) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))); extern int adjtime (__const struct timeval *__delta, struct timeval *__olddelta) __attribute__ ((__nothrow__)); enum __itimer_which { ITIMER_REAL = 0, ITIMER_VIRTUAL = 1, ITIMER_PROF = 2 }; struct itimerval { struct timeval it_interval; struct timeval it_value; }; typedef int __itimer_which_t; extern int getitimer (__itimer_which_t __which, struct itimerval *__value) __attribute__ ((__nothrow__)); extern int setitimer (__itimer_which_t __which, __const struct itimerval *__restrict __new, struct itimerval *__restrict __old) __attribute__ ((__nothrow__)); extern int utimes (__const char *__file, __const struct timeval __tvp[2]) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))); extern int lutimes (__const char *__file, __const struct timeval __tvp[2]) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))); extern int futimes (int __fd, __const struct timeval __tvp[2]) __attribute__ ((__nothrow__)); # 191 "/usr/include/sys/time.h" 3 4 # 351 "triangle.c" 2 # 359 "triangle.c" # 1 "triangle.h" 1 # 252 "triangle.h" struct triangulateio { double *pointlist; double *pointattributelist; int *pointmarkerlist; int numberofpoints; int numberofpointattributes; int *trianglelist; double *triangleattributelist; double *trianglearealist; int *neighborlist; int numberoftriangles; int numberofcorners; int numberoftriangleattributes; int *segmentlist; int *segmentmarkerlist; int numberofsegments; double *holelist; int numberofholes; double *regionlist; int numberofregions; int *edgelist; int *edgemarkerlist; double *normlist; int numberofedges; }; void triangulate(); # 360 "triangle.c" 2 # 372 "triangle.c" enum wordtype {POINTER, FLOATINGPOINT}; enum locateresult {INTRIANGLE, ONEDGE, ONVERTEX, OUTSIDE}; enum insertvertexresult {SUCCESSFULVERTEX, ENCROACHINGVERTEX, VIOLATINGVERTEX, DUPLICATEVERTEX}; enum finddirectionresult {WITHIN, LEFTCOLLINEAR, RIGHTCOLLINEAR}; # 512 "triangle.c" typedef double **triangle; struct otri { triangle *tri; int orient; }; typedef double **subseg; struct osub { subseg *ss; int ssorient; }; typedef double *vertex; struct badsubseg { subseg encsubseg; vertex subsegorg, subsegdest; }; struct badtriang { triangle poortri; double key; vertex triangorg, triangdest, triangapex; struct badtriang *nexttriang; }; struct flipstacker { triangle flippedtri; struct flipstacker *prevflip; }; # 585 "triangle.c" struct event { double xkey, ykey; int *eventptr; int heapposition; }; # 602 "triangle.c" struct splaynode { struct otri keyedge; vertex keydest; struct splaynode *lchild, *rchild; }; # 632 "triangle.c" struct memorypool { int **firstblock, **nowblock; int *nextitem; int *deaditemstack; int **pathblock; int *pathitem; enum wordtype itemwordtype; int alignbytes; int itembytes, itemwords; int itemsperblock; long items, maxitems; int unallocateditems; int pathitemsleft; }; double splitter; double epsilon; double resulterrbound; double ccwerrboundA, ccwerrboundB, ccwerrboundC; double iccerrboundA, iccerrboundB, iccerrboundC; double o3derrboundA, o3derrboundB, o3derrboundC; unsigned long randomseed; struct mesh { struct memorypool triangles; struct memorypool subsegs; struct memorypool vertices; struct memorypool viri; struct memorypool badsubsegs; struct memorypool badtriangles; struct memorypool flipstackers; struct memorypool splaynodes; struct badtriang *queuefront[64]; struct badtriang *queuetail[64]; int nextnonemptyq[64]; int firstnonemptyq; struct flipstacker *lastflip; double xmin, xmax, ymin, ymax; double xminextreme; int invertices; int inelements; int insegments; int holes; int regions; int undeads; long edges; int mesh_dim; int nextras; int eextras; long hullsize; int steinerleft; int vertexmarkindex; int vertex2triindex; int highorderindex; int elemattribindex; int areaboundindex; int checksegments; int checkquality; int readnodefile; long samples; long incirclecount; long counterclockcount; long orient3dcount; long hyperbolacount; long circumcentercount; long circletopcount; vertex infvertex1, infvertex2, infvertex3; triangle *dummytri; triangle *dummytribase; subseg *dummysub; subseg *dummysubbase; struct otri recenttri; }; struct behavior { # 786 "triangle.c" int poly, refine, quality, vararea, fixedarea, usertest; int regionattrib, convex, weighted, jettison; int firstnumber; int edgesout, voronoi, neighbors, geomview; int nobound, nopolywritten, nonodewritten, noelewritten, noiterationnum; int noholes, noexact, nolenses; int incremental, sweepline, dwyer; int splitseg; int docheck; int quiet, verbose; int usesegments; int order; int nobisect; int steiner; double minangle, goodangle; double maxarea; # 820 "triangle.c" }; # 935 "triangle.c" int plus1mod3[3] = {1, 2, 0}; int minus1mod3[3] = {2, 0, 1}; # 1364 "triangle.c" int triunsuitable(triorg, tridest, triapex, area) vertex triorg; vertex tridest; vertex triapex; double area; { double dxoa, dxda, dxod; double dyoa, dyda, dyod; double oalen, dalen, odlen; double maxlen; dxoa = triorg[0] - triapex[0]; dyoa = triorg[1] - triapex[1]; dxda = tridest[0] - triapex[0]; dyda = tridest[1] - triapex[1]; dxod = triorg[0] - tridest[0]; dyod = triorg[1] - tridest[1]; oalen = dxoa * dxoa + dyoa * dyoa; dalen = dxda * dxda + dyda * dyda; odlen = dxod * dxod + dyod * dyod; maxlen = (dalen > oalen) ? dalen : oalen; maxlen = (odlen > maxlen) ? odlen : maxlen; if (maxlen > 0.05 * (triorg[0] * triorg[0] + triorg[1] * triorg[1]) + 0.02) { return 1; } else { return 0; } } # 1411 "triangle.c" int *trimalloc(size) int size; { int *memptr; memptr = malloc(size); if (memptr == (int *) ((void *)0)) { fprintf(stderr, "Error: Out of memory.\n"); exit(1); } return(memptr); } void trifree(memptr) int *memptr; { free(memptr); } # 3135 "triangle.c" void internalerror() { fflush(stdout); fprintf(stderr, " Please report this bug to <EMAIL>\n"); fprintf(stderr, " Include the message above, your input data set, and the exact\n"); fprintf(stderr, " command line you used to run Triangle.\n"); exit(1); } # 3154 "triangle.c" void parsecommandline(argc, argv, b) int argc; char **argv; struct behavior *b; { int i, j, k; char workstring[512]; b->poly = b->refine = b->quality = 0; b->vararea = b->fixedarea = b->usertest = 0; b->regionattrib = b->convex = b->weighted = b->jettison = 0; b->firstnumber = 1; b->edgesout = b->voronoi = b->neighbors = b->geomview = 0; b->nobound = b->nopolywritten = b->nonodewritten = b->noelewritten = 0; b->noiterationnum = 0; b->noholes = b->noexact = 0; b->incremental = b->sweepline = 0; b->dwyer = 1; b->splitseg = 0; b->docheck = 0; b->nobisect = 0; b->nolenses = 0; b->steiner = -1; b->order = 1; b->minangle = 0.0; b->maxarea = -1.0; b->quiet = b->verbose = 0; for (i = 0; i < argc; i++) { for (j = 0; argv[i][j] != '\0'; j++) { if (argv[i][j] == 'p') { b->poly = 1; } if (argv[i][j] == 'r') { b->refine = 1; } if (argv[i][j] == 'q') { b->quality = 1; if (((argv[i][j + 1] >= '0') && (argv[i][j + 1] <= '9')) || (argv[i][j + 1] == '.')) { k = 0; while (((argv[i][j + 1] >= '0') && (argv[i][j + 1] <= '9')) || (argv[i][j + 1] == '.')) { j++; workstring[k] = argv[i][j]; k++; } workstring[k] = '\0'; b->minangle = (double) strtod(workstring, (char **) ((void *)0)); } else { b->minangle = 20.0; } } if (argv[i][j] == 'a') { b->quality = 1; if (((argv[i][j + 1] >= '0') && (argv[i][j + 1] <= '9')) || (argv[i][j + 1] == '.')) { b->fixedarea = 1; k = 0; while (((argv[i][j + 1] >= '0') && (argv[i][j + 1] <= '9')) || (argv[i][j + 1] == '.')) { j++; workstring[k] = argv[i][j]; k++; } workstring[k] = '\0'; b->maxarea = (double) strtod(workstring, (char **) ((void *)0)); if (b->maxarea <= 0.0) { fprintf(stderr, "Error: Maximum area must be greater than zero.\n"); exit(1); } } else { b->vararea = 1; } } if (argv[i][j] == 'u') { b->quality = 1; b->usertest = 1; } if (argv[i][j] == 'A') { b->regionattrib = 1; } if (argv[i][j] == 'c') { b->convex = 1; } if (argv[i][j] == 'w') { b->weighted = 1; } if (argv[i][j] == 'W') { b->weighted = 2; } if (argv[i][j] == 'j') { b->jettison = 1; } if (argv[i][j] == 'z') { b->firstnumber = 0; } if (argv[i][j] == 'e') { b->edgesout = 1; } if (argv[i][j] == 'v') { b->voronoi = 1; } if (argv[i][j] == 'n') { b->neighbors = 1; } if (argv[i][j] == 'g') { b->geomview = 1; } if (argv[i][j] == 'B') { b->nobound = 1; } if (argv[i][j] == 'P') { b->nopolywritten = 1; } if (argv[i][j] == 'N') { b->nonodewritten = 1; } if (argv[i][j] == 'E') { b->noelewritten = 1; } if (argv[i][j] == 'O') { b->noholes = 1; } if (argv[i][j] == 'X') { b->noexact = 1; } if (argv[i][j] == 'o') { if (argv[i][j + 1] == '2') { j++; b->order = 2; } } if (argv[i][j] == 'Y') { b->nobisect++; } if (argv[i][j] == 'S') { b->steiner = 0; while ((argv[i][j + 1] >= '0') && (argv[i][j + 1] <= '9')) { j++; b->steiner = b->steiner * 10 + (int) (argv[i][j] - '0'); } } if (argv[i][j] == 'i') { b->incremental = 1; } if (argv[i][j] == 'F') { b->sweepline = 1; } if (argv[i][j] == 'l') { b->dwyer = 0; } if (argv[i][j] == 's') { b->splitseg = 1; } if (argv[i][j] == 'L') { b->nolenses = 1; } if (argv[i][j] == 'C') { b->docheck = 1; } if (argv[i][j] == 'Q') { b->quiet = 1; } if (argv[i][j] == 'V') { b->verbose++; } } } # 3389 "triangle.c" b->usesegments = b->poly || b->refine || b->quality || b->convex; b->goodangle = cos(b->minangle * 3.141592653589793238462643383279502884197169399375105820974944592308 / 180.0); b->goodangle *= b->goodangle; if (b->refine && b->noiterationnum) { fprintf(stderr, "Error: You cannot use the -I switch when refining a triangulation.\n"); exit(1); } if (!b->refine && !b->poly) { b->vararea = 0; } if (b->refine || !b->poly) { b->regionattrib = 0; } if (b->weighted && (b->poly || b->quality)) { b->weighted = 0; if (!b->quiet) { fprintf(stderr, "Warning: weighted triangulations (-w, -W) are incompatible\n"); fprintf(stderr, " with PSLGs (-p) and meshing (-q, -a, -u). Weights ignored.\n" ); } } if (b->jettison && b->nonodewritten && !b->quiet) { fprintf(stderr, "Warning: -j and -N switches are somewhat incompatible.\n"); fprintf(stderr, " If any vertices are jettisoned, you will need the output\n"); fprintf(stderr, " .node file to reconstruct the new node indices."); } # 3506 "triangle.c" } # 3530 "triangle.c" void printtriangle(m, b, t) struct mesh *m; struct behavior *b; struct otri *t; { struct otri printtri; struct osub printsh; vertex printvertex; fprintf(stderr, "triangle x%lx with orientation %d:\n", (unsigned long) t->tri, t->orient); (printtri).orient = (int) ((unsigned long) (t->tri[0]) & (unsigned long) 3l); (printtri).tri = (triangle *) ((unsigned long) (t->tri[0]) ^ (unsigned long) (printtri).orient); if (printtri.tri == m->dummytri) { fprintf(stderr, " [0] = Outer space\n"); } else { fprintf(stderr, " [0] = x%lx %d\n", (unsigned long) printtri.tri, printtri.orient); } (printtri).orient = (int) ((unsigned long) (t->tri[1]) & (unsigned long) 3l); (printtri).tri = (triangle *) ((unsigned long) (t->tri[1]) ^ (unsigned long) (printtri).orient); if (printtri.tri == m->dummytri) { fprintf(stderr, " [1] = Outer space\n"); } else { fprintf(stderr, " [1] = x%lx %d\n", (unsigned long) printtri.tri, printtri.orient); } (printtri).orient = (int) ((unsigned long) (t->tri[2]) & (unsigned long) 3l); (printtri).tri = (triangle *) ((unsigned long) (t->tri[2]) ^ (unsigned long) (printtri).orient); if (printtri.tri == m->dummytri) { fprintf(stderr, " [2] = Outer space\n"); } else { fprintf(stderr, " [2] = x%lx %d\n", (unsigned long) printtri.tri, printtri.orient); } printvertex = (vertex) (*t).tri[plus1mod3[(*t).orient] + 3]; if (printvertex == (vertex) ((void *)0)) fprintf(stderr, " Origin[%d] = NULL\n", (t->orient + 1) % 3 + 3); else fprintf(stderr, " Origin[%d] = x%lx (%.12g, %.12g)\n", (t->orient + 1) % 3 + 3, (unsigned long) printvertex, printvertex[0], printvertex[1]); printvertex = (vertex) (*t).tri[minus1mod3[(*t).orient] + 3]; if (printvertex == (vertex) ((void *)0)) fprintf(stderr, " Dest [%d] = NULL\n", (t->orient + 2) % 3 + 3); else fprintf(stderr, " Dest [%d] = x%lx (%.12g, %.12g)\n", (t->orient + 2) % 3 + 3, (unsigned long) printvertex, printvertex[0], printvertex[1]); printvertex = (vertex) (*t).tri[(*t).orient + 3]; if (printvertex == (vertex) ((void *)0)) fprintf(stderr, " Apex [%d] = NULL\n", t->orient + 3); else fprintf(stderr, " Apex [%d] = x%lx (%.12g, %.12g)\n", t->orient + 3, (unsigned long) printvertex, printvertex[0], printvertex[1]); if (b->usesegments) { (printsh).ssorient = (int) ((unsigned long) (t->tri[6]) & (unsigned long) 1l); (printsh).ss = (subseg *) ((unsigned long) (t->tri[6]) & ~ (unsigned long) 3l); if (printsh.ss != m->dummysub) { fprintf(stderr, " [6] = x%lx %d\n", (unsigned long) printsh.ss, printsh.ssorient); } (printsh).ssorient = (int) ((unsigned long) (t->tri[7]) & (unsigned long) 1l); (printsh).ss = (subseg *) ((unsigned long) (t->tri[7]) & ~ (unsigned long) 3l); if (printsh.ss != m->dummysub) { fprintf(stderr, " [7] = x%lx %d\n", (unsigned long) printsh.ss, printsh.ssorient); } (printsh).ssorient = (int) ((unsigned long) (t->tri[8]) & (unsigned long) 1l); (printsh).ss = (subseg *) ((unsigned long) (t->tri[8]) & ~ (unsigned long) 3l); if (printsh.ss != m->dummysub) { fprintf(stderr, " [8] = x%lx %d\n", (unsigned long) printsh.ss, printsh.ssorient); } } if (b->vararea) { fprintf(stderr, " Area constraint: %.4g\n", ((double *) (*t).tri)[m->areaboundindex]); } } # 3624 "triangle.c" void printsubseg(m, b, s) struct mesh *m; struct behavior *b; struct osub *s; { struct osub printsh; struct otri printtri; vertex printvertex; fprintf(stderr, "subsegment x%lx with orientation %d and mark %d:\n", (unsigned long) s->ss, s->ssorient, (* (int *) ((*s).ss + 6))); (printsh).ssorient = (int) ((unsigned long) (s->ss[0]) & (unsigned long) 1l); (printsh).ss = (subseg *) ((unsigned long) (s->ss[0]) & ~ (unsigned long) 3l); if (printsh.ss == m->dummysub) { fprintf(stderr, " [0] = No subsegment\n"); } else { fprintf(stderr, " [0] = x%lx %d\n", (unsigned long) printsh.ss, printsh.ssorient); } (printsh).ssorient = (int) ((unsigned long) (s->ss[1]) & (unsigned long) 1l); (printsh).ss = (subseg *) ((unsigned long) (s->ss[1]) & ~ (unsigned long) 3l); if (printsh.ss == m->dummysub) { fprintf(stderr, " [1] = No subsegment\n"); } else { fprintf(stderr, " [1] = x%lx %d\n", (unsigned long) printsh.ss, printsh.ssorient); } printvertex = (vertex) (*s).ss[2 + (*s).ssorient]; if (printvertex == (vertex) ((void *)0)) fprintf(stderr, " Origin[%d] = NULL\n", 2 + s->ssorient); else fprintf(stderr, " Origin[%d] = x%lx (%.12g, %.12g)\n", 2 + s->ssorient, (unsigned long) printvertex, printvertex[0], printvertex[1]); printvertex = (vertex) (*s).ss[3 - (*s).ssorient]; if (printvertex == (vertex) ((void *)0)) fprintf(stderr, " Dest [%d] = NULL\n", 3 - s->ssorient); else fprintf(stderr, " Dest [%d] = x%lx (%.12g, %.12g)\n", 3 - s->ssorient, (unsigned long) printvertex, printvertex[0], printvertex[1]); (printtri).orient = (int) ((unsigned long) (s->ss[4]) & (unsigned long) 3l); (printtri).tri = (triangle *) ((unsigned long) (s->ss[4]) ^ (unsigned long) (printtri).orient); if (printtri.tri == m->dummytri) { fprintf(stderr, " [4] = Outer space\n"); } else { fprintf(stderr, " [4] = x%lx %d\n", (unsigned long) printtri.tri, printtri.orient); } (printtri).orient = (int) ((unsigned long) (s->ss[5]) & (unsigned long) 3l); (printtri).tri = (triangle *) ((unsigned long) (s->ss[5]) ^ (unsigned long) (printtri).orient); if (printtri.tri == m->dummytri) { fprintf(stderr, " [5] = Outer space\n"); } else { fprintf(stderr, " [5] = x%lx %d\n", (unsigned long) printtri.tri, printtri.orient); } } # 3704 "triangle.c" void poolrestart(pool) struct memorypool *pool; { unsigned long alignptr; pool->items = 0; pool->maxitems = 0; pool->nowblock = pool->firstblock; alignptr = (unsigned long) (pool->nowblock + 1); pool->nextitem = (int *) (alignptr + (unsigned long) pool->alignbytes - (alignptr % (unsigned long) pool->alignbytes)); pool->unallocateditems = pool->itemsperblock; pool->deaditemstack = (int *) ((void *)0); } # 3751 "triangle.c" void poolinit(pool, bytecount, itemcount, wtype, alignment) struct memorypool *pool; int bytecount; int itemcount; enum wordtype wtype; int alignment; { int wordsize; pool->itemwordtype = wtype; wordsize = (pool->itemwordtype == POINTER) ? sizeof(int *) : sizeof(double); if (alignment > wordsize) { pool->alignbytes = alignment; } else { pool->alignbytes = wordsize; } if (sizeof(int *) > pool->alignbytes) { pool->alignbytes = sizeof(int *); } pool->itemwords = ((bytecount + pool->alignbytes - 1) / pool->alignbytes) * (pool->alignbytes / wordsize); pool->itembytes = pool->itemwords * wordsize; pool->itemsperblock = itemcount; pool->firstblock = (int **) trimalloc(pool->itemsperblock * pool->itembytes + sizeof(int *) + pool->alignbytes); *(pool->firstblock) = (int *) ((void *)0); poolrestart(pool); } # 3802 "triangle.c" void pooldeinit(pool) struct memorypool *pool; { while (pool->firstblock != (int **) ((void *)0)) { pool->nowblock = (int **) *(pool->firstblock); trifree((int *) pool->firstblock); pool->firstblock = pool->nowblock; } } # 3823 "triangle.c" int *poolalloc(pool) struct memorypool *pool; { int *newitem; int **newblock; unsigned long alignptr; if (pool->deaditemstack != (int *) ((void *)0)) { newitem = pool->deaditemstack; pool->deaditemstack = * (int **) pool->deaditemstack; } else { if (pool->unallocateditems == 0) { if (*(pool->nowblock) == (int *) ((void *)0)) { newblock = (int **) trimalloc(pool->itemsperblock * pool->itembytes + sizeof(int *) + pool->alignbytes); *(pool->nowblock) = (int *) newblock; *newblock = (int *) ((void *)0); } pool->nowblock = (int **) *(pool->nowblock); alignptr = (unsigned long) (pool->nowblock + 1); pool->nextitem = (int *) (alignptr + (unsigned long) pool->alignbytes - (alignptr % (unsigned long) pool->alignbytes)); pool->unallocateditems = pool->itemsperblock; } newitem = pool->nextitem; if (pool->itemwordtype == POINTER) { pool->nextitem = (int *) ((int **) pool->nextitem + pool->itemwords); } else { pool->nextitem = (int *) ((double *) pool->nextitem + pool->itemwords); } pool->unallocateditems--; pool->maxitems++; } pool->items++; return newitem; } # 3887 "triangle.c" void pooldealloc(pool, dyingitem) struct memorypool *pool; int *dyingitem; { *((int **) dyingitem) = pool->deaditemstack; pool->deaditemstack = dyingitem; pool->items--; } # 3910 "triangle.c" void traversalinit(pool) struct memorypool *pool; { unsigned long alignptr; pool->pathblock = pool->firstblock; alignptr = (unsigned long) (pool->pathblock + 1); pool->pathitem = (int *) (alignptr + (unsigned long) pool->alignbytes - (alignptr % (unsigned long) pool->alignbytes)); pool->pathitemsleft = pool->itemsperblock; } # 3946 "triangle.c" int *traverse(pool) struct memorypool *pool; { int *newitem; unsigned long alignptr; if (pool->pathitem == pool->nextitem) { return (int *) ((void *)0); } if (pool->pathitemsleft == 0) { pool->pathblock = (int **) *(pool->pathblock); alignptr = (unsigned long) (pool->pathblock + 1); pool->pathitem = (int *) (alignptr + (unsigned long) pool->alignbytes - (alignptr % (unsigned long) pool->alignbytes)); pool->pathitemsleft = pool->itemsperblock; } newitem = pool->pathitem; if (pool->itemwordtype == POINTER) { pool->pathitem = (int *) ((int **) pool->pathitem + pool->itemwords); } else { pool->pathitem = (int *) ((double *) pool->pathitem + pool->itemwords); } pool->pathitemsleft--; return newitem; } # 4014 "triangle.c" void dummyinit(m, b, trianglewords, subsegwords) struct mesh *m; struct behavior *b; int trianglewords; int subsegwords; { unsigned long alignptr; m->dummytribase = (triangle *) trimalloc(trianglewords * sizeof(triangle) + m->triangles.alignbytes); alignptr = (unsigned long) m->dummytribase; m->dummytri = (triangle *) (alignptr + (unsigned long) m->triangles.alignbytes - (alignptr % (unsigned long) m->triangles.alignbytes)); m->dummytri[0] = (triangle) m->dummytri; m->dummytri[1] = (triangle) m->dummytri; m->dummytri[2] = (triangle) m->dummytri; m->dummytri[3] = (triangle) ((void *)0); m->dummytri[4] = (triangle) ((void *)0); m->dummytri[5] = (triangle) ((void *)0); if (b->usesegments) { m->dummysubbase = (subseg *) trimalloc(subsegwords * sizeof(subseg) + m->subsegs.alignbytes); alignptr = (unsigned long) m->dummysubbase; m->dummysub = (subseg *) (alignptr + (unsigned long) m->subsegs.alignbytes - (alignptr % (unsigned long) m->subsegs.alignbytes)); m->dummysub[0] = (subseg) m->dummysub; m->dummysub[1] = (subseg) m->dummysub; m->dummysub[2] = (subseg) ((void *)0); m->dummysub[3] = (subseg) ((void *)0); m->dummysub[4] = (subseg) m->dummytri; m->dummysub[5] = (subseg) m->dummytri; * (int *) (m->dummysub + 6) = 0; m->dummytri[6] = (triangle) m->dummysub; m->dummytri[7] = (triangle) m->dummysub; m->dummytri[8] = (triangle) m->dummysub; } } # 4091 "triangle.c" void initializevertexpool(m, b) struct mesh *m; struct behavior *b; { int vertexsize; m->vertexmarkindex = ((m->mesh_dim + m->nextras) * sizeof(double) + sizeof(int) - 1) / sizeof(int); vertexsize = (m->vertexmarkindex + 2) * sizeof(int); if (b->poly) { m->vertex2triindex = (vertexsize + sizeof(triangle) - 1) / sizeof(triangle); vertexsize = (m->vertex2triindex + 1) * sizeof(triangle); } poolinit(&m->vertices, vertexsize, 4092, (sizeof(double) >= sizeof(triangle)) ? FLOATINGPOINT : POINTER, 0); } # 4132 "triangle.c" void initializetrisubpools(m, b) struct mesh *m; struct behavior *b; { int trisize; m->highorderindex = 6 + (b->usesegments * 3); trisize = ((b->order + 1) * (b->order + 2) / 2 + (m->highorderindex - 3)) * sizeof(triangle); m->elemattribindex = (trisize + sizeof(double) - 1) / sizeof(double); m->areaboundindex = m->elemattribindex + m->eextras + b->regionattrib; if (b->vararea) { trisize = (m->areaboundindex + 1) * sizeof(double); } else if (m->eextras + b->regionattrib > 0) { trisize = m->areaboundindex * sizeof(double); } if ((b->voronoi || b->neighbors) && (trisize < 6 * sizeof(triangle) + sizeof(int))) { trisize = 6 * sizeof(triangle) + sizeof(int); } poolinit(&m->triangles, trisize, 4092, POINTER, 4); if (b->usesegments) { poolinit(&m->subsegs, 6 * sizeof(triangle) + sizeof(int), 508, POINTER, 4); dummyinit(m, b, m->triangles.itemwords, m->subsegs.itemwords); } else { dummyinit(m, b, m->triangles.itemwords, 0); } } # 4196 "triangle.c" void triangledealloc(m, dyingtriangle) struct mesh *m; triangle *dyingtriangle; { (dyingtriangle)[1] = (triangle) ((void *)0); (dyingtriangle)[3] = (triangle) ((void *)0); pooldealloc(&m->triangles, (int *) dyingtriangle); } # 4217 "triangle.c" triangle *triangletraverse(m) struct mesh *m; { triangle *newtriangle; do { newtriangle = (triangle *) traverse(&m->triangles); if (newtriangle == (triangle *) ((void *)0)) { return (triangle *) ((void *)0); } } while (((newtriangle)[1] == (triangle) ((void *)0))); return newtriangle; } # 4242 "triangle.c" void subsegdealloc(m, dyingsubseg) struct mesh *m; subseg *dyingsubseg; { (dyingsubseg)[1] = (subseg) ((void *)0); (dyingsubseg)[2] = (subseg) ((void *)0); pooldealloc(&m->subsegs, (int *) dyingsubseg); } # 4263 "triangle.c" subseg *subsegtraverse(m) struct mesh *m; { subseg *newsubseg; do { newsubseg = (subseg *) traverse(&m->subsegs); if (newsubseg == (subseg *) ((void *)0)) { return (subseg *) ((void *)0); } } while (((newsubseg)[1] == (subseg) ((void *)0))); return newsubseg; } # 4288 "triangle.c" void vertexdealloc(m, dyingvertex) struct mesh *m; vertex dyingvertex; { ((int *) (dyingvertex))[m->vertexmarkindex + 1] = -32768; pooldealloc(&m->vertices, (int *) dyingvertex); } # 4309 "triangle.c" vertex vertextraverse(m) struct mesh *m; { vertex newvertex; do { newvertex = (vertex) traverse(&m->vertices); if (newvertex == (vertex) ((void *)0)) { return (vertex) ((void *)0); } } while (((int *) (newvertex))[m->vertexmarkindex + 1] == -32768); return newvertex; } # 4337 "triangle.c" void badsubsegdealloc(m, dyingseg) struct mesh *m; struct badsubseg *dyingseg; { dyingseg->subsegorg = (vertex) ((void *)0); pooldealloc(&m->badsubsegs, (int *) dyingseg); } # 4362 "triangle.c" struct badsubseg *badsubsegtraverse(m) struct mesh *m; { struct badsubseg *newseg; do { newseg = (struct badsubseg *) traverse(&m->badsubsegs); if (newseg == (struct badsubseg *) ((void *)0)) { return (struct badsubseg *) ((void *)0); } } while (newseg->subsegorg == (vertex) ((void *)0)); return newseg; } # 4395 "triangle.c" vertex getvertex(m, b, number) struct mesh *m; struct behavior *b; int number; { int **getblock; vertex foundvertex; unsigned long alignptr; int current; getblock = m->vertices.firstblock; current = b->firstnumber; while (current + m->vertices.itemsperblock <= number) { getblock = (int **) *getblock; current += m->vertices.itemsperblock; } alignptr = (unsigned long) (getblock + 1); foundvertex = (vertex) (alignptr + (unsigned long) m->vertices.alignbytes - (alignptr % (unsigned long) m->vertices.alignbytes)); while (current < number) { foundvertex += m->vertices.itemwords; current++; } return foundvertex; } # 4434 "triangle.c" void triangledeinit(m, b) struct mesh *m; struct behavior *b; { pooldeinit(&m->triangles); trifree((int *) m->dummytribase); if (b->usesegments) { pooldeinit(&m->subsegs); trifree((int *) m->dummysubbase); } pooldeinit(&m->vertices); if (b->quality) { pooldeinit(&m->badsubsegs); if ((b->minangle > 0.0) || b->vararea || b->fixedarea || b->usertest) { pooldeinit(&m->badtriangles); pooldeinit(&m->flipstackers); } } } # 4475 "triangle.c" void maketriangle(m, b, newotri) struct mesh *m; struct behavior *b; struct otri *newotri; { int i; newotri->tri = (triangle *) poolalloc(&m->triangles); newotri->tri[0] = (triangle) m->dummytri; newotri->tri[1] = (triangle) m->dummytri; newotri->tri[2] = (triangle) m->dummytri; newotri->tri[3] = (triangle) ((void *)0); newotri->tri[4] = (triangle) ((void *)0); newotri->tri[5] = (triangle) ((void *)0); if (b->usesegments) { newotri->tri[6] = (triangle) m->dummysub; newotri->tri[7] = (triangle) m->dummysub; newotri->tri[8] = (triangle) m->dummysub; } for (i = 0; i < m->eextras; i++) { ((double *) (*newotri).tri)[m->elemattribindex + (i)] = 0.0; } if (b->vararea) { ((double *) (*newotri).tri)[m->areaboundindex] = -1.0; } newotri->orient = 0; } # 4519 "triangle.c" void makesubseg(m, newsubseg) struct mesh *m; struct osub *newsubseg; { newsubseg->ss = (subseg *) poolalloc(&m->subsegs); newsubseg->ss[0] = (subseg) m->dummysub; newsubseg->ss[1] = (subseg) m->dummysub; newsubseg->ss[2] = (subseg) ((void *)0); newsubseg->ss[3] = (subseg) ((void *)0); newsubseg->ss[4] = (subseg) m->dummytri; newsubseg->ss[5] = (subseg) m->dummytri; * (int *) ((*newsubseg).ss + 6) = 0; newsubseg->ssorient = 0; } # 4697 "triangle.c" void exactinit() { double half; double check, lastcheck; int every_other; # 4724 "triangle.c" every_other = 1; half = 0.5; epsilon = 1.0; splitter = 1.0; check = 1.0; do { lastcheck = check; epsilon *= half; if (every_other) { splitter *= 2.0; } every_other = !every_other; check = 1.0 + epsilon; } while ((check != 1.0) && (check != lastcheck)); splitter += 1.0; resulterrbound = (3.0 + 8.0 * epsilon) * epsilon; ccwerrboundA = (3.0 + 16.0 * epsilon) * epsilon; ccwerrboundB = (2.0 + 12.0 * epsilon) * epsilon; ccwerrboundC = (9.0 + 64.0 * epsilon) * epsilon * epsilon; iccerrboundA = (10.0 + 96.0 * epsilon) * epsilon; iccerrboundB = (4.0 + 48.0 * epsilon) * epsilon; iccerrboundC = (44.0 + 576.0 * epsilon) * epsilon * epsilon; o3derrboundA = (7.0 + 56.0 * epsilon) * epsilon; o3derrboundB = (3.0 + 28.0 * epsilon) * epsilon; o3derrboundC = (26.0 + 288.0 * epsilon) * epsilon * epsilon; } # 4773 "triangle.c" int fast_expansion_sum_zeroelim(elen, e, flen, f, h) int elen; double *e; int flen; double *f; double *h; { double Q; double Qnew; double hh; double bvirt; double avirt, bround, around; int eindex, findex, hindex; double enow, fnow; enow = e[0]; fnow = f[0]; eindex = findex = 0; if ((fnow > enow) == (fnow > -enow)) { Q = enow; enow = e[++eindex]; } else { Q = fnow; fnow = f[++findex]; } hindex = 0; if ((eindex < elen) && (findex < flen)) { if ((fnow > enow) == (fnow > -enow)) { Qnew = (double) (enow + Q); bvirt = Qnew - enow; hh = Q - bvirt; enow = e[++eindex]; } else { Qnew = (double) (fnow + Q); bvirt = Qnew - fnow; hh = Q - bvirt; fnow = f[++findex]; } Q = Qnew; if (hh != 0.0) { h[hindex++] = hh; } while ((eindex < elen) && (findex < flen)) { if ((fnow > enow) == (fnow > -enow)) { Qnew = (double) (Q + enow); bvirt = (double) (Qnew - Q); avirt = Qnew - bvirt; bround = enow - bvirt; around = Q - avirt; hh = around + bround; enow = e[++eindex]; } else { Qnew = (double) (Q + fnow); bvirt = (double) (Qnew - Q); avirt = Qnew - bvirt; bround = fnow - bvirt; around = Q - avirt; hh = around + bround; fnow = f[++findex]; } Q = Qnew; if (hh != 0.0) { h[hindex++] = hh; } } } while (eindex < elen) { Qnew = (double) (Q + enow); bvirt = (double) (Qnew - Q); avirt = Qnew - bvirt; bround = enow - bvirt; around = Q - avirt; hh = around + bround; enow = e[++eindex]; Q = Qnew; if (hh != 0.0) { h[hindex++] = hh; } } while (findex < flen) { Qnew = (double) (Q + fnow); bvirt = (double) (Qnew - Q); avirt = Qnew - bvirt; bround = fnow - bvirt; around = Q - avirt; hh = around + bround; fnow = f[++findex]; Q = Qnew; if (hh != 0.0) { h[hindex++] = hh; } } if ((Q != 0.0) || (hindex == 0)) { h[hindex++] = Q; } return hindex; } # 4867 "triangle.c" int scale_expansion_zeroelim(elen, e, b, h) int elen; double *e; double b; double *h; { double Q, sum; double hh; double product1; double product0; int eindex, hindex; double enow; double bvirt; double avirt, bround, around; double c; double abig; double ahi, alo, bhi, blo; double err1, err2, err3; c = (double) (splitter * b); abig = (double) (c - b); bhi = c - abig; blo = b - bhi; Q = (double) (e[0] * b); c = (double) (splitter * e[0]); abig = (double) (c - e[0]); ahi = c - abig; alo = e[0] - ahi; err1 = Q - (ahi * bhi); err2 = err1 - (alo * bhi); err3 = err2 - (ahi * blo); hh = (alo * blo) - err3; hindex = 0; if (hh != 0) { h[hindex++] = hh; } for (eindex = 1; eindex < elen; eindex++) { enow = e[eindex]; product1 = (double) (enow * b); c = (double) (splitter * enow); abig = (double) (c - enow); ahi = c - abig; alo = enow - ahi; err1 = product1 - (ahi * bhi); err2 = err1 - (alo * bhi); err3 = err2 - (ahi * blo); product0 = (alo * blo) - err3; sum = (double) (Q + product0); bvirt = (double) (sum - Q); avirt = sum - bvirt; bround = product0 - bvirt; around = Q - avirt; hh = around + bround; if (hh != 0) { h[hindex++] = hh; } Q = (double) (product1 + sum); bvirt = Q - product1; hh = sum - bvirt; if (hh != 0) { h[hindex++] = hh; } } if ((Q != 0.0) || (hindex == 0)) { h[hindex++] = Q; } return hindex; } # 4923 "triangle.c" double estimate(elen, e) int elen; double *e; { double Q; int eindex; Q = e[0]; for (eindex = 1; eindex < elen; eindex++) { Q += e[eindex]; } return Q; } # 4962 "triangle.c" double counterclockwiseadapt(pa, pb, pc, detsum) vertex pa; vertex pb; vertex pc; double detsum; { double acx, acy, bcx, bcy; double acxtail, acytail, bcxtail, bcytail; double detleft, detright; double detlefttail, detrighttail; double det, errbound; double B[4], C1[8], C2[12], D[16]; double B3; int C1length, C2length, Dlength; double u[4]; double u3; double s1, t1; double s0, t0; double bvirt; double avirt, bround, around; double c; double abig; double ahi, alo, bhi, blo; double err1, err2, err3; double _i, _j; double _0; acx = (double) (pa[0] - pc[0]); bcx = (double) (pb[0] - pc[0]); acy = (double) (pa[1] - pc[1]); bcy = (double) (pb[1] - pc[1]); detleft = (double) (acx * bcy); c = (double) (splitter * acx); abig = (double) (c - acx); ahi = c - abig; alo = acx - ahi; c = (double) (splitter * bcy); abig = (double) (c - bcy); bhi = c - abig; blo = bcy - bhi; err1 = detleft - (ahi * bhi); err2 = err1 - (alo * bhi); err3 = err2 - (ahi * blo); detlefttail = (alo * blo) - err3; detright = (double) (acy * bcx); c = (double) (splitter * acy); abig = (double) (c - acy); ahi = c - abig; alo = acy - ahi; c = (double) (splitter * bcx); abig = (double) (c - bcx); bhi = c - abig; blo = bcx - bhi; err1 = detright - (ahi * bhi); err2 = err1 - (alo * bhi); err3 = err2 - (ahi * blo); detrighttail = (alo * blo) - err3; _i = (double) (detlefttail - detrighttail); bvirt = (double) (detlefttail - _i); avirt = _i + bvirt; bround = bvirt - detrighttail; around = detlefttail - avirt; B[0] = around + bround; _j = (double) (detleft + _i); bvirt = (double) (_j - detleft); avirt = _j - bvirt; bround = _i - bvirt; around = detleft - avirt; _0 = around + bround; _i = (double) (_0 - detright); bvirt = (double) (_0 - _i); avirt = _i + bvirt; bround = bvirt - detright; around = _0 - avirt; B[1] = around + bround; B3 = (double) (_j + _i); bvirt = (double) (B3 - _j); avirt = B3 - bvirt; bround = _i - bvirt; around = _j - avirt; B[2] = around + bround; B[3] = B3; det = estimate(4, B); errbound = ccwerrboundB * detsum; if ((det >= errbound) || (-det >= errbound)) { return det; } bvirt = (double) (pa[0] - acx); avirt = acx + bvirt; bround = bvirt - pc[0]; around = pa[0] - avirt; acxtail = around + bround; bvirt = (double) (pb[0] - bcx); avirt = bcx + bvirt; bround = bvirt - pc[0]; around = pb[0] - avirt; bcxtail = around + bround; bvirt = (double) (pa[1] - acy); avirt = acy + bvirt; bround = bvirt - pc[1]; around = pa[1] - avirt; acytail = around + bround; bvirt = (double) (pb[1] - bcy); avirt = bcy + bvirt; bround = bvirt - pc[1]; around = pb[1] - avirt; bcytail = around + bround; if ((acxtail == 0.0) && (acytail == 0.0) && (bcxtail == 0.0) && (bcytail == 0.0)) { return det; } errbound = ccwerrboundC * detsum + resulterrbound * ((det) >= 0.0 ? (det) : -(det)); det += (acx * bcytail + bcy * acxtail) - (acy * bcxtail + bcx * acytail); if ((det >= errbound) || (-det >= errbound)) { return det; } s1 = (double) (acxtail * bcy); c = (double) (splitter * acxtail); abig = (double) (c - acxtail); ahi = c - abig; alo = acxtail - ahi; c = (double) (splitter * bcy); abig = (double) (c - bcy); bhi = c - abig; blo = bcy - bhi; err1 = s1 - (ahi * bhi); err2 = err1 - (alo * bhi); err3 = err2 - (ahi * blo); s0 = (alo * blo) - err3; t1 = (double) (acytail * bcx); c = (double) (splitter * acytail); abig = (double) (c - acytail); ahi = c - abig; alo = acytail - ahi; c = (double) (splitter * bcx); abig = (double) (c - bcx); bhi = c - abig; blo = bcx - bhi; err1 = t1 - (ahi * bhi); err2 = err1 - (alo * bhi); err3 = err2 - (ahi * blo); t0 = (alo * blo) - err3; _i = (double) (s0 - t0); bvirt = (double) (s0 - _i); avirt = _i + bvirt; bround = bvirt - t0; around = s0 - avirt; u[0] = around + bround; _j = (double) (s1 + _i); bvirt = (double) (_j - s1); avirt = _j - bvirt; bround = _i - bvirt; around = s1 - avirt; _0 = around + bround; _i = (double) (_0 - t1); bvirt = (double) (_0 - _i); avirt = _i + bvirt; bround = bvirt - t1; around = _0 - avirt; u[1] = around + bround; u3 = (double) (_j + _i); bvirt = (double) (u3 - _j); avirt = u3 - bvirt; bround = _i - bvirt; around = _j - avirt; u[2] = around + bround; u[3] = u3; C1length = fast_expansion_sum_zeroelim(4, B, 4, u, C1); s1 = (double) (acx * bcytail); c = (double) (splitter * acx); abig = (double) (c - acx); ahi = c - abig; alo = acx - ahi; c = (double) (splitter * bcytail); abig = (double) (c - bcytail); bhi = c - abig; blo = bcytail - bhi; err1 = s1 - (ahi * bhi); err2 = err1 - (alo * bhi); err3 = err2 - (ahi * blo); s0 = (alo * blo) - err3; t1 = (double) (acy * bcxtail); c = (double) (splitter * acy); abig = (double) (c - acy); ahi = c - abig; alo = acy - ahi; c = (double) (splitter * bcxtail); abig = (double) (c - bcxtail); bhi = c - abig; blo = bcxtail - bhi; err1 = t1 - (ahi * bhi); err2 = err1 - (alo * bhi); err3 = err2 - (ahi * blo); t0 = (alo * blo) - err3; _i = (double) (s0 - t0); bvirt = (double) (s0 - _i); avirt = _i + bvirt; bround = bvirt - t0; around = s0 - avirt; u[0] = around + bround; _j = (double) (s1 + _i); bvirt = (double) (_j - s1); avirt = _j - bvirt; bround = _i - bvirt; around = s1 - avirt; _0 = around + bround; _i = (double) (_0 - t1); bvirt = (double) (_0 - _i); avirt = _i + bvirt; bround = bvirt - t1; around = _0 - avirt; u[1] = around + bround; u3 = (double) (_j + _i); bvirt = (double) (u3 - _j); avirt = u3 - bvirt; bround = _i - bvirt; around = _j - avirt; u[2] = around + bround; u[3] = u3; C2length = fast_expansion_sum_zeroelim(C1length, C1, 4, u, C2); s1 = (double) (acxtail * bcytail); c = (double) (splitter * acxtail); abig = (double) (c - acxtail); ahi = c - abig; alo = acxtail - ahi; c = (double) (splitter * bcytail); abig = (double) (c - bcytail); bhi = c - abig; blo = bcytail - bhi; err1 = s1 - (ahi * bhi); err2 = err1 - (alo * bhi); err3 = err2 - (ahi * blo); s0 = (alo * blo) - err3; t1 = (double) (acytail * bcxtail); c = (double) (splitter * acytail); abig = (double) (c - acytail); ahi = c - abig; alo = acytail - ahi; c = (double) (splitter * bcxtail); abig = (double) (c - bcxtail); bhi = c - abig; blo = bcxtail - bhi; err1 = t1 - (ahi * bhi); err2 = err1 - (alo * bhi); err3 = err2 - (ahi * blo); t0 = (alo * blo) - err3; _i = (double) (s0 - t0); bvirt = (double) (s0 - _i); avirt = _i + bvirt; bround = bvirt - t0; around = s0 - avirt; u[0] = around + bround; _j = (double) (s1 + _i); bvirt = (double) (_j - s1); avirt = _j - bvirt; bround = _i - bvirt; around = s1 - avirt; _0 = around + bround; _i = (double) (_0 - t1); bvirt = (double) (_0 - _i); avirt = _i + bvirt; bround = bvirt - t1; around = _0 - avirt; u[1] = around + bround; u3 = (double) (_j + _i); bvirt = (double) (u3 - _j); avirt = u3 - bvirt; bround = _i - bvirt; around = _j - avirt; u[2] = around + bround; u[3] = u3; Dlength = fast_expansion_sum_zeroelim(C2length, C2, 4, u, D); return(D[Dlength - 1]); } double counterclockwise(m, b, pa, pb, pc) struct mesh *m; struct behavior *b; vertex pa; vertex pb; vertex pc; { double detleft, detright, det; double detsum, errbound; m->counterclockcount++; detleft = (pa[0] - pc[0]) * (pb[1] - pc[1]); detright = (pa[1] - pc[1]) * (pb[0] - pc[0]); det = detleft - detright; if (b->noexact) { return det; } if (detleft > 0.0) { if (detright <= 0.0) { return det; } else { detsum = detleft + detright; } } else if (detleft < 0.0) { if (detright >= 0.0) { return det; } else { detsum = -detleft - detright; } } else { return det; } errbound = ccwerrboundA * detsum; if ((det >= errbound) || (-det >= errbound)) { return det; } return counterclockwiseadapt(pa, pb, pc, detsum); } # 5120 "triangle.c" double incircleadapt(pa, pb, pc, pd, permanent) vertex pa; vertex pb; vertex pc; vertex pd; double permanent; { double adx, bdx, cdx, ady, bdy, cdy; double det, errbound; double bdxcdy1, cdxbdy1, cdxady1, adxcdy1, adxbdy1, bdxady1; double bdxcdy0, cdxbdy0, cdxady0, adxcdy0, adxbdy0, bdxady0; double bc[4], ca[4], ab[4]; double bc3, ca3, ab3; double axbc[8], axxbc[16], aybc[8], ayybc[16], adet[32]; int axbclen, axxbclen, aybclen, ayybclen, alen; double bxca[8], bxxca[16], byca[8], byyca[16], bdet[32]; int bxcalen, bxxcalen, bycalen, byycalen, blen; double cxab[8], cxxab[16], cyab[8], cyyab[16], cdet[32]; int cxablen, cxxablen, cyablen, cyyablen, clen; double abdet[64]; int ablen; double fin1[1152], fin2[1152]; double *finnow, *finother, *finswap; int finlength; double adxtail, bdxtail, cdxtail, adytail, bdytail, cdytail; double adxadx1, adyady1, bdxbdx1, bdybdy1, cdxcdx1, cdycdy1; double adxadx0, adyady0, bdxbdx0, bdybdy0, cdxcdx0, cdycdy0; double aa[4], bb[4], cc[4]; double aa3, bb3, cc3; double ti1, tj1; double ti0, tj0; double u[4], v[4]; double u3, v3; double temp8[8], temp16a[16], temp16b[16], temp16c[16]; double temp32a[32], temp32b[32], temp48[48], temp64[64]; int temp8len, temp16alen, temp16blen, temp16clen; int temp32alen, temp32blen, temp48len, temp64len; double axtbb[8], axtcc[8], aytbb[8], aytcc[8]; int axtbblen, axtcclen, aytbblen, aytcclen; double bxtaa[8], bxtcc[8], bytaa[8], bytcc[8]; int bxtaalen, bxtcclen, bytaalen, bytcclen; double cxtaa[8], cxtbb[8], cytaa[8], cytbb[8]; int cxtaalen, cxtbblen, cytaalen, cytbblen; double axtbc[8], aytbc[8], bxtca[8], bytca[8], cxtab[8], cytab[8]; int axtbclen, aytbclen, bxtcalen, bytcalen, cxtablen, cytablen; double axtbct[16], aytbct[16], bxtcat[16], bytcat[16], cxtabt[16], cytabt[16]; int axtbctlen, aytbctlen, bxtcatlen, bytcatlen, cxtabtlen, cytabtlen; double axtbctt[8], aytbctt[8], bxtcatt[8]; double bytcatt[8], cxtabtt[8], cytabtt[8]; int axtbcttlen, aytbcttlen, bxtcattlen, bytcattlen, cxtabttlen, cytabttlen; double abt[8], bct[8], cat[8]; int abtlen, bctlen, catlen; double abtt[4], bctt[4], catt[4]; int abttlen, bcttlen, cattlen; double abtt3, bctt3, catt3; double negate; double bvirt; double avirt, bround, around; double c; double abig; double ahi, alo, bhi, blo; double err1, err2, err3; double _i, _j; double _0; adx = (double) (pa[0] - pd[0]); bdx = (double) (pb[0] - pd[0]); cdx = (double) (pc[0] - pd[0]); ady = (double) (pa[1] - pd[1]); bdy = (double) (pb[1] - pd[1]); cdy = (double) (pc[1] - pd[1]); bdxcdy1 = (double) (bdx * cdy); c = (double) (splitter * bdx); abig = (double) (c - bdx); ahi = c - abig; alo = bdx - ahi; c = (double) (splitter * cdy); abig = (double) (c - cdy); bhi = c - abig; blo = cdy - bhi; err1 = bdxcdy1 - (ahi * bhi); err2 = err1 - (alo * bhi); err3 = err2 - (ahi * blo); bdxcdy0 = (alo * blo) - err3; cdxbdy1 = (double) (cdx * bdy); c = (double) (splitter * cdx); abig = (double) (c - cdx); ahi = c - abig; alo = cdx - ahi; c = (double) (splitter * bdy); abig = (double) (c - bdy); bhi = c - abig; blo = bdy - bhi; err1 = cdxbdy1 - (ahi * bhi); err2 = err1 - (alo * bhi); err3 = err2 - (ahi * blo); cdxbdy0 = (alo * blo) - err3; _i = (double) (bdxcdy0 - cdxbdy0); bvirt = (double) (bdxcdy0 - _i); avirt = _i + bvirt; bround = bvirt - cdxbdy0; around = bdxcdy0 - avirt; bc[0] = around + bround; _j = (double) (bdxcdy1 + _i); bvirt = (double) (_j - bdxcdy1); avirt = _j - bvirt; bround = _i - bvirt; around = bdxcdy1 - avirt; _0 = around + bround; _i = (double) (_0 - cdxbdy1); bvirt = (double) (_0 - _i); avirt = _i + bvirt; bround = bvirt - cdxbdy1; around = _0 - avirt; bc[1] = around + bround; bc3 = (double) (_j + _i); bvirt = (double) (bc3 - _j); avirt = bc3 - bvirt; bround = _i - bvirt; around = _j - avirt; bc[2] = around + bround; bc[3] = bc3; axbclen = scale_expansion_zeroelim(4, bc, adx, axbc); axxbclen = scale_expansion_zeroelim(axbclen, axbc, adx, axxbc); aybclen = scale_expansion_zeroelim(4, bc, ady, aybc); ayybclen = scale_expansion_zeroelim(aybclen, aybc, ady, ayybc); alen = fast_expansion_sum_zeroelim(axxbclen, axxbc, ayybclen, ayybc, adet); cdxady1 = (double) (cdx * ady); c = (double) (splitter * cdx); abig = (double) (c - cdx); ahi = c - abig; alo = cdx - ahi; c = (double) (splitter * ady); abig = (double) (c - ady); bhi = c - abig; blo = ady - bhi; err1 = cdxady1 - (ahi * bhi); err2 = err1 - (alo * bhi); err3 = err2 - (ahi * blo); cdxady0 = (alo * blo) - err3; adxcdy1 = (double) (adx * cdy); c = (double) (splitter * adx); abig = (double) (c - adx); ahi = c - abig; alo = adx - ahi; c = (double) (splitter * cdy); abig = (double) (c - cdy); bhi = c - abig; blo = cdy - bhi; err1 = adxcdy1 - (ahi * bhi); err2 = err1 - (alo * bhi); err3 = err2 - (ahi * blo); adxcdy0 = (alo * blo) - err3; _i = (double) (cdxady0 - adxcdy0); bvirt = (double) (cdxady0 - _i); avirt = _i + bvirt; bround = bvirt - adxcdy0; around = cdxady0 - avirt; ca[0] = around + bround; _j = (double) (cdxady1 + _i); bvirt = (double) (_j - cdxady1); avirt = _j - bvirt; bround = _i - bvirt; around = cdxady1 - avirt; _0 = around + bround; _i = (double) (_0 - adxcdy1); bvirt = (double) (_0 - _i); avirt = _i + bvirt; bround = bvirt - adxcdy1; around = _0 - avirt; ca[1] = around + bround; ca3 = (double) (_j + _i); bvirt = (double) (ca3 - _j); avirt = ca3 - bvirt; bround = _i - bvirt; around = _j - avirt; ca[2] = around + bround; ca[3] = ca3; bxcalen = scale_expansion_zeroelim(4, ca, bdx, bxca); bxxcalen = scale_expansion_zeroelim(bxcalen, bxca, bdx, bxxca); bycalen = scale_expansion_zeroelim(4, ca, bdy, byca); byycalen = scale_expansion_zeroelim(bycalen, byca, bdy, byyca); blen = fast_expansion_sum_zeroelim(bxxcalen, bxxca, byycalen, byyca, bdet); adxbdy1 = (double) (adx * bdy); c = (double) (splitter * adx); abig = (double) (c - adx); ahi = c - abig; alo = adx - ahi; c = (double) (splitter * bdy); abig = (double) (c - bdy); bhi = c - abig; blo = bdy - bhi; err1 = adxbdy1 - (ahi * bhi); err2 = err1 - (alo * bhi); err3 = err2 - (ahi * blo); adxbdy0 = (alo * blo) - err3; bdxady1 = (double) (bdx * ady); c = (double) (splitter * bdx); abig = (double) (c - bdx); ahi = c - abig; alo = bdx - ahi; c = (double) (splitter * ady); abig = (double) (c - ady); bhi = c - abig; blo = ady - bhi; err1 = bdxady1 - (ahi * bhi); err2 = err1 - (alo * bhi); err3 = err2 - (ahi * blo); bdxady0 = (alo * blo) - err3; _i = (double) (adxbdy0 - bdxady0); bvirt = (double) (adxbdy0 - _i); avirt = _i + bvirt; bround = bvirt - bdxady0; around = adxbdy0 - avirt; ab[0] = around + bround; _j = (double) (adxbdy1 + _i); bvirt = (double) (_j - adxbdy1); avirt = _j - bvirt; bround = _i - bvirt; around = adxbdy1 - avirt; _0 = around + bround; _i = (double) (_0 - bdxady1); bvirt = (double) (_0 - _i); avirt = _i + bvirt; bround = bvirt - bdxady1; around = _0 - avirt; ab[1] = around + bround; ab3 = (double) (_j + _i); bvirt = (double) (ab3 - _j); avirt = ab3 - bvirt; bround = _i - bvirt; around = _j - avirt; ab[2] = around + bround; ab[3] = ab3; cxablen = scale_expansion_zeroelim(4, ab, cdx, cxab); cxxablen = scale_expansion_zeroelim(cxablen, cxab, cdx, cxxab); cyablen = scale_expansion_zeroelim(4, ab, cdy, cyab); cyyablen = scale_expansion_zeroelim(cyablen, cyab, cdy, cyyab); clen = fast_expansion_sum_zeroelim(cxxablen, cxxab, cyyablen, cyyab, cdet); ablen = fast_expansion_sum_zeroelim(alen, adet, blen, bdet, abdet); finlength = fast_expansion_sum_zeroelim(ablen, abdet, clen, cdet, fin1); det = estimate(finlength, fin1); errbound = iccerrboundB * permanent; if ((det >= errbound) || (-det >= errbound)) { return det; } bvirt = (double) (pa[0] - adx); avirt = adx + bvirt; bround = bvirt - pd[0]; around = pa[0] - avirt; adxtail = around + bround; bvirt = (double) (pa[1] - ady); avirt = ady + bvirt; bround = bvirt - pd[1]; around = pa[1] - avirt; adytail = around + bround; bvirt = (double) (pb[0] - bdx); avirt = bdx + bvirt; bround = bvirt - pd[0]; around = pb[0] - avirt; bdxtail = around + bround; bvirt = (double) (pb[1] - bdy); avirt = bdy + bvirt; bround = bvirt - pd[1]; around = pb[1] - avirt; bdytail = around + bround; bvirt = (double) (pc[0] - cdx); avirt = cdx + bvirt; bround = bvirt - pd[0]; around = pc[0] - avirt; cdxtail = around + bround; bvirt = (double) (pc[1] - cdy); avirt = cdy + bvirt; bround = bvirt - pd[1]; around = pc[1] - avirt; cdytail = around + bround; if ((adxtail == 0.0) && (bdxtail == 0.0) && (cdxtail == 0.0) && (adytail == 0.0) && (bdytail == 0.0) && (cdytail == 0.0)) { return det; } errbound = iccerrboundC * permanent + resulterrbound * ((det) >= 0.0 ? (det) : -(det)); det += ((adx * adx + ady * ady) * ((bdx * cdytail + cdy * bdxtail) - (bdy * cdxtail + cdx * bdytail)) + 2.0 * (adx * adxtail + ady * adytail) * (bdx * cdy - bdy * cdx)) + ((bdx * bdx + bdy * bdy) * ((cdx * adytail + ady * cdxtail) - (cdy * adxtail + adx * cdytail)) + 2.0 * (bdx * bdxtail + bdy * bdytail) * (cdx * ady - cdy * adx)) + ((cdx * cdx + cdy * cdy) * ((adx * bdytail + bdy * adxtail) - (ady * bdxtail + bdx * adytail)) + 2.0 * (cdx * cdxtail + cdy * cdytail) * (adx * bdy - ady * bdx)); if ((det >= errbound) || (-det >= errbound)) { return det; } finnow = fin1; finother = fin2; if ((bdxtail != 0.0) || (bdytail != 0.0) || (cdxtail != 0.0) || (cdytail != 0.0)) { adxadx1 = (double) (adx * adx); c = (double) (splitter * adx); abig = (double) (c - adx); ahi = c - abig; alo = adx - ahi; err1 = adxadx1 - (ahi * ahi); err3 = err1 - ((ahi + ahi) * alo); adxadx0 = (alo * alo) - err3; adyady1 = (double) (ady * ady); c = (double) (splitter * ady); abig = (double) (c - ady); ahi = c - abig; alo = ady - ahi; err1 = adyady1 - (ahi * ahi); err3 = err1 - ((ahi + ahi) * alo); adyady0 = (alo * alo) - err3; _i = (double) (adxadx0 + adyady0); bvirt = (double) (_i - adxadx0); avirt = _i - bvirt; bround = adyady0 - bvirt; around = adxadx0 - avirt; aa[0] = around + bround; _j = (double) (adxadx1 + _i); bvirt = (double) (_j - adxadx1); avirt = _j - bvirt; bround = _i - bvirt; around = adxadx1 - avirt; _0 = around + bround; _i = (double) (_0 + adyady1); bvirt = (double) (_i - _0); avirt = _i - bvirt; bround = adyady1 - bvirt; around = _0 - avirt; aa[1] = around + bround; aa3 = (double) (_j + _i); bvirt = (double) (aa3 - _j); avirt = aa3 - bvirt; bround = _i - bvirt; around = _j - avirt; aa[2] = around + bround; aa[3] = aa3; } if ((cdxtail != 0.0) || (cdytail != 0.0) || (adxtail != 0.0) || (adytail != 0.0)) { bdxbdx1 = (double) (bdx * bdx); c = (double) (splitter * bdx); abig = (double) (c - bdx); ahi = c - abig; alo = bdx - ahi; err1 = bdxbdx1 - (ahi * ahi); err3 = err1 - ((ahi + ahi) * alo); bdxbdx0 = (alo * alo) - err3; bdybdy1 = (double) (bdy * bdy); c = (double) (splitter * bdy); abig = (double) (c - bdy); ahi = c - abig; alo = bdy - ahi; err1 = bdybdy1 - (ahi * ahi); err3 = err1 - ((ahi + ahi) * alo); bdybdy0 = (alo * alo) - err3; _i = (double) (bdxbdx0 + bdybdy0); bvirt = (double) (_i - bdxbdx0); avirt = _i - bvirt; bround = bdybdy0 - bvirt; around = bdxbdx0 - avirt; bb[0] = around + bround; _j = (double) (bdxbdx1 + _i); bvirt = (double) (_j - bdxbdx1); avirt = _j - bvirt; bround = _i - bvirt; around = bdxbdx1 - avirt; _0 = around + bround; _i = (double) (_0 + bdybdy1); bvirt = (double) (_i - _0); avirt = _i - bvirt; bround = bdybdy1 - bvirt; around = _0 - avirt; bb[1] = around + bround; bb3 = (double) (_j + _i); bvirt = (double) (bb3 - _j); avirt = bb3 - bvirt; bround = _i - bvirt; around = _j - avirt; bb[2] = around + bround; bb[3] = bb3; } if ((adxtail != 0.0) || (adytail != 0.0) || (bdxtail != 0.0) || (bdytail != 0.0)) { cdxcdx1 = (double) (cdx * cdx); c = (double) (splitter * cdx); abig = (double) (c - cdx); ahi = c - abig; alo = cdx - ahi; err1 = cdxcdx1 - (ahi * ahi); err3 = err1 - ((ahi + ahi) * alo); cdxcdx0 = (alo * alo) - err3; cdycdy1 = (double) (cdy * cdy); c = (double) (splitter * cdy); abig = (double) (c - cdy); ahi = c - abig; alo = cdy - ahi; err1 = cdycdy1 - (ahi * ahi); err3 = err1 - ((ahi + ahi) * alo); cdycdy0 = (alo * alo) - err3; _i = (double) (cdxcdx0 + cdycdy0); bvirt = (double) (_i - cdxcdx0); avirt = _i - bvirt; bround = cdycdy0 - bvirt; around = cdxcdx0 - avirt; cc[0] = around + bround; _j = (double) (cdxcdx1 + _i); bvirt = (double) (_j - cdxcdx1); avirt = _j - bvirt; bround = _i - bvirt; around = cdxcdx1 - avirt; _0 = around + bround; _i = (double) (_0 + cdycdy1); bvirt = (double) (_i - _0); avirt = _i - bvirt; bround = cdycdy1 - bvirt; around = _0 - avirt; cc[1] = around + bround; cc3 = (double) (_j + _i); bvirt = (double) (cc3 - _j); avirt = cc3 - bvirt; bround = _i - bvirt; around = _j - avirt; cc[2] = around + bround; cc[3] = cc3; } if (adxtail != 0.0) { axtbclen = scale_expansion_zeroelim(4, bc, adxtail, axtbc); temp16alen = scale_expansion_zeroelim(axtbclen, axtbc, 2.0 * adx, temp16a); axtcclen = scale_expansion_zeroelim(4, cc, adxtail, axtcc); temp16blen = scale_expansion_zeroelim(axtcclen, axtcc, bdy, temp16b); axtbblen = scale_expansion_zeroelim(4, bb, adxtail, axtbb); temp16clen = scale_expansion_zeroelim(axtbblen, axtbb, -cdy, temp16c); temp32alen = fast_expansion_sum_zeroelim(temp16alen, temp16a, temp16blen, temp16b, temp32a); temp48len = fast_expansion_sum_zeroelim(temp16clen, temp16c, temp32alen, temp32a, temp48); finlength = fast_expansion_sum_zeroelim(finlength, finnow, temp48len, temp48, finother); finswap = finnow; finnow = finother; finother = finswap; } if (adytail != 0.0) { aytbclen = scale_expansion_zeroelim(4, bc, adytail, aytbc); temp16alen = scale_expansion_zeroelim(aytbclen, aytbc, 2.0 * ady, temp16a); aytbblen = scale_expansion_zeroelim(4, bb, adytail, aytbb); temp16blen = scale_expansion_zeroelim(aytbblen, aytbb, cdx, temp16b); aytcclen = scale_expansion_zeroelim(4, cc, adytail, aytcc); temp16clen = scale_expansion_zeroelim(aytcclen, aytcc, -bdx, temp16c); temp32alen = fast_expansion_sum_zeroelim(temp16alen, temp16a, temp16blen, temp16b, temp32a); temp48len = fast_expansion_sum_zeroelim(temp16clen, temp16c, temp32alen, temp32a, temp48); finlength = fast_expansion_sum_zeroelim(finlength, finnow, temp48len, temp48, finother); finswap = finnow; finnow = finother; finother = finswap; } if (bdxtail != 0.0) { bxtcalen = scale_expansion_zeroelim(4, ca, bdxtail, bxtca); temp16alen = scale_expansion_zeroelim(bxtcalen, bxtca, 2.0 * bdx, temp16a); bxtaalen = scale_expansion_zeroelim(4, aa, bdxtail, bxtaa); temp16blen = scale_expansion_zeroelim(bxtaalen, bxtaa, cdy, temp16b); bxtcclen = scale_expansion_zeroelim(4, cc, bdxtail, bxtcc); temp16clen = scale_expansion_zeroelim(bxtcclen, bxtcc, -ady, temp16c); temp32alen = fast_expansion_sum_zeroelim(temp16alen, temp16a, temp16blen, temp16b, temp32a); temp48len = fast_expansion_sum_zeroelim(temp16clen, temp16c, temp32alen, temp32a, temp48); finlength = fast_expansion_sum_zeroelim(finlength, finnow, temp48len, temp48, finother); finswap = finnow; finnow = finother; finother = finswap; } if (bdytail != 0.0) { bytcalen = scale_expansion_zeroelim(4, ca, bdytail, bytca); temp16alen = scale_expansion_zeroelim(bytcalen, bytca, 2.0 * bdy, temp16a); bytcclen = scale_expansion_zeroelim(4, cc, bdytail, bytcc); temp16blen = scale_expansion_zeroelim(bytcclen, bytcc, adx, temp16b); bytaalen = scale_expansion_zeroelim(4, aa, bdytail, bytaa); temp16clen = scale_expansion_zeroelim(bytaalen, bytaa, -cdx, temp16c); temp32alen = fast_expansion_sum_zeroelim(temp16alen, temp16a, temp16blen, temp16b, temp32a); temp48len = fast_expansion_sum_zeroelim(temp16clen, temp16c, temp32alen, temp32a, temp48); finlength = fast_expansion_sum_zeroelim(finlength, finnow, temp48len, temp48, finother); finswap = finnow; finnow = finother; finother = finswap; } if (cdxtail != 0.0) { cxtablen = scale_expansion_zeroelim(4, ab, cdxtail, cxtab); temp16alen = scale_expansion_zeroelim(cxtablen, cxtab, 2.0 * cdx, temp16a); cxtbblen = scale_expansion_zeroelim(4, bb, cdxtail, cxtbb); temp16blen = scale_expansion_zeroelim(cxtbblen, cxtbb, ady, temp16b); cxtaalen = scale_expansion_zeroelim(4, aa, cdxtail, cxtaa); temp16clen = scale_expansion_zeroelim(cxtaalen, cxtaa, -bdy, temp16c); temp32alen = fast_expansion_sum_zeroelim(temp16alen, temp16a, temp16blen, temp16b, temp32a); temp48len = fast_expansion_sum_zeroelim(temp16clen, temp16c, temp32alen, temp32a, temp48); finlength = fast_expansion_sum_zeroelim(finlength, finnow, temp48len, temp48, finother); finswap = finnow; finnow = finother; finother = finswap; } if (cdytail != 0.0) { cytablen = scale_expansion_zeroelim(4, ab, cdytail, cytab); temp16alen = scale_expansion_zeroelim(cytablen, cytab, 2.0 * cdy, temp16a); cytaalen = scale_expansion_zeroelim(4, aa, cdytail, cytaa); temp16blen = scale_expansion_zeroelim(cytaalen, cytaa, bdx, temp16b); cytbblen = scale_expansion_zeroelim(4, bb, cdytail, cytbb); temp16clen = scale_expansion_zeroelim(cytbblen, cytbb, -adx, temp16c); temp32alen = fast_expansion_sum_zeroelim(temp16alen, temp16a, temp16blen, temp16b, temp32a); temp48len = fast_expansion_sum_zeroelim(temp16clen, temp16c, temp32alen, temp32a, temp48); finlength = fast_expansion_sum_zeroelim(finlength, finnow, temp48len, temp48, finother); finswap = finnow; finnow = finother; finother = finswap; } if ((adxtail != 0.0) || (adytail != 0.0)) { if ((bdxtail != 0.0) || (bdytail != 0.0) || (cdxtail != 0.0) || (cdytail != 0.0)) { ti1 = (double) (bdxtail * cdy); c = (double) (splitter * bdxtail); abig = (double) (c - bdxtail); ahi = c - abig; alo = bdxtail - ahi; c = (double) (splitter * cdy); abig = (double) (c - cdy); bhi = c - abig; blo = cdy - bhi; err1 = ti1 - (ahi * bhi); err2 = err1 - (alo * bhi); err3 = err2 - (ahi * blo); ti0 = (alo * blo) - err3; tj1 = (double) (bdx * cdytail); c = (double) (splitter * bdx); abig = (double) (c - bdx); ahi = c - abig; alo = bdx - ahi; c = (double) (splitter * cdytail); abig = (double) (c - cdytail); bhi = c - abig; blo = cdytail - bhi; err1 = tj1 - (ahi * bhi); err2 = err1 - (alo * bhi); err3 = err2 - (ahi * blo); tj0 = (alo * blo) - err3; _i = (double) (ti0 + tj0); bvirt = (double) (_i - ti0); avirt = _i - bvirt; bround = tj0 - bvirt; around = ti0 - avirt; u[0] = around + bround; _j = (double) (ti1 + _i); bvirt = (double) (_j - ti1); avirt = _j - bvirt; bround = _i - bvirt; around = ti1 - avirt; _0 = around + bround; _i = (double) (_0 + tj1); bvirt = (double) (_i - _0); avirt = _i - bvirt; bround = tj1 - bvirt; around = _0 - avirt; u[1] = around + bround; u3 = (double) (_j + _i); bvirt = (double) (u3 - _j); avirt = u3 - bvirt; bround = _i - bvirt; around = _j - avirt; u[2] = around + bround; u[3] = u3; negate = -bdy; ti1 = (double) (cdxtail * negate); c = (double) (splitter * cdxtail); abig = (double) (c - cdxtail); ahi = c - abig; alo = cdxtail - ahi; c = (double) (splitter * negate); abig = (double) (c - negate); bhi = c - abig; blo = negate - bhi; err1 = ti1 - (ahi * bhi); err2 = err1 - (alo * bhi); err3 = err2 - (ahi * blo); ti0 = (alo * blo) - err3; negate = -bdytail; tj1 = (double) (cdx * negate); c = (double) (splitter * cdx); abig = (double) (c - cdx); ahi = c - abig; alo = cdx - ahi; c = (double) (splitter * negate); abig = (double) (c - negate); bhi = c - abig; blo = negate - bhi; err1 = tj1 - (ahi * bhi); err2 = err1 - (alo * bhi); err3 = err2 - (ahi * blo); tj0 = (alo * blo) - err3; _i = (double) (ti0 + tj0); bvirt = (double) (_i - ti0); avirt = _i - bvirt; bround = tj0 - bvirt; around = ti0 - avirt; v[0] = around + bround; _j = (double) (ti1 + _i); bvirt = (double) (_j - ti1); avirt = _j - bvirt; bround = _i - bvirt; around = ti1 - avirt; _0 = around + bround; _i = (double) (_0 + tj1); bvirt = (double) (_i - _0); avirt = _i - bvirt; bround = tj1 - bvirt; around = _0 - avirt; v[1] = around + bround; v3 = (double) (_j + _i); bvirt = (double) (v3 - _j); avirt = v3 - bvirt; bround = _i - bvirt; around = _j - avirt; v[2] = around + bround; v[3] = v3; bctlen = fast_expansion_sum_zeroelim(4, u, 4, v, bct); ti1 = (double) (bdxtail * cdytail); c = (double) (splitter * bdxtail); abig = (double) (c - bdxtail); ahi = c - abig; alo = bdxtail - ahi; c = (double) (splitter * cdytail); abig = (double) (c - cdytail); bhi = c - abig; blo = cdytail - bhi; err1 = ti1 - (ahi * bhi); err2 = err1 - (alo * bhi); err3 = err2 - (ahi * blo); ti0 = (alo * blo) - err3; tj1 = (double) (cdxtail * bdytail); c = (double) (splitter * cdxtail); abig = (double) (c - cdxtail); ahi = c - abig; alo = cdxtail - ahi; c = (double) (splitter * bdytail); abig = (double) (c - bdytail); bhi = c - abig; blo = bdytail - bhi; err1 = tj1 - (ahi * bhi); err2 = err1 - (alo * bhi); err3 = err2 - (ahi * blo); tj0 = (alo * blo) - err3; _i = (double) (ti0 - tj0); bvirt = (double) (ti0 - _i); avirt = _i + bvirt; bround = bvirt - tj0; around = ti0 - avirt; bctt[0] = around + bround; _j = (double) (ti1 + _i); bvirt = (double) (_j - ti1); avirt = _j - bvirt; bround = _i - bvirt; around = ti1 - avirt; _0 = around + bround; _i = (double) (_0 - tj1); bvirt = (double) (_0 - _i); avirt = _i + bvirt; bround = bvirt - tj1; around = _0 - avirt; bctt[1] = around + bround; bctt3 = (double) (_j + _i); bvirt = (double) (bctt3 - _j); avirt = bctt3 - bvirt; bround = _i - bvirt; around = _j - avirt; bctt[2] = around + bround; bctt[3] = bctt3; bcttlen = 4; } else { bct[0] = 0.0; bctlen = 1; bctt[0] = 0.0; bcttlen = 1; } if (adxtail != 0.0) { temp16alen = scale_expansion_zeroelim(axtbclen, axtbc, adxtail, temp16a); axtbctlen = scale_expansion_zeroelim(bctlen, bct, adxtail, axtbct); temp32alen = scale_expansion_zeroelim(axtbctlen, axtbct, 2.0 * adx, temp32a); temp48len = fast_expansion_sum_zeroelim(temp16alen, temp16a, temp32alen, temp32a, temp48); finlength = fast_expansion_sum_zeroelim(finlength, finnow, temp48len, temp48, finother); finswap = finnow; finnow = finother; finother = finswap; if (bdytail != 0.0) { temp8len = scale_expansion_zeroelim(4, cc, adxtail, temp8); temp16alen = scale_expansion_zeroelim(temp8len, temp8, bdytail, temp16a); finlength = fast_expansion_sum_zeroelim(finlength, finnow, temp16alen, temp16a, finother); finswap = finnow; finnow = finother; finother = finswap; } if (cdytail != 0.0) { temp8len = scale_expansion_zeroelim(4, bb, -adxtail, temp8); temp16alen = scale_expansion_zeroelim(temp8len, temp8, cdytail, temp16a); finlength = fast_expansion_sum_zeroelim(finlength, finnow, temp16alen, temp16a, finother); finswap = finnow; finnow = finother; finother = finswap; } temp32alen = scale_expansion_zeroelim(axtbctlen, axtbct, adxtail, temp32a); axtbcttlen = scale_expansion_zeroelim(bcttlen, bctt, adxtail, axtbctt); temp16alen = scale_expansion_zeroelim(axtbcttlen, axtbctt, 2.0 * adx, temp16a); temp16blen = scale_expansion_zeroelim(axtbcttlen, axtbctt, adxtail, temp16b); temp32blen = fast_expansion_sum_zeroelim(temp16alen, temp16a, temp16blen, temp16b, temp32b); temp64len = fast_expansion_sum_zeroelim(temp32alen, temp32a, temp32blen, temp32b, temp64); finlength = fast_expansion_sum_zeroelim(finlength, finnow, temp64len, temp64, finother); finswap = finnow; finnow = finother; finother = finswap; } if (adytail != 0.0) { temp16alen = scale_expansion_zeroelim(aytbclen, aytbc, adytail, temp16a); aytbctlen = scale_expansion_zeroelim(bctlen, bct, adytail, aytbct); temp32alen = scale_expansion_zeroelim(aytbctlen, aytbct, 2.0 * ady, temp32a); temp48len = fast_expansion_sum_zeroelim(temp16alen, temp16a, temp32alen, temp32a, temp48); finlength = fast_expansion_sum_zeroelim(finlength, finnow, temp48len, temp48, finother); finswap = finnow; finnow = finother; finother = finswap; temp32alen = scale_expansion_zeroelim(aytbctlen, aytbct, adytail, temp32a); aytbcttlen = scale_expansion_zeroelim(bcttlen, bctt, adytail, aytbctt); temp16alen = scale_expansion_zeroelim(aytbcttlen, aytbctt, 2.0 * ady, temp16a); temp16blen = scale_expansion_zeroelim(aytbcttlen, aytbctt, adytail, temp16b); temp32blen = fast_expansion_sum_zeroelim(temp16alen, temp16a, temp16blen, temp16b, temp32b); temp64len = fast_expansion_sum_zeroelim(temp32alen, temp32a, temp32blen, temp32b, temp64); finlength = fast_expansion_sum_zeroelim(finlength, finnow, temp64len, temp64, finother); finswap = finnow; finnow = finother; finother = finswap; } } if ((bdxtail != 0.0) || (bdytail != 0.0)) { if ((cdxtail != 0.0) || (cdytail != 0.0) || (adxtail != 0.0) || (adytail != 0.0)) { ti1 = (double) (cdxtail * ady); c = (double) (splitter * cdxtail); abig = (double) (c - cdxtail); ahi = c - abig; alo = cdxtail - ahi; c = (double) (splitter * ady); abig = (double) (c - ady); bhi = c - abig; blo = ady - bhi; err1 = ti1 - (ahi * bhi); err2 = err1 - (alo * bhi); err3 = err2 - (ahi * blo); ti0 = (alo * blo) - err3; tj1 = (double) (cdx * adytail); c = (double) (splitter * cdx); abig = (double) (c - cdx); ahi = c - abig; alo = cdx - ahi; c = (double) (splitter * adytail); abig = (double) (c - adytail); bhi = c - abig; blo = adytail - bhi; err1 = tj1 - (ahi * bhi); err2 = err1 - (alo * bhi); err3 = err2 - (ahi * blo); tj0 = (alo * blo) - err3; _i = (double) (ti0 + tj0); bvirt = (double) (_i - ti0); avirt = _i - bvirt; bround = tj0 - bvirt; around = ti0 - avirt; u[0] = around + bround; _j = (double) (ti1 + _i); bvirt = (double) (_j - ti1); avirt = _j - bvirt; bround = _i - bvirt; around = ti1 - avirt; _0 = around + bround; _i = (double) (_0 + tj1); bvirt = (double) (_i - _0); avirt = _i - bvirt; bround = tj1 - bvirt; around = _0 - avirt; u[1] = around + bround; u3 = (double) (_j + _i); bvirt = (double) (u3 - _j); avirt = u3 - bvirt; bround = _i - bvirt; around = _j - avirt; u[2] = around + bround; u[3] = u3; negate = -cdy; ti1 = (double) (adxtail * negate); c = (double) (splitter * adxtail); abig = (double) (c - adxtail); ahi = c - abig; alo = adxtail - ahi; c = (double) (splitter * negate); abig = (double) (c - negate); bhi = c - abig; blo = negate - bhi; err1 = ti1 - (ahi * bhi); err2 = err1 - (alo * bhi); err3 = err2 - (ahi * blo); ti0 = (alo * blo) - err3; negate = -cdytail; tj1 = (double) (adx * negate); c = (double) (splitter * adx); abig = (double) (c - adx); ahi = c - abig; alo = adx - ahi; c = (double) (splitter * negate); abig = (double) (c - negate); bhi = c - abig; blo = negate - bhi; err1 = tj1 - (ahi * bhi); err2 = err1 - (alo * bhi); err3 = err2 - (ahi * blo); tj0 = (alo * blo) - err3; _i = (double) (ti0 + tj0); bvirt = (double) (_i - ti0); avirt = _i - bvirt; bround = tj0 - bvirt; around = ti0 - avirt; v[0] = around + bround; _j = (double) (ti1 + _i); bvirt = (double) (_j - ti1); avirt = _j - bvirt; bround = _i - bvirt; around = ti1 - avirt; _0 = around + bround; _i = (double) (_0 + tj1); bvirt = (double) (_i - _0); avirt = _i - bvirt; bround = tj1 - bvirt; around = _0 - avirt; v[1] = around + bround; v3 = (double) (_j + _i); bvirt = (double) (v3 - _j); avirt = v3 - bvirt; bround = _i - bvirt; around = _j - avirt; v[2] = around + bround; v[3] = v3; catlen = fast_expansion_sum_zeroelim(4, u, 4, v, cat); ti1 = (double) (cdxtail * adytail); c = (double) (splitter * cdxtail); abig = (double) (c - cdxtail); ahi = c - abig; alo = cdxtail - ahi; c = (double) (splitter * adytail); abig = (double) (c - adytail); bhi = c - abig; blo = adytail - bhi; err1 = ti1 - (ahi * bhi); err2 = err1 - (alo * bhi); err3 = err2 - (ahi * blo); ti0 = (alo * blo) - err3; tj1 = (double) (adxtail * cdytail); c = (double) (splitter * adxtail); abig = (double) (c - adxtail); ahi = c - abig; alo = adxtail - ahi; c = (double) (splitter * cdytail); abig = (double) (c - cdytail); bhi = c - abig; blo = cdytail - bhi; err1 = tj1 - (ahi * bhi); err2 = err1 - (alo * bhi); err3 = err2 - (ahi * blo); tj0 = (alo * blo) - err3; _i = (double) (ti0 - tj0); bvirt = (double) (ti0 - _i); avirt = _i + bvirt; bround = bvirt - tj0; around = ti0 - avirt; catt[0] = around + bround; _j = (double) (ti1 + _i); bvirt = (double) (_j - ti1); avirt = _j - bvirt; bround = _i - bvirt; around = ti1 - avirt; _0 = around + bround; _i = (double) (_0 - tj1); bvirt = (double) (_0 - _i); avirt = _i + bvirt; bround = bvirt - tj1; around = _0 - avirt; catt[1] = around + bround; catt3 = (double) (_j + _i); bvirt = (double) (catt3 - _j); avirt = catt3 - bvirt; bround = _i - bvirt; around = _j - avirt; catt[2] = around + bround; catt[3] = catt3; cattlen = 4; } else { cat[0] = 0.0; catlen = 1; catt[0] = 0.0; cattlen = 1; } if (bdxtail != 0.0) { temp16alen = scale_expansion_zeroelim(bxtcalen, bxtca, bdxtail, temp16a); bxtcatlen = scale_expansion_zeroelim(catlen, cat, bdxtail, bxtcat); temp32alen = scale_expansion_zeroelim(bxtcatlen, bxtcat, 2.0 * bdx, temp32a); temp48len = fast_expansion_sum_zeroelim(temp16alen, temp16a, temp32alen, temp32a, temp48); finlength = fast_expansion_sum_zeroelim(finlength, finnow, temp48len, temp48, finother); finswap = finnow; finnow = finother; finother = finswap; if (cdytail != 0.0) { temp8len = scale_expansion_zeroelim(4, aa, bdxtail, temp8); temp16alen = scale_expansion_zeroelim(temp8len, temp8, cdytail, temp16a); finlength = fast_expansion_sum_zeroelim(finlength, finnow, temp16alen, temp16a, finother); finswap = finnow; finnow = finother; finother = finswap; } if (adytail != 0.0) { temp8len = scale_expansion_zeroelim(4, cc, -bdxtail, temp8); temp16alen = scale_expansion_zeroelim(temp8len, temp8, adytail, temp16a); finlength = fast_expansion_sum_zeroelim(finlength, finnow, temp16alen, temp16a, finother); finswap = finnow; finnow = finother; finother = finswap; } temp32alen = scale_expansion_zeroelim(bxtcatlen, bxtcat, bdxtail, temp32a); bxtcattlen = scale_expansion_zeroelim(cattlen, catt, bdxtail, bxtcatt); temp16alen = scale_expansion_zeroelim(bxtcattlen, bxtcatt, 2.0 * bdx, temp16a); temp16blen = scale_expansion_zeroelim(bxtcattlen, bxtcatt, bdxtail, temp16b); temp32blen = fast_expansion_sum_zeroelim(temp16alen, temp16a, temp16blen, temp16b, temp32b); temp64len = fast_expansion_sum_zeroelim(temp32alen, temp32a, temp32blen, temp32b, temp64); finlength = fast_expansion_sum_zeroelim(finlength, finnow, temp64len, temp64, finother); finswap = finnow; finnow = finother; finother = finswap; } if (bdytail != 0.0) { temp16alen = scale_expansion_zeroelim(bytcalen, bytca, bdytail, temp16a); bytcatlen = scale_expansion_zeroelim(catlen, cat, bdytail, bytcat); temp32alen = scale_expansion_zeroelim(bytcatlen, bytcat, 2.0 * bdy, temp32a); temp48len = fast_expansion_sum_zeroelim(temp16alen, temp16a, temp32alen, temp32a, temp48); finlength = fast_expansion_sum_zeroelim(finlength, finnow, temp48len, temp48, finother); finswap = finnow; finnow = finother; finother = finswap; temp32alen = scale_expansion_zeroelim(bytcatlen, bytcat, bdytail, temp32a); bytcattlen = scale_expansion_zeroelim(cattlen, catt, bdytail, bytcatt); temp16alen = scale_expansion_zeroelim(bytcattlen, bytcatt, 2.0 * bdy, temp16a); temp16blen = scale_expansion_zeroelim(bytcattlen, bytcatt, bdytail, temp16b); temp32blen = fast_expansion_sum_zeroelim(temp16alen, temp16a, temp16blen, temp16b, temp32b); temp64len = fast_expansion_sum_zeroelim(temp32alen, temp32a, temp32blen, temp32b, temp64); finlength = fast_expansion_sum_zeroelim(finlength, finnow, temp64len, temp64, finother); finswap = finnow; finnow = finother; finother = finswap; } } if ((cdxtail != 0.0) || (cdytail != 0.0)) { if ((adxtail != 0.0) || (adytail != 0.0) || (bdxtail != 0.0) || (bdytail != 0.0)) { ti1 = (double) (adxtail * bdy); c = (double) (splitter * adxtail); abig = (double) (c - adxtail); ahi = c - abig; alo = adxtail - ahi; c = (double) (splitter * bdy); abig = (double) (c - bdy); bhi = c - abig; blo = bdy - bhi; err1 = ti1 - (ahi * bhi); err2 = err1 - (alo * bhi); err3 = err2 - (ahi * blo); ti0 = (alo * blo) - err3; tj1 = (double) (adx * bdytail); c = (double) (splitter * adx); abig = (double) (c - adx); ahi = c - abig; alo = adx - ahi; c = (double) (splitter * bdytail); abig = (double) (c - bdytail); bhi = c - abig; blo = bdytail - bhi; err1 = tj1 - (ahi * bhi); err2 = err1 - (alo * bhi); err3 = err2 - (ahi * blo); tj0 = (alo * blo) - err3; _i = (double) (ti0 + tj0); bvirt = (double) (_i - ti0); avirt = _i - bvirt; bround = tj0 - bvirt; around = ti0 - avirt; u[0] = around + bround; _j = (double) (ti1 + _i); bvirt = (double) (_j - ti1); avirt = _j - bvirt; bround = _i - bvirt; around = ti1 - avirt; _0 = around + bround; _i = (double) (_0 + tj1); bvirt = (double) (_i - _0); avirt = _i - bvirt; bround = tj1 - bvirt; around = _0 - avirt; u[1] = around + bround; u3 = (double) (_j + _i); bvirt = (double) (u3 - _j); avirt = u3 - bvirt; bround = _i - bvirt; around = _j - avirt; u[2] = around + bround; u[3] = u3; negate = -ady; ti1 = (double) (bdxtail * negate); c = (double) (splitter * bdxtail); abig = (double) (c - bdxtail); ahi = c - abig; alo = bdxtail - ahi; c = (double) (splitter * negate); abig = (double) (c - negate); bhi = c - abig; blo = negate - bhi; err1 = ti1 - (ahi * bhi); err2 = err1 - (alo * bhi); err3 = err2 - (ahi * blo); ti0 = (alo * blo) - err3; negate = -adytail; tj1 = (double) (bdx * negate); c = (double) (splitter * bdx); abig = (double) (c - bdx); ahi = c - abig; alo = bdx - ahi; c = (double) (splitter * negate); abig = (double) (c - negate); bhi = c - abig; blo = negate - bhi; err1 = tj1 - (ahi * bhi); err2 = err1 - (alo * bhi); err3 = err2 - (ahi * blo); tj0 = (alo * blo) - err3; _i = (double) (ti0 + tj0); bvirt = (double) (_i - ti0); avirt = _i - bvirt; bround = tj0 - bvirt; around = ti0 - avirt; v[0] = around + bround; _j = (double) (ti1 + _i); bvirt = (double) (_j - ti1); avirt = _j - bvirt; bround = _i - bvirt; around = ti1 - avirt; _0 = around + bround; _i = (double) (_0 + tj1); bvirt = (double) (_i - _0); avirt = _i - bvirt; bround = tj1 - bvirt; around = _0 - avirt; v[1] = around + bround; v3 = (double) (_j + _i); bvirt = (double) (v3 - _j); avirt = v3 - bvirt; bround = _i - bvirt; around = _j - avirt; v[2] = around + bround; v[3] = v3; abtlen = fast_expansion_sum_zeroelim(4, u, 4, v, abt); ti1 = (double) (adxtail * bdytail); c = (double) (splitter * adxtail); abig = (double) (c - adxtail); ahi = c - abig; alo = adxtail - ahi; c = (double) (splitter * bdytail); abig = (double) (c - bdytail); bhi = c - abig; blo = bdytail - bhi; err1 = ti1 - (ahi * bhi); err2 = err1 - (alo * bhi); err3 = err2 - (ahi * blo); ti0 = (alo * blo) - err3; tj1 = (double) (bdxtail * adytail); c = (double) (splitter * bdxtail); abig = (double) (c - bdxtail); ahi = c - abig; alo = bdxtail - ahi; c = (double) (splitter * adytail); abig = (double) (c - adytail); bhi = c - abig; blo = adytail - bhi; err1 = tj1 - (ahi * bhi); err2 = err1 - (alo * bhi); err3 = err2 - (ahi * blo); tj0 = (alo * blo) - err3; _i = (double) (ti0 - tj0); bvirt = (double) (ti0 - _i); avirt = _i + bvirt; bround = bvirt - tj0; around = ti0 - avirt; abtt[0] = around + bround; _j = (double) (ti1 + _i); bvirt = (double) (_j - ti1); avirt = _j - bvirt; bround = _i - bvirt; around = ti1 - avirt; _0 = around + bround; _i = (double) (_0 - tj1); bvirt = (double) (_0 - _i); avirt = _i + bvirt; bround = bvirt - tj1; around = _0 - avirt; abtt[1] = around + bround; abtt3 = (double) (_j + _i); bvirt = (double) (abtt3 - _j); avirt = abtt3 - bvirt; bround = _i - bvirt; around = _j - avirt; abtt[2] = around + bround; abtt[3] = abtt3; abttlen = 4; } else { abt[0] = 0.0; abtlen = 1; abtt[0] = 0.0; abttlen = 1; } if (cdxtail != 0.0) { temp16alen = scale_expansion_zeroelim(cxtablen, cxtab, cdxtail, temp16a); cxtabtlen = scale_expansion_zeroelim(abtlen, abt, cdxtail, cxtabt); temp32alen = scale_expansion_zeroelim(cxtabtlen, cxtabt, 2.0 * cdx, temp32a); temp48len = fast_expansion_sum_zeroelim(temp16alen, temp16a, temp32alen, temp32a, temp48); finlength = fast_expansion_sum_zeroelim(finlength, finnow, temp48len, temp48, finother); finswap = finnow; finnow = finother; finother = finswap; if (adytail != 0.0) { temp8len = scale_expansion_zeroelim(4, bb, cdxtail, temp8); temp16alen = scale_expansion_zeroelim(temp8len, temp8, adytail, temp16a); finlength = fast_expansion_sum_zeroelim(finlength, finnow, temp16alen, temp16a, finother); finswap = finnow; finnow = finother; finother = finswap; } if (bdytail != 0.0) { temp8len = scale_expansion_zeroelim(4, aa, -cdxtail, temp8); temp16alen = scale_expansion_zeroelim(temp8len, temp8, bdytail, temp16a); finlength = fast_expansion_sum_zeroelim(finlength, finnow, temp16alen, temp16a, finother); finswap = finnow; finnow = finother; finother = finswap; } temp32alen = scale_expansion_zeroelim(cxtabtlen, cxtabt, cdxtail, temp32a); cxtabttlen = scale_expansion_zeroelim(abttlen, abtt, cdxtail, cxtabtt); temp16alen = scale_expansion_zeroelim(cxtabttlen, cxtabtt, 2.0 * cdx, temp16a); temp16blen = scale_expansion_zeroelim(cxtabttlen, cxtabtt, cdxtail, temp16b); temp32blen = fast_expansion_sum_zeroelim(temp16alen, temp16a, temp16blen, temp16b, temp32b); temp64len = fast_expansion_sum_zeroelim(temp32alen, temp32a, temp32blen, temp32b, temp64); finlength = fast_expansion_sum_zeroelim(finlength, finnow, temp64len, temp64, finother); finswap = finnow; finnow = finother; finother = finswap; } if (cdytail != 0.0) { temp16alen = scale_expansion_zeroelim(cytablen, cytab, cdytail, temp16a); cytabtlen = scale_expansion_zeroelim(abtlen, abt, cdytail, cytabt); temp32alen = scale_expansion_zeroelim(cytabtlen, cytabt, 2.0 * cdy, temp32a); temp48len = fast_expansion_sum_zeroelim(temp16alen, temp16a, temp32alen, temp32a, temp48); finlength = fast_expansion_sum_zeroelim(finlength, finnow, temp48len, temp48, finother); finswap = finnow; finnow = finother; finother = finswap; temp32alen = scale_expansion_zeroelim(cytabtlen, cytabt, cdytail, temp32a); cytabttlen = scale_expansion_zeroelim(abttlen, abtt, cdytail, cytabtt); temp16alen = scale_expansion_zeroelim(cytabttlen, cytabtt, 2.0 * cdy, temp16a); temp16blen = scale_expansion_zeroelim(cytabttlen, cytabtt, cdytail, temp16b); temp32blen = fast_expansion_sum_zeroelim(temp16alen, temp16a, temp16blen, temp16b, temp32b); temp64len = fast_expansion_sum_zeroelim(temp32alen, temp32a, temp32blen, temp32b, temp64); finlength = fast_expansion_sum_zeroelim(finlength, finnow, temp64len, temp64, finother); finswap = finnow; finnow = finother; finother = finswap; } } return finnow[finlength - 1]; } double incircle(m, b, pa, pb, pc, pd) struct mesh *m; struct behavior *b; vertex pa; vertex pb; vertex pc; vertex pd; { double adx, bdx, cdx, ady, bdy, cdy; double bdxcdy, cdxbdy, cdxady, adxcdy, adxbdy, bdxady; double alift, blift, clift; double det; double permanent, errbound; m->incirclecount++; adx = pa[0] - pd[0]; bdx = pb[0] - pd[0]; cdx = pc[0] - pd[0]; ady = pa[1] - pd[1]; bdy = pb[1] - pd[1]; cdy = pc[1] - pd[1]; bdxcdy = bdx * cdy; cdxbdy = cdx * bdy; alift = adx * adx + ady * ady; cdxady = cdx * ady; adxcdy = adx * cdy; blift = bdx * bdx + bdy * bdy; adxbdy = adx * bdy; bdxady = bdx * ady; clift = cdx * cdx + cdy * cdy; det = alift * (bdxcdy - cdxbdy) + blift * (cdxady - adxcdy) + clift * (adxbdy - bdxady); if (b->noexact) { return det; } permanent = (((bdxcdy) >= 0.0 ? (bdxcdy) : -(bdxcdy)) + ((cdxbdy) >= 0.0 ? (cdxbdy) : -(cdxbdy))) * alift + (((cdxady) >= 0.0 ? (cdxady) : -(cdxady)) + ((adxcdy) >= 0.0 ? (adxcdy) : -(adxcdy))) * blift + (((adxbdy) >= 0.0 ? (adxbdy) : -(adxbdy)) + ((bdxady) >= 0.0 ? (bdxady) : -(bdxady))) * clift; errbound = iccerrboundA * permanent; if ((det > errbound) || (-det > errbound)) { return det; } return incircleadapt(pa, pb, pc, pd, permanent); } # 5783 "triangle.c" double orient3dadapt(pa, pb, pc, pd, aheight, bheight, cheight, dheight, permanent) vertex pa; vertex pb; vertex pc; vertex pd; double aheight; double bheight; double cheight; double dheight; double permanent; { double adx, bdx, cdx, ady, bdy, cdy, adheight, bdheight, cdheight; double det, errbound; double bdxcdy1, cdxbdy1, cdxady1, adxcdy1, adxbdy1, bdxady1; double bdxcdy0, cdxbdy0, cdxady0, adxcdy0, adxbdy0, bdxady0; double bc[4], ca[4], ab[4]; double bc3, ca3, ab3; double adet[8], bdet[8], cdet[8]; int alen, blen, clen; double abdet[16]; int ablen; double *finnow, *finother, *finswap; double fin1[192], fin2[192]; int finlength; double adxtail, bdxtail, cdxtail; double adytail, bdytail, cdytail; double adheighttail, bdheighttail, cdheighttail; double at_blarge, at_clarge; double bt_clarge, bt_alarge; double ct_alarge, ct_blarge; double at_b[4], at_c[4], bt_c[4], bt_a[4], ct_a[4], ct_b[4]; int at_blen, at_clen, bt_clen, bt_alen, ct_alen, ct_blen; double bdxt_cdy1, cdxt_bdy1, cdxt_ady1; double adxt_cdy1, adxt_bdy1, bdxt_ady1; double bdxt_cdy0, cdxt_bdy0, cdxt_ady0; double adxt_cdy0, adxt_bdy0, bdxt_ady0; double bdyt_cdx1, cdyt_bdx1, cdyt_adx1; double adyt_cdx1, adyt_bdx1, bdyt_adx1; double bdyt_cdx0, cdyt_bdx0, cdyt_adx0; double adyt_cdx0, adyt_bdx0, bdyt_adx0; double bct[8], cat[8], abt[8]; int bctlen, catlen, abtlen; double bdxt_cdyt1, cdxt_bdyt1, cdxt_adyt1; double adxt_cdyt1, adxt_bdyt1, bdxt_adyt1; double bdxt_cdyt0, cdxt_bdyt0, cdxt_adyt0; double adxt_cdyt0, adxt_bdyt0, bdxt_adyt0; double u[4], v[12], w[16]; double u3; int vlength, wlength; double negate; double bvirt; double avirt, bround, around; double c; double abig; double ahi, alo, bhi, blo; double err1, err2, err3; double _i, _j, _k; double _0; adx = (double) (pa[0] - pd[0]); bdx = (double) (pb[0] - pd[0]); cdx = (double) (pc[0] - pd[0]); ady = (double) (pa[1] - pd[1]); bdy = (double) (pb[1] - pd[1]); cdy = (double) (pc[1] - pd[1]); adheight = (double) (aheight - dheight); bdheight = (double) (bheight - dheight); cdheight = (double) (cheight - dheight); bdxcdy1 = (double) (bdx * cdy); c = (double) (splitter * bdx); abig = (double) (c - bdx); ahi = c - abig; alo = bdx - ahi; c = (double) (splitter * cdy); abig = (double) (c - cdy); bhi = c - abig; blo = cdy - bhi; err1 = bdxcdy1 - (ahi * bhi); err2 = err1 - (alo * bhi); err3 = err2 - (ahi * blo); bdxcdy0 = (alo * blo) - err3; cdxbdy1 = (double) (cdx * bdy); c = (double) (splitter * cdx); abig = (double) (c - cdx); ahi = c - abig; alo = cdx - ahi; c = (double) (splitter * bdy); abig = (double) (c - bdy); bhi = c - abig; blo = bdy - bhi; err1 = cdxbdy1 - (ahi * bhi); err2 = err1 - (alo * bhi); err3 = err2 - (ahi * blo); cdxbdy0 = (alo * blo) - err3; _i = (double) (bdxcdy0 - cdxbdy0); bvirt = (double) (bdxcdy0 - _i); avirt = _i + bvirt; bround = bvirt - cdxbdy0; around = bdxcdy0 - avirt; bc[0] = around + bround; _j = (double) (bdxcdy1 + _i); bvirt = (double) (_j - bdxcdy1); avirt = _j - bvirt; bround = _i - bvirt; around = bdxcdy1 - avirt; _0 = around + bround; _i = (double) (_0 - cdxbdy1); bvirt = (double) (_0 - _i); avirt = _i + bvirt; bround = bvirt - cdxbdy1; around = _0 - avirt; bc[1] = around + bround; bc3 = (double) (_j + _i); bvirt = (double) (bc3 - _j); avirt = bc3 - bvirt; bround = _i - bvirt; around = _j - avirt; bc[2] = around + bround; bc[3] = bc3; alen = scale_expansion_zeroelim(4, bc, adheight, adet); cdxady1 = (double) (cdx * ady); c = (double) (splitter * cdx); abig = (double) (c - cdx); ahi = c - abig; alo = cdx - ahi; c = (double) (splitter * ady); abig = (double) (c - ady); bhi = c - abig; blo = ady - bhi; err1 = cdxady1 - (ahi * bhi); err2 = err1 - (alo * bhi); err3 = err2 - (ahi * blo); cdxady0 = (alo * blo) - err3; adxcdy1 = (double) (adx * cdy); c = (double) (splitter * adx); abig = (double) (c - adx); ahi = c - abig; alo = adx - ahi; c = (double) (splitter * cdy); abig = (double) (c - cdy); bhi = c - abig; blo = cdy - bhi; err1 = adxcdy1 - (ahi * bhi); err2 = err1 - (alo * bhi); err3 = err2 - (ahi * blo); adxcdy0 = (alo * blo) - err3; _i = (double) (cdxady0 - adxcdy0); bvirt = (double) (cdxady0 - _i); avirt = _i + bvirt; bround = bvirt - adxcdy0; around = cdxady0 - avirt; ca[0] = around + bround; _j = (double) (cdxady1 + _i); bvirt = (double) (_j - cdxady1); avirt = _j - bvirt; bround = _i - bvirt; around = cdxady1 - avirt; _0 = around + bround; _i = (double) (_0 - adxcdy1); bvirt = (double) (_0 - _i); avirt = _i + bvirt; bround = bvirt - adxcdy1; around = _0 - avirt; ca[1] = around + bround; ca3 = (double) (_j + _i); bvirt = (double) (ca3 - _j); avirt = ca3 - bvirt; bround = _i - bvirt; around = _j - avirt; ca[2] = around + bround; ca[3] = ca3; blen = scale_expansion_zeroelim(4, ca, bdheight, bdet); adxbdy1 = (double) (adx * bdy); c = (double) (splitter * adx); abig = (double) (c - adx); ahi = c - abig; alo = adx - ahi; c = (double) (splitter * bdy); abig = (double) (c - bdy); bhi = c - abig; blo = bdy - bhi; err1 = adxbdy1 - (ahi * bhi); err2 = err1 - (alo * bhi); err3 = err2 - (ahi * blo); adxbdy0 = (alo * blo) - err3; bdxady1 = (double) (bdx * ady); c = (double) (splitter * bdx); abig = (double) (c - bdx); ahi = c - abig; alo = bdx - ahi; c = (double) (splitter * ady); abig = (double) (c - ady); bhi = c - abig; blo = ady - bhi; err1 = bdxady1 - (ahi * bhi); err2 = err1 - (alo * bhi); err3 = err2 - (ahi * blo); bdxady0 = (alo * blo) - err3; _i = (double) (adxbdy0 - bdxady0); bvirt = (double) (adxbdy0 - _i); avirt = _i + bvirt; bround = bvirt - bdxady0; around = adxbdy0 - avirt; ab[0] = around + bround; _j = (double) (adxbdy1 + _i); bvirt = (double) (_j - adxbdy1); avirt = _j - bvirt; bround = _i - bvirt; around = adxbdy1 - avirt; _0 = around + bround; _i = (double) (_0 - bdxady1); bvirt = (double) (_0 - _i); avirt = _i + bvirt; bround = bvirt - bdxady1; around = _0 - avirt; ab[1] = around + bround; ab3 = (double) (_j + _i); bvirt = (double) (ab3 - _j); avirt = ab3 - bvirt; bround = _i - bvirt; around = _j - avirt; ab[2] = around + bround; ab[3] = ab3; clen = scale_expansion_zeroelim(4, ab, cdheight, cdet); ablen = fast_expansion_sum_zeroelim(alen, adet, blen, bdet, abdet); finlength = fast_expansion_sum_zeroelim(ablen, abdet, clen, cdet, fin1); det = estimate(finlength, fin1); errbound = o3derrboundB * permanent; if ((det >= errbound) || (-det >= errbound)) { return det; } bvirt = (double) (pa[0] - adx); avirt = adx + bvirt; bround = bvirt - pd[0]; around = pa[0] - avirt; adxtail = around + bround; bvirt = (double) (pb[0] - bdx); avirt = bdx + bvirt; bround = bvirt - pd[0]; around = pb[0] - avirt; bdxtail = around + bround; bvirt = (double) (pc[0] - cdx); avirt = cdx + bvirt; bround = bvirt - pd[0]; around = pc[0] - avirt; cdxtail = around + bround; bvirt = (double) (pa[1] - ady); avirt = ady + bvirt; bround = bvirt - pd[1]; around = pa[1] - avirt; adytail = around + bround; bvirt = (double) (pb[1] - bdy); avirt = bdy + bvirt; bround = bvirt - pd[1]; around = pb[1] - avirt; bdytail = around + bround; bvirt = (double) (pc[1] - cdy); avirt = cdy + bvirt; bround = bvirt - pd[1]; around = pc[1] - avirt; cdytail = around + bround; bvirt = (double) (aheight - adheight); avirt = adheight + bvirt; bround = bvirt - dheight; around = aheight - avirt; adheighttail = around + bround; bvirt = (double) (bheight - bdheight); avirt = bdheight + bvirt; bround = bvirt - dheight; around = bheight - avirt; bdheighttail = around + bround; bvirt = (double) (cheight - cdheight); avirt = cdheight + bvirt; bround = bvirt - dheight; around = cheight - avirt; cdheighttail = around + bround; if ((adxtail == 0.0) && (bdxtail == 0.0) && (cdxtail == 0.0) && (adytail == 0.0) && (bdytail == 0.0) && (cdytail == 0.0) && (adheighttail == 0.0) && (bdheighttail == 0.0) && (cdheighttail == 0.0)) { return det; } errbound = o3derrboundC * permanent + resulterrbound * ((det) >= 0.0 ? (det) : -(det)); det += (adheight * ((bdx * cdytail + cdy * bdxtail) - (bdy * cdxtail + cdx * bdytail)) + adheighttail * (bdx * cdy - bdy * cdx)) + (bdheight * ((cdx * adytail + ady * cdxtail) - (cdy * adxtail + adx * cdytail)) + bdheighttail * (cdx * ady - cdy * adx)) + (cdheight * ((adx * bdytail + bdy * adxtail) - (ady * bdxtail + bdx * adytail)) + cdheighttail * (adx * bdy - ady * bdx)); if ((det >= errbound) || (-det >= errbound)) { return det; } finnow = fin1; finother = fin2; if (adxtail == 0.0) { if (adytail == 0.0) { at_b[0] = 0.0; at_blen = 1; at_c[0] = 0.0; at_clen = 1; } else { negate = -adytail; at_blarge = (double) (negate * bdx); c = (double) (splitter * negate); abig = (double) (c - negate); ahi = c - abig; alo = negate - ahi; c = (double) (splitter * bdx); abig = (double) (c - bdx); bhi = c - abig; blo = bdx - bhi; err1 = at_blarge - (ahi * bhi); err2 = err1 - (alo * bhi); err3 = err2 - (ahi * blo); at_b[0] = (alo * blo) - err3; at_b[1] = at_blarge; at_blen = 2; at_clarge = (double) (adytail * cdx); c = (double) (splitter * adytail); abig = (double) (c - adytail); ahi = c - abig; alo = adytail - ahi; c = (double) (splitter * cdx); abig = (double) (c - cdx); bhi = c - abig; blo = cdx - bhi; err1 = at_clarge - (ahi * bhi); err2 = err1 - (alo * bhi); err3 = err2 - (ahi * blo); at_c[0] = (alo * blo) - err3; at_c[1] = at_clarge; at_clen = 2; } } else { if (adytail == 0.0) { at_blarge = (double) (adxtail * bdy); c = (double) (splitter * adxtail); abig = (double) (c - adxtail); ahi = c - abig; alo = adxtail - ahi; c = (double) (splitter * bdy); abig = (double) (c - bdy); bhi = c - abig; blo = bdy - bhi; err1 = at_blarge - (ahi * bhi); err2 = err1 - (alo * bhi); err3 = err2 - (ahi * blo); at_b[0] = (alo * blo) - err3; at_b[1] = at_blarge; at_blen = 2; negate = -adxtail; at_clarge = (double) (negate * cdy); c = (double) (splitter * negate); abig = (double) (c - negate); ahi = c - abig; alo = negate - ahi; c = (double) (splitter * cdy); abig = (double) (c - cdy); bhi = c - abig; blo = cdy - bhi; err1 = at_clarge - (ahi * bhi); err2 = err1 - (alo * bhi); err3 = err2 - (ahi * blo); at_c[0] = (alo * blo) - err3; at_c[1] = at_clarge; at_clen = 2; } else { adxt_bdy1 = (double) (adxtail * bdy); c = (double) (splitter * adxtail); abig = (double) (c - adxtail); ahi = c - abig; alo = adxtail - ahi; c = (double) (splitter * bdy); abig = (double) (c - bdy); bhi = c - abig; blo = bdy - bhi; err1 = adxt_bdy1 - (ahi * bhi); err2 = err1 - (alo * bhi); err3 = err2 - (ahi * blo); adxt_bdy0 = (alo * blo) - err3; adyt_bdx1 = (double) (adytail * bdx); c = (double) (splitter * adytail); abig = (double) (c - adytail); ahi = c - abig; alo = adytail - ahi; c = (double) (splitter * bdx); abig = (double) (c - bdx); bhi = c - abig; blo = bdx - bhi; err1 = adyt_bdx1 - (ahi * bhi); err2 = err1 - (alo * bhi); err3 = err2 - (ahi * blo); adyt_bdx0 = (alo * blo) - err3; _i = (double) (adxt_bdy0 - adyt_bdx0); bvirt = (double) (adxt_bdy0 - _i); avirt = _i + bvirt; bround = bvirt - adyt_bdx0; around = adxt_bdy0 - avirt; at_b[0] = around + bround; _j = (double) (adxt_bdy1 + _i); bvirt = (double) (_j - adxt_bdy1); avirt = _j - bvirt; bround = _i - bvirt; around = adxt_bdy1 - avirt; _0 = around + bround; _i = (double) (_0 - adyt_bdx1); bvirt = (double) (_0 - _i); avirt = _i + bvirt; bround = bvirt - adyt_bdx1; around = _0 - avirt; at_b[1] = around + bround; at_blarge = (double) (_j + _i); bvirt = (double) (at_blarge - _j); avirt = at_blarge - bvirt; bround = _i - bvirt; around = _j - avirt; at_b[2] = around + bround; at_b[3] = at_blarge; at_blen = 4; adyt_cdx1 = (double) (adytail * cdx); c = (double) (splitter * adytail); abig = (double) (c - adytail); ahi = c - abig; alo = adytail - ahi; c = (double) (splitter * cdx); abig = (double) (c - cdx); bhi = c - abig; blo = cdx - bhi; err1 = adyt_cdx1 - (ahi * bhi); err2 = err1 - (alo * bhi); err3 = err2 - (ahi * blo); adyt_cdx0 = (alo * blo) - err3; adxt_cdy1 = (double) (adxtail * cdy); c = (double) (splitter * adxtail); abig = (double) (c - adxtail); ahi = c - abig; alo = adxtail - ahi; c = (double) (splitter * cdy); abig = (double) (c - cdy); bhi = c - abig; blo = cdy - bhi; err1 = adxt_cdy1 - (ahi * bhi); err2 = err1 - (alo * bhi); err3 = err2 - (ahi * blo); adxt_cdy0 = (alo * blo) - err3; _i = (double) (adyt_cdx0 - adxt_cdy0); bvirt = (double) (adyt_cdx0 - _i); avirt = _i + bvirt; bround = bvirt - adxt_cdy0; around = adyt_cdx0 - avirt; at_c[0] = around + bround; _j = (double) (adyt_cdx1 + _i); bvirt = (double) (_j - adyt_cdx1); avirt = _j - bvirt; bround = _i - bvirt; around = adyt_cdx1 - avirt; _0 = around + bround; _i = (double) (_0 - adxt_cdy1); bvirt = (double) (_0 - _i); avirt = _i + bvirt; bround = bvirt - adxt_cdy1; around = _0 - avirt; at_c[1] = around + bround; at_clarge = (double) (_j + _i); bvirt = (double) (at_clarge - _j); avirt = at_clarge - bvirt; bround = _i - bvirt; around = _j - avirt; at_c[2] = around + bround; at_c[3] = at_clarge; at_clen = 4; } } if (bdxtail == 0.0) { if (bdytail == 0.0) { bt_c[0] = 0.0; bt_clen = 1; bt_a[0] = 0.0; bt_alen = 1; } else { negate = -bdytail; bt_clarge = (double) (negate * cdx); c = (double) (splitter * negate); abig = (double) (c - negate); ahi = c - abig; alo = negate - ahi; c = (double) (splitter * cdx); abig = (double) (c - cdx); bhi = c - abig; blo = cdx - bhi; err1 = bt_clarge - (ahi * bhi); err2 = err1 - (alo * bhi); err3 = err2 - (ahi * blo); bt_c[0] = (alo * blo) - err3; bt_c[1] = bt_clarge; bt_clen = 2; bt_alarge = (double) (bdytail * adx); c = (double) (splitter * bdytail); abig = (double) (c - bdytail); ahi = c - abig; alo = bdytail - ahi; c = (double) (splitter * adx); abig = (double) (c - adx); bhi = c - abig; blo = adx - bhi; err1 = bt_alarge - (ahi * bhi); err2 = err1 - (alo * bhi); err3 = err2 - (ahi * blo); bt_a[0] = (alo * blo) - err3; bt_a[1] = bt_alarge; bt_alen = 2; } } else { if (bdytail == 0.0) { bt_clarge = (double) (bdxtail * cdy); c = (double) (splitter * bdxtail); abig = (double) (c - bdxtail); ahi = c - abig; alo = bdxtail - ahi; c = (double) (splitter * cdy); abig = (double) (c - cdy); bhi = c - abig; blo = cdy - bhi; err1 = bt_clarge - (ahi * bhi); err2 = err1 - (alo * bhi); err3 = err2 - (ahi * blo); bt_c[0] = (alo * blo) - err3; bt_c[1] = bt_clarge; bt_clen = 2; negate = -bdxtail; bt_alarge = (double) (negate * ady); c = (double) (splitter * negate); abig = (double) (c - negate); ahi = c - abig; alo = negate - ahi; c = (double) (splitter * ady); abig = (double) (c - ady); bhi = c - abig; blo = ady - bhi; err1 = bt_alarge - (ahi * bhi); err2 = err1 - (alo * bhi); err3 = err2 - (ahi * blo); bt_a[0] = (alo * blo) - err3; bt_a[1] = bt_alarge; bt_alen = 2; } else { bdxt_cdy1 = (double) (bdxtail * cdy); c = (double) (splitter * bdxtail); abig = (double) (c - bdxtail); ahi = c - abig; alo = bdxtail - ahi; c = (double) (splitter * cdy); abig = (double) (c - cdy); bhi = c - abig; blo = cdy - bhi; err1 = bdxt_cdy1 - (ahi * bhi); err2 = err1 - (alo * bhi); err3 = err2 - (ahi * blo); bdxt_cdy0 = (alo * blo) - err3; bdyt_cdx1 = (double) (bdytail * cdx); c = (double) (splitter * bdytail); abig = (double) (c - bdytail); ahi = c - abig; alo = bdytail - ahi; c = (double) (splitter * cdx); abig = (double) (c - cdx); bhi = c - abig; blo = cdx - bhi; err1 = bdyt_cdx1 - (ahi * bhi); err2 = err1 - (alo * bhi); err3 = err2 - (ahi * blo); bdyt_cdx0 = (alo * blo) - err3; _i = (double) (bdxt_cdy0 - bdyt_cdx0); bvirt = (double) (bdxt_cdy0 - _i); avirt = _i + bvirt; bround = bvirt - bdyt_cdx0; around = bdxt_cdy0 - avirt; bt_c[0] = around + bround; _j = (double) (bdxt_cdy1 + _i); bvirt = (double) (_j - bdxt_cdy1); avirt = _j - bvirt; bround = _i - bvirt; around = bdxt_cdy1 - avirt; _0 = around + bround; _i = (double) (_0 - bdyt_cdx1); bvirt = (double) (_0 - _i); avirt = _i + bvirt; bround = bvirt - bdyt_cdx1; around = _0 - avirt; bt_c[1] = around + bround; bt_clarge = (double) (_j + _i); bvirt = (double) (bt_clarge - _j); avirt = bt_clarge - bvirt; bround = _i - bvirt; around = _j - avirt; bt_c[2] = around + bround; bt_c[3] = bt_clarge; bt_clen = 4; bdyt_adx1 = (double) (bdytail * adx); c = (double) (splitter * bdytail); abig = (double) (c - bdytail); ahi = c - abig; alo = bdytail - ahi; c = (double) (splitter * adx); abig = (double) (c - adx); bhi = c - abig; blo = adx - bhi; err1 = bdyt_adx1 - (ahi * bhi); err2 = err1 - (alo * bhi); err3 = err2 - (ahi * blo); bdyt_adx0 = (alo * blo) - err3; bdxt_ady1 = (double) (bdxtail * ady); c = (double) (splitter * bdxtail); abig = (double) (c - bdxtail); ahi = c - abig; alo = bdxtail - ahi; c = (double) (splitter * ady); abig = (double) (c - ady); bhi = c - abig; blo = ady - bhi; err1 = bdxt_ady1 - (ahi * bhi); err2 = err1 - (alo * bhi); err3 = err2 - (ahi * blo); bdxt_ady0 = (alo * blo) - err3; _i = (double) (bdyt_adx0 - bdxt_ady0); bvirt = (double) (bdyt_adx0 - _i); avirt = _i + bvirt; bround = bvirt - bdxt_ady0; around = bdyt_adx0 - avirt; bt_a[0] = around + bround; _j = (double) (bdyt_adx1 + _i); bvirt = (double) (_j - bdyt_adx1); avirt = _j - bvirt; bround = _i - bvirt; around = bdyt_adx1 - avirt; _0 = around + bround; _i = (double) (_0 - bdxt_ady1); bvirt = (double) (_0 - _i); avirt = _i + bvirt; bround = bvirt - bdxt_ady1; around = _0 - avirt; bt_a[1] = around + bround; bt_alarge = (double) (_j + _i); bvirt = (double) (bt_alarge - _j); avirt = bt_alarge - bvirt; bround = _i - bvirt; around = _j - avirt; bt_a[2] = around + bround; bt_a[3] = bt_alarge; bt_alen = 4; } } if (cdxtail == 0.0) { if (cdytail == 0.0) { ct_a[0] = 0.0; ct_alen = 1; ct_b[0] = 0.0; ct_blen = 1; } else { negate = -cdytail; ct_alarge = (double) (negate * adx); c = (double) (splitter * negate); abig = (double) (c - negate); ahi = c - abig; alo = negate - ahi; c = (double) (splitter * adx); abig = (double) (c - adx); bhi = c - abig; blo = adx - bhi; err1 = ct_alarge - (ahi * bhi); err2 = err1 - (alo * bhi); err3 = err2 - (ahi * blo); ct_a[0] = (alo * blo) - err3; ct_a[1] = ct_alarge; ct_alen = 2; ct_blarge = (double) (cdytail * bdx); c = (double) (splitter * cdytail); abig = (double) (c - cdytail); ahi = c - abig; alo = cdytail - ahi; c = (double) (splitter * bdx); abig = (double) (c - bdx); bhi = c - abig; blo = bdx - bhi; err1 = ct_blarge - (ahi * bhi); err2 = err1 - (alo * bhi); err3 = err2 - (ahi * blo); ct_b[0] = (alo * blo) - err3; ct_b[1] = ct_blarge; ct_blen = 2; } } else { if (cdytail == 0.0) { ct_alarge = (double) (cdxtail * ady); c = (double) (splitter * cdxtail); abig = (double) (c - cdxtail); ahi = c - abig; alo = cdxtail - ahi; c = (double) (splitter * ady); abig = (double) (c - ady); bhi = c - abig; blo = ady - bhi; err1 = ct_alarge - (ahi * bhi); err2 = err1 - (alo * bhi); err3 = err2 - (ahi * blo); ct_a[0] = (alo * blo) - err3; ct_a[1] = ct_alarge; ct_alen = 2; negate = -cdxtail; ct_blarge = (double) (negate * bdy); c = (double) (splitter * negate); abig = (double) (c - negate); ahi = c - abig; alo = negate - ahi; c = (double) (splitter * bdy); abig = (double) (c - bdy); bhi = c - abig; blo = bdy - bhi; err1 = ct_blarge - (ahi * bhi); err2 = err1 - (alo * bhi); err3 = err2 - (ahi * blo); ct_b[0] = (alo * blo) - err3; ct_b[1] = ct_blarge; ct_blen = 2; } else { cdxt_ady1 = (double) (cdxtail * ady); c = (double) (splitter * cdxtail); abig = (double) (c - cdxtail); ahi = c - abig; alo = cdxtail - ahi; c = (double) (splitter * ady); abig = (double) (c - ady); bhi = c - abig; blo = ady - bhi; err1 = cdxt_ady1 - (ahi * bhi); err2 = err1 - (alo * bhi); err3 = err2 - (ahi * blo); cdxt_ady0 = (alo * blo) - err3; cdyt_adx1 = (double) (cdytail * adx); c = (double) (splitter * cdytail); abig = (double) (c - cdytail); ahi = c - abig; alo = cdytail - ahi; c = (double) (splitter * adx); abig = (double) (c - adx); bhi = c - abig; blo = adx - bhi; err1 = cdyt_adx1 - (ahi * bhi); err2 = err1 - (alo * bhi); err3 = err2 - (ahi * blo); cdyt_adx0 = (alo * blo) - err3; _i = (double) (cdxt_ady0 - cdyt_adx0); bvirt = (double) (cdxt_ady0 - _i); avirt = _i + bvirt; bround = bvirt - cdyt_adx0; around = cdxt_ady0 - avirt; ct_a[0] = around + bround; _j = (double) (cdxt_ady1 + _i); bvirt = (double) (_j - cdxt_ady1); avirt = _j - bvirt; bround = _i - bvirt; around = cdxt_ady1 - avirt; _0 = around + bround; _i = (double) (_0 - cdyt_adx1); bvirt = (double) (_0 - _i); avirt = _i + bvirt; bround = bvirt - cdyt_adx1; around = _0 - avirt; ct_a[1] = around + bround; ct_alarge = (double) (_j + _i); bvirt = (double) (ct_alarge - _j); avirt = ct_alarge - bvirt; bround = _i - bvirt; around = _j - avirt; ct_a[2] = around + bround; ct_a[3] = ct_alarge; ct_alen = 4; cdyt_bdx1 = (double) (cdytail * bdx); c = (double) (splitter * cdytail); abig = (double) (c - cdytail); ahi = c - abig; alo = cdytail - ahi; c = (double) (splitter * bdx); abig = (double) (c - bdx); bhi = c - abig; blo = bdx - bhi; err1 = cdyt_bdx1 - (ahi * bhi); err2 = err1 - (alo * bhi); err3 = err2 - (ahi * blo); cdyt_bdx0 = (alo * blo) - err3; cdxt_bdy1 = (double) (cdxtail * bdy); c = (double) (splitter * cdxtail); abig = (double) (c - cdxtail); ahi = c - abig; alo = cdxtail - ahi; c = (double) (splitter * bdy); abig = (double) (c - bdy); bhi = c - abig; blo = bdy - bhi; err1 = cdxt_bdy1 - (ahi * bhi); err2 = err1 - (alo * bhi); err3 = err2 - (ahi * blo); cdxt_bdy0 = (alo * blo) - err3; _i = (double) (cdyt_bdx0 - cdxt_bdy0); bvirt = (double) (cdyt_bdx0 - _i); avirt = _i + bvirt; bround = bvirt - cdxt_bdy0; around = cdyt_bdx0 - avirt; ct_b[0] = around + bround; _j = (double) (cdyt_bdx1 + _i); bvirt = (double) (_j - cdyt_bdx1); avirt = _j - bvirt; bround = _i - bvirt; around = cdyt_bdx1 - avirt; _0 = around + bround; _i = (double) (_0 - cdxt_bdy1); bvirt = (double) (_0 - _i); avirt = _i + bvirt; bround = bvirt - cdxt_bdy1; around = _0 - avirt; ct_b[1] = around + bround; ct_blarge = (double) (_j + _i); bvirt = (double) (ct_blarge - _j); avirt = ct_blarge - bvirt; bround = _i - bvirt; around = _j - avirt; ct_b[2] = around + bround; ct_b[3] = ct_blarge; ct_blen = 4; } } bctlen = fast_expansion_sum_zeroelim(bt_clen, bt_c, ct_blen, ct_b, bct); wlength = scale_expansion_zeroelim(bctlen, bct, adheight, w); finlength = fast_expansion_sum_zeroelim(finlength, finnow, wlength, w, finother); finswap = finnow; finnow = finother; finother = finswap; catlen = fast_expansion_sum_zeroelim(ct_alen, ct_a, at_clen, at_c, cat); wlength = scale_expansion_zeroelim(catlen, cat, bdheight, w); finlength = fast_expansion_sum_zeroelim(finlength, finnow, wlength, w, finother); finswap = finnow; finnow = finother; finother = finswap; abtlen = fast_expansion_sum_zeroelim(at_blen, at_b, bt_alen, bt_a, abt); wlength = scale_expansion_zeroelim(abtlen, abt, cdheight, w); finlength = fast_expansion_sum_zeroelim(finlength, finnow, wlength, w, finother); finswap = finnow; finnow = finother; finother = finswap; if (adheighttail != 0.0) { vlength = scale_expansion_zeroelim(4, bc, adheighttail, v); finlength = fast_expansion_sum_zeroelim(finlength, finnow, vlength, v, finother); finswap = finnow; finnow = finother; finother = finswap; } if (bdheighttail != 0.0) { vlength = scale_expansion_zeroelim(4, ca, bdheighttail, v); finlength = fast_expansion_sum_zeroelim(finlength, finnow, vlength, v, finother); finswap = finnow; finnow = finother; finother = finswap; } if (cdheighttail != 0.0) { vlength = scale_expansion_zeroelim(4, ab, cdheighttail, v); finlength = fast_expansion_sum_zeroelim(finlength, finnow, vlength, v, finother); finswap = finnow; finnow = finother; finother = finswap; } if (adxtail != 0.0) { if (bdytail != 0.0) { adxt_bdyt1 = (double) (adxtail * bdytail); c = (double) (splitter * adxtail); abig = (double) (c - adxtail); ahi = c - abig; alo = adxtail - ahi; c = (double) (splitter * bdytail); abig = (double) (c - bdytail); bhi = c - abig; blo = bdytail - bhi; err1 = adxt_bdyt1 - (ahi * bhi); err2 = err1 - (alo * bhi); err3 = err2 - (ahi * blo); adxt_bdyt0 = (alo * blo) - err3; c = (double) (splitter * cdheight); abig = (double) (c - cdheight); bhi = c - abig; blo = cdheight - bhi; _i = (double) (adxt_bdyt0 * cdheight); c = (double) (splitter * adxt_bdyt0); abig = (double) (c - adxt_bdyt0); ahi = c - abig; alo = adxt_bdyt0 - ahi; err1 = _i - (ahi * bhi); err2 = err1 - (alo * bhi); err3 = err2 - (ahi * blo); u[0] = (alo * blo) - err3; _j = (double) (adxt_bdyt1 * cdheight); c = (double) (splitter * adxt_bdyt1); abig = (double) (c - adxt_bdyt1); ahi = c - abig; alo = adxt_bdyt1 - ahi; err1 = _j - (ahi * bhi); err2 = err1 - (alo * bhi); err3 = err2 - (ahi * blo); _0 = (alo * blo) - err3; _k = (double) (_i + _0); bvirt = (double) (_k - _i); avirt = _k - bvirt; bround = _0 - bvirt; around = _i - avirt; u[1] = around + bround; u3 = (double) (_j + _k); bvirt = u3 - _j; u[2] = _k - bvirt; u[3] = u3; finlength = fast_expansion_sum_zeroelim(finlength, finnow, 4, u, finother); finswap = finnow; finnow = finother; finother = finswap; if (cdheighttail != 0.0) { c = (double) (splitter * cdheighttail); abig = (double) (c - cdheighttail); bhi = c - abig; blo = cdheighttail - bhi; _i = (double) (adxt_bdyt0 * cdheighttail); c = (double) (splitter * adxt_bdyt0); abig = (double) (c - adxt_bdyt0); ahi = c - abig; alo = adxt_bdyt0 - ahi; err1 = _i - (ahi * bhi); err2 = err1 - (alo * bhi); err3 = err2 - (ahi * blo); u[0] = (alo * blo) - err3; _j = (double) (adxt_bdyt1 * cdheighttail); c = (double) (splitter * adxt_bdyt1); abig = (double) (c - adxt_bdyt1); ahi = c - abig; alo = adxt_bdyt1 - ahi; err1 = _j - (ahi * bhi); err2 = err1 - (alo * bhi); err3 = err2 - (ahi * blo); _0 = (alo * blo) - err3; _k = (double) (_i + _0); bvirt = (double) (_k - _i); avirt = _k - bvirt; bround = _0 - bvirt; around = _i - avirt; u[1] = around + bround; u3 = (double) (_j + _k); bvirt = u3 - _j; u[2] = _k - bvirt; u[3] = u3; finlength = fast_expansion_sum_zeroelim(finlength, finnow, 4, u, finother); finswap = finnow; finnow = finother; finother = finswap; } } if (cdytail != 0.0) { negate = -adxtail; adxt_cdyt1 = (double) (negate * cdytail); c = (double) (splitter * negate); abig = (double) (c - negate); ahi = c - abig; alo = negate - ahi; c = (double) (splitter * cdytail); abig = (double) (c - cdytail); bhi = c - abig; blo = cdytail - bhi; err1 = adxt_cdyt1 - (ahi * bhi); err2 = err1 - (alo * bhi); err3 = err2 - (ahi * blo); adxt_cdyt0 = (alo * blo) - err3; c = (double) (splitter * bdheight); abig = (double) (c - bdheight); bhi = c - abig; blo = bdheight - bhi; _i = (double) (adxt_cdyt0 * bdheight); c = (double) (splitter * adxt_cdyt0); abig = (double) (c - adxt_cdyt0); ahi = c - abig; alo = adxt_cdyt0 - ahi; err1 = _i - (ahi * bhi); err2 = err1 - (alo * bhi); err3 = err2 - (ahi * blo); u[0] = (alo * blo) - err3; _j = (double) (adxt_cdyt1 * bdheight); c = (double) (splitter * adxt_cdyt1); abig = (double) (c - adxt_cdyt1); ahi = c - abig; alo = adxt_cdyt1 - ahi; err1 = _j - (ahi * bhi); err2 = err1 - (alo * bhi); err3 = err2 - (ahi * blo); _0 = (alo * blo) - err3; _k = (double) (_i + _0); bvirt = (double) (_k - _i); avirt = _k - bvirt; bround = _0 - bvirt; around = _i - avirt; u[1] = around + bround; u3 = (double) (_j + _k); bvirt = u3 - _j; u[2] = _k - bvirt; u[3] = u3; finlength = fast_expansion_sum_zeroelim(finlength, finnow, 4, u, finother); finswap = finnow; finnow = finother; finother = finswap; if (bdheighttail != 0.0) { c = (double) (splitter * bdheighttail); abig = (double) (c - bdheighttail); bhi = c - abig; blo = bdheighttail - bhi; _i = (double) (adxt_cdyt0 * bdheighttail); c = (double) (splitter * adxt_cdyt0); abig = (double) (c - adxt_cdyt0); ahi = c - abig; alo = adxt_cdyt0 - ahi; err1 = _i - (ahi * bhi); err2 = err1 - (alo * bhi); err3 = err2 - (ahi * blo); u[0] = (alo * blo) - err3; _j = (double) (adxt_cdyt1 * bdheighttail); c = (double) (splitter * adxt_cdyt1); abig = (double) (c - adxt_cdyt1); ahi = c - abig; alo = adxt_cdyt1 - ahi; err1 = _j - (ahi * bhi); err2 = err1 - (alo * bhi); err3 = err2 - (ahi * blo); _0 = (alo * blo) - err3; _k = (double) (_i + _0); bvirt = (double) (_k - _i); avirt = _k - bvirt; bround = _0 - bvirt; around = _i - avirt; u[1] = around + bround; u3 = (double) (_j + _k); bvirt = u3 - _j; u[2] = _k - bvirt; u[3] = u3; finlength = fast_expansion_sum_zeroelim(finlength, finnow, 4, u, finother); finswap = finnow; finnow = finother; finother = finswap; } } } if (bdxtail != 0.0) { if (cdytail != 0.0) { bdxt_cdyt1 = (double) (bdxtail * cdytail); c = (double) (splitter * bdxtail); abig = (double) (c - bdxtail); ahi = c - abig; alo = bdxtail - ahi; c = (double) (splitter * cdytail); abig = (double) (c - cdytail); bhi = c - abig; blo = cdytail - bhi; err1 = bdxt_cdyt1 - (ahi * bhi); err2 = err1 - (alo * bhi); err3 = err2 - (ahi * blo); bdxt_cdyt0 = (alo * blo) - err3; c = (double) (splitter * adheight); abig = (double) (c - adheight); bhi = c - abig; blo = adheight - bhi; _i = (double) (bdxt_cdyt0 * adheight); c = (double) (splitter * bdxt_cdyt0); abig = (double) (c - bdxt_cdyt0); ahi = c - abig; alo = bdxt_cdyt0 - ahi; err1 = _i - (ahi * bhi); err2 = err1 - (alo * bhi); err3 = err2 - (ahi * blo); u[0] = (alo * blo) - err3; _j = (double) (bdxt_cdyt1 * adheight); c = (double) (splitter * bdxt_cdyt1); abig = (double) (c - bdxt_cdyt1); ahi = c - abig; alo = bdxt_cdyt1 - ahi; err1 = _j - (ahi * bhi); err2 = err1 - (alo * bhi); err3 = err2 - (ahi * blo); _0 = (alo * blo) - err3; _k = (double) (_i + _0); bvirt = (double) (_k - _i); avirt = _k - bvirt; bround = _0 - bvirt; around = _i - avirt; u[1] = around + bround; u3 = (double) (_j + _k); bvirt = u3 - _j; u[2] = _k - bvirt; u[3] = u3; finlength = fast_expansion_sum_zeroelim(finlength, finnow, 4, u, finother); finswap = finnow; finnow = finother; finother = finswap; if (adheighttail != 0.0) { c = (double) (splitter * adheighttail); abig = (double) (c - adheighttail); bhi = c - abig; blo = adheighttail - bhi; _i = (double) (bdxt_cdyt0 * adheighttail); c = (double) (splitter * bdxt_cdyt0); abig = (double) (c - bdxt_cdyt0); ahi = c - abig; alo = bdxt_cdyt0 - ahi; err1 = _i - (ahi * bhi); err2 = err1 - (alo * bhi); err3 = err2 - (ahi * blo); u[0] = (alo * blo) - err3; _j = (double) (bdxt_cdyt1 * adheighttail); c = (double) (splitter * bdxt_cdyt1); abig = (double) (c - bdxt_cdyt1); ahi = c - abig; alo = bdxt_cdyt1 - ahi; err1 = _j - (ahi * bhi); err2 = err1 - (alo * bhi); err3 = err2 - (ahi * blo); _0 = (alo * blo) - err3; _k = (double) (_i + _0); bvirt = (double) (_k - _i); avirt = _k - bvirt; bround = _0 - bvirt; around = _i - avirt; u[1] = around + bround; u3 = (double) (_j + _k); bvirt = u3 - _j; u[2] = _k - bvirt; u[3] = u3; finlength = fast_expansion_sum_zeroelim(finlength, finnow, 4, u, finother); finswap = finnow; finnow = finother; finother = finswap; } } if (adytail != 0.0) { negate = -bdxtail; bdxt_adyt1 = (double) (negate * adytail); c = (double) (splitter * negate); abig = (double) (c - negate); ahi = c - abig; alo = negate - ahi; c = (double) (splitter * adytail); abig = (double) (c - adytail); bhi = c - abig; blo = adytail - bhi; err1 = bdxt_adyt1 - (ahi * bhi); err2 = err1 - (alo * bhi); err3 = err2 - (ahi * blo); bdxt_adyt0 = (alo * blo) - err3; c = (double) (splitter * cdheight); abig = (double) (c - cdheight); bhi = c - abig; blo = cdheight - bhi; _i = (double) (bdxt_adyt0 * cdheight); c = (double) (splitter * bdxt_adyt0); abig = (double) (c - bdxt_adyt0); ahi = c - abig; alo = bdxt_adyt0 - ahi; err1 = _i - (ahi * bhi); err2 = err1 - (alo * bhi); err3 = err2 - (ahi * blo); u[0] = (alo * blo) - err3; _j = (double) (bdxt_adyt1 * cdheight); c = (double) (splitter * bdxt_adyt1); abig = (double) (c - bdxt_adyt1); ahi = c - abig; alo = bdxt_adyt1 - ahi; err1 = _j - (ahi * bhi); err2 = err1 - (alo * bhi); err3 = err2 - (ahi * blo); _0 = (alo * blo) - err3; _k = (double) (_i + _0); bvirt = (double) (_k - _i); avirt = _k - bvirt; bround = _0 - bvirt; around = _i - avirt; u[1] = around + bround; u3 = (double) (_j + _k); bvirt = u3 - _j; u[2] = _k - bvirt; u[3] = u3; finlength = fast_expansion_sum_zeroelim(finlength, finnow, 4, u, finother); finswap = finnow; finnow = finother; finother = finswap; if (cdheighttail != 0.0) { c = (double) (splitter * cdheighttail); abig = (double) (c - cdheighttail); bhi = c - abig; blo = cdheighttail - bhi; _i = (double) (bdxt_adyt0 * cdheighttail); c = (double) (splitter * bdxt_adyt0); abig = (double) (c - bdxt_adyt0); ahi = c - abig; alo = bdxt_adyt0 - ahi; err1 = _i - (ahi * bhi); err2 = err1 - (alo * bhi); err3 = err2 - (ahi * blo); u[0] = (alo * blo) - err3; _j = (double) (bdxt_adyt1 * cdheighttail); c = (double) (splitter * bdxt_adyt1); abig = (double) (c - bdxt_adyt1); ahi = c - abig; alo = bdxt_adyt1 - ahi; err1 = _j - (ahi * bhi); err2 = err1 - (alo * bhi); err3 = err2 - (ahi * blo); _0 = (alo * blo) - err3; _k = (double) (_i + _0); bvirt = (double) (_k - _i); avirt = _k - bvirt; bround = _0 - bvirt; around = _i - avirt; u[1] = around + bround; u3 = (double) (_j + _k); bvirt = u3 - _j; u[2] = _k - bvirt; u[3] = u3; finlength = fast_expansion_sum_zeroelim(finlength, finnow, 4, u, finother); finswap = finnow; finnow = finother; finother = finswap; } } } if (cdxtail != 0.0) { if (adytail != 0.0) { cdxt_adyt1 = (double) (cdxtail * adytail); c = (double) (splitter * cdxtail); abig = (double) (c - cdxtail); ahi = c - abig; alo = cdxtail - ahi; c = (double) (splitter * adytail); abig = (double) (c - adytail); bhi = c - abig; blo = adytail - bhi; err1 = cdxt_adyt1 - (ahi * bhi); err2 = err1 - (alo * bhi); err3 = err2 - (ahi * blo); cdxt_adyt0 = (alo * blo) - err3; c = (double) (splitter * bdheight); abig = (double) (c - bdheight); bhi = c - abig; blo = bdheight - bhi; _i = (double) (cdxt_adyt0 * bdheight); c = (double) (splitter * cdxt_adyt0); abig = (double) (c - cdxt_adyt0); ahi = c - abig; alo = cdxt_adyt0 - ahi; err1 = _i - (ahi * bhi); err2 = err1 - (alo * bhi); err3 = err2 - (ahi * blo); u[0] = (alo * blo) - err3; _j = (double) (cdxt_adyt1 * bdheight); c = (double) (splitter * cdxt_adyt1); abig = (double) (c - cdxt_adyt1); ahi = c - abig; alo = cdxt_adyt1 - ahi; err1 = _j - (ahi * bhi); err2 = err1 - (alo * bhi); err3 = err2 - (ahi * blo); _0 = (alo * blo) - err3; _k = (double) (_i + _0); bvirt = (double) (_k - _i); avirt = _k - bvirt; bround = _0 - bvirt; around = _i - avirt; u[1] = around + bround; u3 = (double) (_j + _k); bvirt = u3 - _j; u[2] = _k - bvirt; u[3] = u3; finlength = fast_expansion_sum_zeroelim(finlength, finnow, 4, u, finother); finswap = finnow; finnow = finother; finother = finswap; if (bdheighttail != 0.0) { c = (double) (splitter * bdheighttail); abig = (double) (c - bdheighttail); bhi = c - abig; blo = bdheighttail - bhi; _i = (double) (cdxt_adyt0 * bdheighttail); c = (double) (splitter * cdxt_adyt0); abig = (double) (c - cdxt_adyt0); ahi = c - abig; alo = cdxt_adyt0 - ahi; err1 = _i - (ahi * bhi); err2 = err1 - (alo * bhi); err3 = err2 - (ahi * blo); u[0] = (alo * blo) - err3; _j = (double) (cdxt_adyt1 * bdheighttail); c = (double) (splitter * cdxt_adyt1); abig = (double) (c - cdxt_adyt1); ahi = c - abig; alo = cdxt_adyt1 - ahi; err1 = _j - (ahi * bhi); err2 = err1 - (alo * bhi); err3 = err2 - (ahi * blo); _0 = (alo * blo) - err3; _k = (double) (_i + _0); bvirt = (double) (_k - _i); avirt = _k - bvirt; bround = _0 - bvirt; around = _i - avirt; u[1] = around + bround; u3 = (double) (_j + _k); bvirt = u3 - _j; u[2] = _k - bvirt; u[3] = u3; finlength = fast_expansion_sum_zeroelim(finlength, finnow, 4, u, finother); finswap = finnow; finnow = finother; finother = finswap; } } if (bdytail != 0.0) { negate = -cdxtail; cdxt_bdyt1 = (double) (negate * bdytail); c = (double) (splitter * negate); abig = (double) (c - negate); ahi = c - abig; alo = negate - ahi; c = (double) (splitter * bdytail); abig = (double) (c - bdytail); bhi = c - abig; blo = bdytail - bhi; err1 = cdxt_bdyt1 - (ahi * bhi); err2 = err1 - (alo * bhi); err3 = err2 - (ahi * blo); cdxt_bdyt0 = (alo * blo) - err3; c = (double) (splitter * adheight); abig = (double) (c - adheight); bhi = c - abig; blo = adheight - bhi; _i = (double) (cdxt_bdyt0 * adheight); c = (double) (splitter * cdxt_bdyt0); abig = (double) (c - cdxt_bdyt0); ahi = c - abig; alo = cdxt_bdyt0 - ahi; err1 = _i - (ahi * bhi); err2 = err1 - (alo * bhi); err3 = err2 - (ahi * blo); u[0] = (alo * blo) - err3; _j = (double) (cdxt_bdyt1 * adheight); c = (double) (splitter * cdxt_bdyt1); abig = (double) (c - cdxt_bdyt1); ahi = c - abig; alo = cdxt_bdyt1 - ahi; err1 = _j - (ahi * bhi); err2 = err1 - (alo * bhi); err3 = err2 - (ahi * blo); _0 = (alo * blo) - err3; _k = (double) (_i + _0); bvirt = (double) (_k - _i); avirt = _k - bvirt; bround = _0 - bvirt; around = _i - avirt; u[1] = around + bround; u3 = (double) (_j + _k); bvirt = u3 - _j; u[2] = _k - bvirt; u[3] = u3; finlength = fast_expansion_sum_zeroelim(finlength, finnow, 4, u, finother); finswap = finnow; finnow = finother; finother = finswap; if (adheighttail != 0.0) { c = (double) (splitter * adheighttail); abig = (double) (c - adheighttail); bhi = c - abig; blo = adheighttail - bhi; _i = (double) (cdxt_bdyt0 * adheighttail); c = (double) (splitter * cdxt_bdyt0); abig = (double) (c - cdxt_bdyt0); ahi = c - abig; alo = cdxt_bdyt0 - ahi; err1 = _i - (ahi * bhi); err2 = err1 - (alo * bhi); err3 = err2 - (ahi * blo); u[0] = (alo * blo) - err3; _j = (double) (cdxt_bdyt1 * adheighttail); c = (double) (splitter * cdxt_bdyt1); abig = (double) (c - cdxt_bdyt1); ahi = c - abig; alo = cdxt_bdyt1 - ahi; err1 = _j - (ahi * bhi); err2 = err1 - (alo * bhi); err3 = err2 - (ahi * blo); _0 = (alo * blo) - err3; _k = (double) (_i + _0); bvirt = (double) (_k - _i); avirt = _k - bvirt; bround = _0 - bvirt; around = _i - avirt; u[1] = around + bround; u3 = (double) (_j + _k); bvirt = u3 - _j; u[2] = _k - bvirt; u[3] = u3; finlength = fast_expansion_sum_zeroelim(finlength, finnow, 4, u, finother); finswap = finnow; finnow = finother; finother = finswap; } } } if (adheighttail != 0.0) { wlength = scale_expansion_zeroelim(bctlen, bct, adheighttail, w); finlength = fast_expansion_sum_zeroelim(finlength, finnow, wlength, w, finother); finswap = finnow; finnow = finother; finother = finswap; } if (bdheighttail != 0.0) { wlength = scale_expansion_zeroelim(catlen, cat, bdheighttail, w); finlength = fast_expansion_sum_zeroelim(finlength, finnow, wlength, w, finother); finswap = finnow; finnow = finother; finother = finswap; } if (cdheighttail != 0.0) { wlength = scale_expansion_zeroelim(abtlen, abt, cdheighttail, w); finlength = fast_expansion_sum_zeroelim(finlength, finnow, wlength, w, finother); finswap = finnow; finnow = finother; finother = finswap; } return finnow[finlength - 1]; } double orient3d(m, b, pa, pb, pc, pd, aheight, bheight, cheight, dheight) struct mesh *m; struct behavior *b; vertex pa; vertex pb; vertex pc; vertex pd; double aheight; double bheight; double cheight; double dheight; { double adx, bdx, cdx, ady, bdy, cdy, adheight, bdheight, cdheight; double bdxcdy, cdxbdy, cdxady, adxcdy, adxbdy, bdxady; double det; double permanent, errbound; m->orient3dcount++; adx = pa[0] - pd[0]; bdx = pb[0] - pd[0]; cdx = pc[0] - pd[0]; ady = pa[1] - pd[1]; bdy = pb[1] - pd[1]; cdy = pc[1] - pd[1]; adheight = aheight - dheight; bdheight = bheight - dheight; cdheight = cheight - dheight; bdxcdy = bdx * cdy; cdxbdy = cdx * bdy; cdxady = cdx * ady; adxcdy = adx * cdy; adxbdy = adx * bdy; bdxady = bdx * ady; det = adheight * (bdxcdy - cdxbdy) + bdheight * (cdxady - adxcdy) + cdheight * (adxbdy - bdxady); if (b->noexact) { return det; } permanent = (((bdxcdy) >= 0.0 ? (bdxcdy) : -(bdxcdy)) + ((cdxbdy) >= 0.0 ? (cdxbdy) : -(cdxbdy))) * ((adheight) >= 0.0 ? (adheight) : -(adheight)) + (((cdxady) >= 0.0 ? (cdxady) : -(cdxady)) + ((adxcdy) >= 0.0 ? (adxcdy) : -(adxcdy))) * ((bdheight) >= 0.0 ? (bdheight) : -(bdheight)) + (((adxbdy) >= 0.0 ? (adxbdy) : -(adxbdy)) + ((bdxady) >= 0.0 ? (bdxady) : -(bdxady))) * ((cdheight) >= 0.0 ? (cdheight) : -(cdheight)); errbound = o3derrboundA * permanent; if ((det > errbound) || (-det > errbound)) { return det; } return orient3dadapt(pa, pb, pc, pd, aheight, bheight, cheight, dheight, permanent); } # 6290 "triangle.c" double nonregular(m, b, pa, pb, pc, pd) struct mesh *m; struct behavior *b; vertex pa; vertex pb; vertex pc; vertex pd; { if (b->weighted == 0) { return incircle(m, b, pa, pb, pc, pd); } else if (b->weighted == 1) { return orient3d(m, b, pa, pb, pc, pd, pa[0] * pa[0] + pa[1] * pa[1] - pa[2], pb[0] * pb[0] + pb[1] * pb[1] - pb[2], pc[0] * pc[0] + pc[1] * pc[1] - pc[2], pd[0] * pd[0] + pd[1] * pd[1] - pd[2]); } else { return orient3d(m, b, pa, pb, pc, pd, pa[2], pb[2], pc[2], pd[2]); } } # 6332 "triangle.c" void findcircumcenter(m, b, torg, tdest, tapex, circumcenter, xi, eta, minedge) struct mesh *m; struct behavior *b; vertex torg; vertex tdest; vertex tapex; vertex circumcenter; double *xi; double *eta; double *minedge; { double xdo, ydo, xao, yao; double dodist, aodist, dadist; double denominator; double dx, dy; m->circumcentercount++; xdo = tdest[0] - torg[0]; ydo = tdest[1] - torg[1]; xao = tapex[0] - torg[0]; yao = tapex[1] - torg[1]; dodist = xdo * xdo + ydo * ydo; aodist = xao * xao + yao * yao; dadist = (tdest[0] - tapex[0]) * (tdest[0] - tapex[0]) + (tdest[1] - tapex[1]) * (tdest[1] - tapex[1]); if (b->noexact) { denominator = 0.5 / (xdo * yao - xao * ydo); } else { denominator = 0.5 / counterclockwise(m, b, tdest, tapex, torg); m->counterclockcount--; } circumcenter[0] = torg[0] - (ydo * aodist - yao * dodist) * denominator; circumcenter[1] = torg[1] + (xdo * aodist - xao * dodist) * denominator; dx = circumcenter[0] - torg[0]; dy = circumcenter[1] - torg[1]; *xi = (dx * yao - xao * dy) * (2.0 * denominator); *eta = (xdo * dy - dx * ydo) * (2.0 * denominator); *minedge = ((dodist < aodist) && (dodist < dadist)) ? dodist : (aodist < dadist) ? aodist : dadist; } # 6406 "triangle.c" void triangleinit(m) struct mesh *m; { m->vertices.maxitems = m->triangles.maxitems = m->subsegs.maxitems = m->viri.maxitems = m->badsubsegs.maxitems = m->badtriangles.maxitems = m->flipstackers.maxitems = m->splaynodes.maxitems = 0l; m->vertices.itembytes = m->triangles.itembytes = m->subsegs.itembytes = m->viri.itembytes = m->badsubsegs.itembytes = m->badtriangles.itembytes = m->flipstackers.itembytes = m->splaynodes.itembytes = 0; m->recenttri.tri = (triangle *) ((void *)0); m->undeads = 0; m->samples = 1; m->checksegments = 0; m->checkquality = 0; m->incirclecount = m->counterclockcount = m->orient3dcount = 0; m->hyperbolacount = m->circletopcount = m->circumcentercount = 0; randomseed = 1; exactinit(); } # 6442 "triangle.c" unsigned long randomnation(choices) unsigned int choices; { randomseed = (randomseed * 1366l + 150889l) % 714025l; return randomseed / (714025l / choices + 1); } # 6466 "triangle.c" void checkmesh(m, b) struct mesh *m; struct behavior *b; { struct otri triangleloop; struct otri oppotri, oppooppotri; vertex triorg, tridest, triapex; vertex oppoorg, oppodest; int horrors; int saveexact; triangle ptr; saveexact = b->noexact; b->noexact = 0; if (!b->quiet) { fprintf(stderr, " Checking consistency of mesh...\n"); } horrors = 0; traversalinit(&m->triangles); triangleloop.tri = triangletraverse(m); while (triangleloop.tri != (triangle *) ((void *)0)) { for (triangleloop.orient = 0; triangleloop.orient < 3; triangleloop.orient++) { triorg = (vertex) (triangleloop).tri[plus1mod3[(triangleloop).orient] + 3]; tridest = (vertex) (triangleloop).tri[minus1mod3[(triangleloop).orient] + 3]; if (triangleloop.orient == 0) { triapex = (vertex) (triangleloop).tri[(triangleloop).orient + 3]; if (counterclockwise(m, b, triorg, tridest, triapex) <= 0.0) { fprintf(stderr, " !! !! Inverted "); printtriangle(m, b, &triangleloop); horrors++; } } ptr = (triangleloop).tri[(triangleloop).orient]; (oppotri).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (oppotri).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (oppotri).orient);; if (oppotri.tri != m->dummytri) { ptr = (oppotri).tri[(oppotri).orient]; (oppooppotri).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (oppooppotri).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (oppooppotri).orient);; if ((triangleloop.tri != oppooppotri.tri) || (triangleloop.orient != oppooppotri.orient)) { fprintf(stderr, " !! !! Asymmetric triangle-triangle bond:\n"); if (triangleloop.tri == oppooppotri.tri) { fprintf(stderr, " (Right triangle, wrong orientation)\n"); } fprintf(stderr, " First "); printtriangle(m, b, &triangleloop); fprintf(stderr, " Second (nonreciprocating) "); printtriangle(m, b, &oppotri); horrors++; } oppoorg = (vertex) (oppotri).tri[plus1mod3[(oppotri).orient] + 3]; oppodest = (vertex) (oppotri).tri[minus1mod3[(oppotri).orient] + 3]; if ((triorg != oppodest) || (tridest != oppoorg)) { fprintf(stderr, " !! !! Mismatched edge coordinates between two triangles:\n" ); fprintf(stderr, " First mismatched "); printtriangle(m, b, &triangleloop); fprintf(stderr, " Second mismatched "); printtriangle(m, b, &oppotri); horrors++; } } } triangleloop.tri = triangletraverse(m); } if (horrors == 0) { if (!b->quiet) { fprintf(stderr, " In my studied opinion, the mesh appears to be consistent.\n"); } } else if (horrors == 1) { fprintf(stderr, " !! !! !! !! Precisely one festering wound discovered.\n"); } else { fprintf(stderr, " !! !! !! !! %d abominations witnessed.\n", horrors); } b->noexact = saveexact; } # 6565 "triangle.c" void checkdelaunay(m, b) struct mesh *m; struct behavior *b; { struct otri triangleloop; struct otri oppotri; struct osub opposubseg; vertex triorg, tridest, triapex; vertex oppoapex; int shouldbedelaunay; int horrors; int saveexact; triangle ptr; subseg sptr; saveexact = b->noexact; b->noexact = 0; if (!b->quiet) { fprintf(stderr, " Checking Delaunay property of mesh...\n"); } horrors = 0; traversalinit(&m->triangles); triangleloop.tri = triangletraverse(m); while (triangleloop.tri != (triangle *) ((void *)0)) { for (triangleloop.orient = 0; triangleloop.orient < 3; triangleloop.orient++) { triorg = (vertex) (triangleloop).tri[plus1mod3[(triangleloop).orient] + 3]; tridest = (vertex) (triangleloop).tri[minus1mod3[(triangleloop).orient] + 3]; triapex = (vertex) (triangleloop).tri[(triangleloop).orient + 3]; ptr = (triangleloop).tri[(triangleloop).orient]; (oppotri).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (oppotri).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (oppotri).orient);; oppoapex = (vertex) (oppotri).tri[(oppotri).orient + 3]; shouldbedelaunay = (oppotri.tri != m->dummytri) && !((oppotri.tri)[1] == (triangle) ((void *)0)) && (triangleloop.tri < oppotri.tri) && (triorg != m->infvertex1) && (triorg != m->infvertex2) && (triorg != m->infvertex3) && (tridest != m->infvertex1) && (tridest != m->infvertex2) && (tridest != m->infvertex3) && (triapex != m->infvertex1) && (triapex != m->infvertex2) && (triapex != m->infvertex3) && (oppoapex != m->infvertex1) && (oppoapex != m->infvertex2) && (oppoapex != m->infvertex3); if (m->checksegments && shouldbedelaunay) { sptr = (subseg) (triangleloop).tri[6 + (triangleloop).orient]; (opposubseg).ssorient = (int) ((unsigned long) (sptr) & (unsigned long) 1l); (opposubseg).ss = (subseg *) ((unsigned long) (sptr) & ~ (unsigned long) 3l); if (opposubseg.ss != m->dummysub){ shouldbedelaunay = 0; } } if (shouldbedelaunay) { if (nonregular(m, b, triorg, tridest, triapex, oppoapex) > 0.0) { if (!b->weighted) { fprintf(stderr, " !! !! Non-Delaunay pair of triangles:\n"); fprintf(stderr, " First non-Delaunay "); printtriangle(m, b, &triangleloop); fprintf(stderr, " Second non-Delaunay "); } else { fprintf(stderr, " !! !! Non-regular pair of triangles:\n"); fprintf(stderr, " First non-regular "); printtriangle(m, b, &triangleloop); fprintf(stderr, " Second non-regular "); } printtriangle(m, b, &oppotri); horrors++; } } } triangleloop.tri = triangletraverse(m); } if (horrors == 0) { if (!b->quiet) { fprintf(stderr, " By virtue of my perceptive intelligence, I declare the mesh Delaunay.\n"); } } else if (horrors == 1) { fprintf(stderr, " !! !! !! !! Precisely one terrifying transgression identified.\n"); } else { fprintf(stderr, " !! !! !! !! %d obscenities viewed with horror.\n", horrors); } b->noexact = saveexact; } # 6676 "triangle.c" void enqueuebadtriang(m, b, badtri) struct mesh *m; struct behavior *b; struct badtriang *badtri; { int queuenumber; int i; if (b->verbose > 2) { fprintf(stderr, " Queueing bad triangle:\n"); fprintf(stderr, " (%.12g, %.12g) (%.12g, %.12g) (%.12g, %.12g)\n", badtri->triangorg[0], badtri->triangorg[1], badtri->triangdest[0], badtri->triangdest[1], badtri->triangapex[0], badtri->triangapex[1]); } if (badtri->key > 0.6) { queuenumber = (int) (160.0 * (badtri->key - 0.6)); if (queuenumber > 63) { queuenumber = 63; } } else { queuenumber = 0; } if (m->queuefront[queuenumber] == (struct badtriang *) ((void *)0)) { if (queuenumber > m->firstnonemptyq) { m->nextnonemptyq[queuenumber] = m->firstnonemptyq; m->firstnonemptyq = queuenumber; } else { i = queuenumber + 1; while (m->queuefront[i] == (struct badtriang *) ((void *)0)) { i++; } m->nextnonemptyq[queuenumber] = m->nextnonemptyq[i]; m->nextnonemptyq[i] = queuenumber; } m->queuefront[queuenumber] = badtri; } else { m->queuetail[queuenumber]->nexttriang = badtri; } m->queuetail[queuenumber] = badtri; badtri->nexttriang = (struct badtriang *) ((void *)0); } # 6752 "triangle.c" void enqueuebadtri(m, b, enqtri, angle, enqapex, enqorg, enqdest) struct mesh *m; struct behavior *b; struct otri *enqtri; double angle; vertex enqapex; vertex enqorg; vertex enqdest; { struct badtriang *newbad; newbad = (struct badtriang *) poolalloc(&m->badtriangles); newbad->poortri = (triangle) ((unsigned long) (*enqtri).tri | (unsigned long) (*enqtri).orient); newbad->key = angle; newbad->triangapex = enqapex; newbad->triangorg = enqorg; newbad->triangdest = enqdest; enqueuebadtriang(m, b, newbad); } # 6788 "triangle.c" struct badtriang *dequeuebadtriang(m) struct mesh *m; { struct badtriang *result; if (m->firstnonemptyq < 0) { return (struct badtriang *) ((void *)0); } result = m->queuefront[m->firstnonemptyq]; m->queuefront[m->firstnonemptyq] = result->nexttriang; if (result == m->queuetail[m->firstnonemptyq]) { m->firstnonemptyq = m->nextnonemptyq[m->firstnonemptyq]; } return result; } # 6825 "triangle.c" int under60degrees(struct osub *sub1, struct osub *sub2) { vertex segmentapex, v1, v2; double dotprod; segmentapex = (vertex) (*sub1).ss[2 + (*sub1).ssorient]; v1 = (vertex) (*sub1).ss[3 - (*sub1).ssorient]; v2 = (vertex) (*sub2).ss[3 - (*sub2).ssorient]; dotprod = (v2[0] - segmentapex[0]) * (v1[0] - segmentapex[0]) + (v2[1] - segmentapex[1]) * (v1[1] - segmentapex[1]); return (dotprod > 0.0) && (4.0 * dotprod * dotprod > ((v1[0] - segmentapex[0]) * (v1[0] - segmentapex[0]) + (v1[1] - segmentapex[1]) * (v1[1] - segmentapex[1])) * ((v2[0] - segmentapex[0]) * (v2[0] - segmentapex[0]) + (v2[1] - segmentapex[1]) * (v2[1] - segmentapex[1]))); } # 6857 "triangle.c" int clockwiseseg(struct mesh *m, struct osub *thissub, struct osub *nextsub) { struct otri neighbortri; triangle ptr; subseg sptr; ptr = (triangle) (*thissub).ss[4 + (*thissub).ssorient]; (neighbortri).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (neighbortri).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (neighbortri).orient); if (neighbortri.tri == m->dummytri) { return 0; } else { (neighbortri).orient = plus1mod3[(neighbortri).orient]; sptr = (subseg) (neighbortri).tri[6 + (neighbortri).orient]; (*nextsub).ssorient = (int) ((unsigned long) (sptr) & (unsigned long) 1l); (*nextsub).ss = (subseg *) ((unsigned long) (sptr) & ~ (unsigned long) 3l); while (nextsub->ss == m->dummysub) { ptr = (neighbortri).tri[(neighbortri).orient]; (neighbortri).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (neighbortri).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (neighbortri).orient);; (neighbortri).orient = plus1mod3[(neighbortri).orient]; sptr = (subseg) (neighbortri).tri[6 + (neighbortri).orient]; (*nextsub).ssorient = (int) ((unsigned long) (sptr) & (unsigned long) 1l); (*nextsub).ss = (subseg *) ((unsigned long) (sptr) & ~ (unsigned long) 3l); } (*nextsub).ssorient = 1 - (*nextsub).ssorient; return under60degrees(thissub, nextsub); } } # 6894 "triangle.c" int counterclockwiseseg(struct mesh *m, struct osub *thissub, struct osub *nextsub) { struct otri neighbortri; struct osub subsym; triangle ptr; subseg sptr; (subsym).ss = (*thissub).ss; (subsym).ssorient = 1 - (*thissub).ssorient; ptr = (triangle) (subsym).ss[4 + (subsym).ssorient]; (neighbortri).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (neighbortri).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (neighbortri).orient); if (neighbortri.tri == m->dummytri) { return 0; } else { (neighbortri).orient = minus1mod3[(neighbortri).orient]; sptr = (subseg) (neighbortri).tri[6 + (neighbortri).orient]; (*nextsub).ssorient = (int) ((unsigned long) (sptr) & (unsigned long) 1l); (*nextsub).ss = (subseg *) ((unsigned long) (sptr) & ~ (unsigned long) 3l); while (nextsub->ss == m->dummysub) { ptr = (neighbortri).tri[(neighbortri).orient]; (neighbortri).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (neighbortri).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (neighbortri).orient);; (neighbortri).orient = minus1mod3[(neighbortri).orient]; sptr = (subseg) (neighbortri).tri[6 + (neighbortri).orient]; (*nextsub).ssorient = (int) ((unsigned long) (sptr) & (unsigned long) 1l); (*nextsub).ss = (subseg *) ((unsigned long) (sptr) & ~ (unsigned long) 3l); } return under60degrees(thissub, nextsub); } } # 6945 "triangle.c" int splitpermitted(struct mesh *m, struct osub *testsubseg, double iradius) { struct osub cwsubseg, ccwsubseg, cwsubseg2, ccwsubseg2; struct osub testsym; struct osub startsubseg, nowsubseg; vertex suborg, dest1, dest2; double nearestpoweroffour, seglength, prevseglength, edgelength; int cwsmall, ccwsmall, cwsmall2, ccwsmall2; int orgcluster, destcluster; int toosmall; suborg = (vertex) (*testsubseg).ss[2 + (*testsubseg).ssorient]; dest1 = (vertex) (*testsubseg).ss[3 - (*testsubseg).ssorient]; seglength = (dest1[0] - suborg[0]) * (dest1[0] - suborg[0]) + (dest1[1] - suborg[1]) * (dest1[1] - suborg[1]); nearestpoweroffour = 1.0; while (seglength > 2.0 * nearestpoweroffour) { nearestpoweroffour *= 4.0; } while (seglength < 0.5 * nearestpoweroffour) { nearestpoweroffour *= 0.25; } if ((nearestpoweroffour > 1.001 * seglength) || (nearestpoweroffour < 0.999 * seglength)) { return 1; } cwsmall = clockwiseseg(m, testsubseg, &cwsubseg); ccwsmall = cwsmall ? 0 : counterclockwiseseg(m, testsubseg, &ccwsubseg); orgcluster = cwsmall || ccwsmall; (testsym).ss = (*testsubseg).ss; (testsym).ssorient = 1 - (*testsubseg).ssorient; cwsmall2 = clockwiseseg(m, &testsym, &cwsubseg2); ccwsmall2 = cwsmall2 ? 0 : counterclockwiseseg(m, &testsym, &ccwsubseg2); destcluster = cwsmall2 || ccwsmall2; if (orgcluster == destcluster) { return 1; } else if (orgcluster) { (startsubseg).ss = (*testsubseg).ss; (startsubseg).ssorient = (*testsubseg).ssorient; } else { (startsubseg).ss = (testsym).ss; (startsubseg).ssorient = (testsym).ssorient; (cwsubseg).ss = (cwsubseg2).ss; (cwsubseg).ssorient = (cwsubseg2).ssorient; (ccwsubseg).ss = (ccwsubseg2).ss; (ccwsubseg).ssorient = (ccwsubseg2).ssorient; cwsmall = cwsmall2; ccwsmall = ccwsmall2; } toosmall = 0; if (cwsmall) { (nowsubseg).ss = (startsubseg).ss; (nowsubseg).ssorient = (startsubseg).ssorient; suborg = (vertex) (nowsubseg).ss[2 + (nowsubseg).ssorient]; dest1 = (vertex) (nowsubseg).ss[3 - (nowsubseg).ssorient]; prevseglength = nearestpoweroffour; do { dest2 = (vertex) (cwsubseg).ss[3 - (cwsubseg).ssorient]; seglength = (dest2[0] - suborg[0]) * (dest2[0] - suborg[0]) + (dest2[1] - suborg[1]) * (dest2[1] - suborg[1]); if (nearestpoweroffour > 1.001 * seglength) { return 1; } edgelength = 0.5 * nearestpoweroffour * (1 - (((dest1[0] - suborg[0]) * (dest2[0] - suborg[0]) + (dest1[1] - suborg[1]) * (dest2[1] - suborg[1])) / sqrt(prevseglength * seglength))); if (edgelength < iradius) { toosmall = 1; } if (cwsubseg.ss == startsubseg.ss) { return !toosmall; } (nowsubseg).ss = (cwsubseg).ss; (nowsubseg).ssorient = (cwsubseg).ssorient; dest1 = dest2; prevseglength = seglength; cwsmall = clockwiseseg(m, &nowsubseg, &cwsubseg); } while (cwsmall); ccwsmall = counterclockwiseseg(m, &startsubseg, &ccwsubseg); } if (ccwsmall) { (nowsubseg).ss = (startsubseg).ss; (nowsubseg).ssorient = (startsubseg).ssorient; suborg = (vertex) (nowsubseg).ss[2 + (nowsubseg).ssorient]; dest1 = (vertex) (nowsubseg).ss[3 - (nowsubseg).ssorient]; prevseglength = nearestpoweroffour; do { dest2 = (vertex) (ccwsubseg).ss[3 - (ccwsubseg).ssorient]; seglength = (dest2[0] - suborg[0]) * (dest2[0] - suborg[0]) + (dest2[1] - suborg[1]) * (dest2[1] - suborg[1]); if (nearestpoweroffour > 1.001 * seglength) { return 1; } edgelength = 0.5 * nearestpoweroffour * (1 - (((dest1[0] - suborg[0]) * (dest2[0] - suborg[0]) + (dest1[1] - suborg[1]) * (dest2[1] - suborg[1])) / sqrt(prevseglength * seglength))); if (edgelength < iradius) { toosmall = 1; } if (ccwsubseg.ss == startsubseg.ss) { return !toosmall; } (nowsubseg).ss = (ccwsubseg).ss; (nowsubseg).ssorient = (ccwsubseg).ssorient; dest1 = dest2; prevseglength = seglength; ccwsmall = counterclockwiseseg(m, &nowsubseg, &ccwsubseg); } while (ccwsmall); } return !toosmall; } # 7120 "triangle.c" int checkseg4encroach(m, b, testsubseg, iradius) struct mesh *m; struct behavior *b; struct osub *testsubseg; double iradius; { struct otri neighbortri; struct osub testsym; struct badsubseg *encroachedseg; double dotproduct; int encroached; int sides; int enq; vertex eorg, edest, eapex; triangle ptr; encroached = 0; sides = 0; eorg = (vertex) (*testsubseg).ss[2 + (*testsubseg).ssorient]; edest = (vertex) (*testsubseg).ss[3 - (*testsubseg).ssorient]; ptr = (triangle) (*testsubseg).ss[4 + (*testsubseg).ssorient]; (neighbortri).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (neighbortri).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (neighbortri).orient); if (neighbortri.tri != m->dummytri) { sides++; eapex = (vertex) (neighbortri).tri[(neighbortri).orient + 3]; dotproduct = (eorg[0] - eapex[0]) * (edest[0] - eapex[0]) + (eorg[1] - eapex[1]) * (edest[1] - eapex[1]); if (dotproduct < 0.0) { if (b->nolenses || (dotproduct * dotproduct >= 0.25 * ((eorg[0] - eapex[0]) * (eorg[0] - eapex[0]) + (eorg[1] - eapex[1]) * (eorg[1] - eapex[1])) * ((edest[0] - eapex[0]) * (edest[0] - eapex[0]) + (edest[1] - eapex[1]) * (edest[1] - eapex[1])))) { encroached = 1; } } } (testsym).ss = (*testsubseg).ss; (testsym).ssorient = 1 - (*testsubseg).ssorient; ptr = (triangle) (testsym).ss[4 + (testsym).ssorient]; (neighbortri).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (neighbortri).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (neighbortri).orient); if (neighbortri.tri != m->dummytri) { sides++; eapex = (vertex) (neighbortri).tri[(neighbortri).orient + 3]; dotproduct = (eorg[0] - eapex[0]) * (edest[0] - eapex[0]) + (eorg[1] - eapex[1]) * (edest[1] - eapex[1]); if (dotproduct < 0.0) { if (b->nolenses || (dotproduct * dotproduct >= 0.25 * ((eorg[0] - eapex[0]) * (eorg[0] - eapex[0]) + (eorg[1] - eapex[1]) * (eorg[1] - eapex[1])) * ((edest[0] - eapex[0]) * (edest[0] - eapex[0]) + (edest[1] - eapex[1]) * (edest[1] - eapex[1])))) { encroached += 2; } } } if (encroached && (!b->nobisect || ((b->nobisect == 1) && (sides == 2)))) { if (iradius > 0.0) { enq = splitpermitted(m, testsubseg, iradius); } else { enq = 1; } if (enq) { if (b->verbose > 2) { fprintf(stderr, " Queueing encroached subsegment (%.12g, %.12g) (%.12g, %.12g).\n", eorg[0], eorg[1], edest[0], edest[1]); } encroachedseg = (struct badsubseg *) poolalloc(&m->badsubsegs); if (encroached == 1) { encroachedseg->encsubseg = (subseg) ((unsigned long) (*testsubseg).ss | (unsigned long) (*testsubseg).ssorient); encroachedseg->subsegorg = eorg; encroachedseg->subsegdest = edest; } else { encroachedseg->encsubseg = (subseg) ((unsigned long) (testsym).ss | (unsigned long) (testsym).ssorient); encroachedseg->subsegorg = edest; encroachedseg->subsegdest = eorg; } } } return encroached; } # 7247 "triangle.c" void testtriangle(m, b, testtri) struct mesh *m; struct behavior *b; struct otri *testtri; { struct otri sametesttri; struct osub subseg1, subseg2; vertex torg, tdest, tapex; vertex anglevertex; double dxod, dyod, dxda, dyda, dxao, dyao; double dxod2, dyod2, dxda2, dyda2, dxao2, dyao2; double apexlen, orglen, destlen; double angle; double area; subseg sptr; torg = (vertex) (*testtri).tri[plus1mod3[(*testtri).orient] + 3]; tdest = (vertex) (*testtri).tri[minus1mod3[(*testtri).orient] + 3]; tapex = (vertex) (*testtri).tri[(*testtri).orient + 3]; dxod = torg[0] - tdest[0]; dyod = torg[1] - tdest[1]; dxda = tdest[0] - tapex[0]; dyda = tdest[1] - tapex[1]; dxao = tapex[0] - torg[0]; dyao = tapex[1] - torg[1]; dxod2 = dxod * dxod; dyod2 = dyod * dyod; dxda2 = dxda * dxda; dyda2 = dyda * dyda; dxao2 = dxao * dxao; dyao2 = dyao * dyao; apexlen = dxod2 + dyod2; orglen = dxda2 + dyda2; destlen = dxao2 + dyao2; if ((apexlen < orglen) && (apexlen < destlen)) { angle = dxda * dxao + dyda * dyao; angle = angle * angle / (orglen * destlen); anglevertex = tapex; (sametesttri).tri = (*testtri).tri; (sametesttri).orient = plus1mod3[(*testtri).orient]; sptr = (subseg) (sametesttri).tri[6 + (sametesttri).orient]; (subseg1).ssorient = (int) ((unsigned long) (sptr) & (unsigned long) 1l); (subseg1).ss = (subseg *) ((unsigned long) (sptr) & ~ (unsigned long) 3l); (sametesttri).orient = plus1mod3[(sametesttri).orient]; sptr = (subseg) (sametesttri).tri[6 + (sametesttri).orient]; (subseg2).ssorient = (int) ((unsigned long) (sptr) & (unsigned long) 1l); (subseg2).ss = (subseg *) ((unsigned long) (sptr) & ~ (unsigned long) 3l); } else if (orglen < destlen) { angle = dxod * dxao + dyod * dyao; angle = angle * angle / (apexlen * destlen); anglevertex = torg; sptr = (subseg) (*testtri).tri[6 + (*testtri).orient]; (subseg1).ssorient = (int) ((unsigned long) (sptr) & (unsigned long) 1l); (subseg1).ss = (subseg *) ((unsigned long) (sptr) & ~ (unsigned long) 3l); (sametesttri).tri = (*testtri).tri; (sametesttri).orient = minus1mod3[(*testtri).orient]; sptr = (subseg) (sametesttri).tri[6 + (sametesttri).orient]; (subseg2).ssorient = (int) ((unsigned long) (sptr) & (unsigned long) 1l); (subseg2).ss = (subseg *) ((unsigned long) (sptr) & ~ (unsigned long) 3l); } else { angle = dxod * dxda + dyod * dyda; angle = angle * angle / (apexlen * orglen); anglevertex = tdest; sptr = (subseg) (*testtri).tri[6 + (*testtri).orient]; (subseg1).ssorient = (int) ((unsigned long) (sptr) & (unsigned long) 1l); (subseg1).ss = (subseg *) ((unsigned long) (sptr) & ~ (unsigned long) 3l); (sametesttri).tri = (*testtri).tri; (sametesttri).orient = plus1mod3[(*testtri).orient]; sptr = (subseg) (sametesttri).tri[6 + (sametesttri).orient]; (subseg2).ssorient = (int) ((unsigned long) (sptr) & (unsigned long) 1l); (subseg2).ss = (subseg *) ((unsigned long) (sptr) & ~ (unsigned long) 3l); } if ((subseg1.ss != m->dummysub) && (subseg2.ss != m->dummysub)) { angle = 0.0; } if (angle > b->goodangle) { enqueuebadtri(m, b, testtri, angle, tapex, torg, tdest); return; } if (b->vararea || b->fixedarea || b->usertest) { area = 0.5 * (dxod * dyda - dyod * dxda); if (b->fixedarea && (area > b->maxarea)) { enqueuebadtri(m, b, testtri, angle, tapex, torg, tdest); return; } if ((b->vararea) && (area > ((double *) (*testtri).tri)[m->areaboundindex]) && (((double *) (*testtri).tri)[m->areaboundindex] > 0.0)) { enqueuebadtri(m, b, testtri, angle, tapex, torg, tdest); return; } if (b->usertest) { if (triunsuitable(torg, tdest, tapex, area)) { enqueuebadtri(m, b, testtri, angle, tapex, torg, tdest); return; } } } } # 7383 "triangle.c" void makevertexmap(m, b) struct mesh *m; struct behavior *b; { struct otri triangleloop; vertex triorg; if (b->verbose) { fprintf(stderr, " Constructing mapping from vertices to triangles.\n"); } traversalinit(&m->triangles); triangleloop.tri = triangletraverse(m); while (triangleloop.tri != (triangle *) ((void *)0)) { for (triangleloop.orient = 0; triangleloop.orient < 3; triangleloop.orient++) { triorg = (vertex) (triangleloop).tri[plus1mod3[(triangleloop).orient] + 3]; ((triangle *) (triorg))[m->vertex2triindex] = (triangle) ((unsigned long) (triangleloop).tri | (unsigned long) (triangleloop).orient); } triangleloop.tri = triangletraverse(m); } } # 7480 "triangle.c" enum locateresult preciselocate(m, b, searchpoint, searchtri, stopatsubsegment) struct mesh *m; struct behavior *b; vertex searchpoint; struct otri *searchtri; int stopatsubsegment; { struct otri backtracktri; struct osub checkedge; vertex forg, fdest, fapex; double orgorient, destorient; int moveleft; triangle ptr; subseg sptr; if (b->verbose > 2) { fprintf(stderr, " Searching for point (%.12g, %.12g).\n", searchpoint[0], searchpoint[1]); } forg = (vertex) (*searchtri).tri[plus1mod3[(*searchtri).orient] + 3]; fdest = (vertex) (*searchtri).tri[minus1mod3[(*searchtri).orient] + 3]; fapex = (vertex) (*searchtri).tri[(*searchtri).orient + 3]; while (1) { if (b->verbose > 2) { fprintf(stderr, " At (%.12g, %.12g) (%.12g, %.12g) (%.12g, %.12g)\n", forg[0], forg[1], fdest[0], fdest[1], fapex[0], fapex[1]); } if ((fapex[0] == searchpoint[0]) && (fapex[1] == searchpoint[1])) { (*searchtri).orient = minus1mod3[(*searchtri).orient]; return ONVERTEX; } destorient = counterclockwise(m, b, forg, fapex, searchpoint); orgorient = counterclockwise(m, b, fapex, fdest, searchpoint); if (destorient > 0.0) { if (orgorient > 0.0) { moveleft = (fapex[0] - searchpoint[0]) * (fdest[0] - forg[0]) + (fapex[1] - searchpoint[1]) * (fdest[1] - forg[1]) > 0.0; } else { moveleft = 1; } } else { if (orgorient > 0.0) { moveleft = 0; } else { if (destorient == 0.0) { (*searchtri).orient = minus1mod3[(*searchtri).orient]; return ONEDGE; } if (orgorient == 0.0) { (*searchtri).orient = plus1mod3[(*searchtri).orient]; return ONEDGE; } return INTRIANGLE; } } if (moveleft) { (backtracktri).tri = (*searchtri).tri; (backtracktri).orient = minus1mod3[(*searchtri).orient]; fdest = fapex; } else { (backtracktri).tri = (*searchtri).tri; (backtracktri).orient = plus1mod3[(*searchtri).orient]; forg = fapex; } ptr = (backtracktri).tri[(backtracktri).orient]; (*searchtri).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (*searchtri).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (*searchtri).orient);; if (m->checksegments && stopatsubsegment) { sptr = (subseg) (backtracktri).tri[6 + (backtracktri).orient]; (checkedge).ssorient = (int) ((unsigned long) (sptr) & (unsigned long) 1l); (checkedge).ss = (subseg *) ((unsigned long) (sptr) & ~ (unsigned long) 3l); if (checkedge.ss != m->dummysub) { (*searchtri).tri = (backtracktri).tri; (*searchtri).orient = (backtracktri).orient; return OUTSIDE; } } if (searchtri->tri == m->dummytri) { (*searchtri).tri = (backtracktri).tri; (*searchtri).orient = (backtracktri).orient; return OUTSIDE; } fapex = (vertex) (*searchtri).tri[(*searchtri).orient + 3]; } } # 7623 "triangle.c" enum locateresult locate(m, b, searchpoint, searchtri) struct mesh *m; struct behavior *b; vertex searchpoint; struct otri *searchtri; { int **sampleblock; triangle *firsttri; struct otri sampletri; vertex torg, tdest; unsigned long alignptr; double searchdist, dist; double ahead; long sampleblocks, samplesperblock, samplenum; long triblocks; long i, j; triangle ptr; if (b->verbose > 2) { fprintf(stderr, " Randomly sampling for a triangle near point (%.12g, %.12g).\n", searchpoint[0], searchpoint[1]); } torg = (vertex) (*searchtri).tri[plus1mod3[(*searchtri).orient] + 3]; searchdist = (searchpoint[0] - torg[0]) * (searchpoint[0] - torg[0]) + (searchpoint[1] - torg[1]) * (searchpoint[1] - torg[1]); if (b->verbose > 2) { fprintf(stderr, " Boundary triangle has origin (%.12g, %.12g).\n", torg[0], torg[1]); } if (m->recenttri.tri != (triangle *) ((void *)0)) { if (!((m->recenttri.tri)[1] == (triangle) ((void *)0))) { torg = (vertex) (m->recenttri).tri[plus1mod3[(m->recenttri).orient] + 3]; if ((torg[0] == searchpoint[0]) && (torg[1] == searchpoint[1])) { (*searchtri).tri = (m->recenttri).tri; (*searchtri).orient = (m->recenttri).orient; return ONVERTEX; } dist = (searchpoint[0] - torg[0]) * (searchpoint[0] - torg[0]) + (searchpoint[1] - torg[1]) * (searchpoint[1] - torg[1]); if (dist < searchdist) { (*searchtri).tri = (m->recenttri).tri; (*searchtri).orient = (m->recenttri).orient; searchdist = dist; if (b->verbose > 2) { fprintf(stderr, " Choosing recent triangle with origin (%.12g, %.12g).\n", torg[0], torg[1]); } } } } while (11 * m->samples * m->samples * m->samples < m->triangles.items) { m->samples++; } triblocks = (m->triangles.maxitems + 4092 - 1) / 4092; samplesperblock = (m->samples + triblocks - 1) / triblocks; sampleblocks = m->samples / samplesperblock; sampleblock = m->triangles.firstblock; sampletri.orient = 0; for (i = 0; i < sampleblocks; i++) { alignptr = (unsigned long) (sampleblock + 1); firsttri = (triangle *) (alignptr + (unsigned long) m->triangles.alignbytes - (alignptr % (unsigned long) m->triangles.alignbytes)); for (j = 0; j < samplesperblock; j++) { if (i == triblocks - 1) { samplenum = randomnation((int) (m->triangles.maxitems - (i * 4092))); } else { samplenum = randomnation(4092); } sampletri.tri = (triangle *) (firsttri + (samplenum * m->triangles.itemwords)); if (!((sampletri.tri)[1] == (triangle) ((void *)0))) { torg = (vertex) (sampletri).tri[plus1mod3[(sampletri).orient] + 3]; dist = (searchpoint[0] - torg[0]) * (searchpoint[0] - torg[0]) + (searchpoint[1] - torg[1]) * (searchpoint[1] - torg[1]); if (dist < searchdist) { (*searchtri).tri = (sampletri).tri; (*searchtri).orient = (sampletri).orient; searchdist = dist; if (b->verbose > 2) { fprintf(stderr, " Choosing triangle with origin (%.12g, %.12g).\n", torg[0], torg[1]); } } } } sampleblock = (int **) *sampleblock; } torg = (vertex) (*searchtri).tri[plus1mod3[(*searchtri).orient] + 3]; tdest = (vertex) (*searchtri).tri[minus1mod3[(*searchtri).orient] + 3]; if ((torg[0] == searchpoint[0]) && (torg[1] == searchpoint[1])) { return ONVERTEX; } if ((tdest[0] == searchpoint[0]) && (tdest[1] == searchpoint[1])) { (*searchtri).orient = plus1mod3[(*searchtri).orient]; return ONVERTEX; } ahead = counterclockwise(m, b, torg, tdest, searchpoint); if (ahead < 0.0) { ptr = (*searchtri).tri[(*searchtri).orient]; (*searchtri).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (*searchtri).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (*searchtri).orient);; } else if (ahead == 0.0) { if (((torg[0] < searchpoint[0]) == (searchpoint[0] < tdest[0])) && ((torg[1] < searchpoint[1]) == (searchpoint[1] < tdest[1]))) { return ONEDGE; } } return preciselocate(m, b, searchpoint, searchtri, 0); } # 7771 "triangle.c" void insertsubseg(m, b, tri, subsegmark) struct mesh *m; struct behavior *b; struct otri *tri; int subsegmark; { struct otri oppotri; struct osub newsubseg; vertex triorg, tridest; triangle ptr; subseg sptr; triorg = (vertex) (*tri).tri[plus1mod3[(*tri).orient] + 3]; tridest = (vertex) (*tri).tri[minus1mod3[(*tri).orient] + 3]; if (((int *) (triorg))[m->vertexmarkindex] == 0) { ((int *) (triorg))[m->vertexmarkindex] = subsegmark; } if (((int *) (tridest))[m->vertexmarkindex] == 0) { ((int *) (tridest))[m->vertexmarkindex] = subsegmark; } sptr = (subseg) (*tri).tri[6 + (*tri).orient]; (newsubseg).ssorient = (int) ((unsigned long) (sptr) & (unsigned long) 1l); (newsubseg).ss = (subseg *) ((unsigned long) (sptr) & ~ (unsigned long) 3l); if (newsubseg.ss == m->dummysub) { makesubseg(m, &newsubseg); (newsubseg).ss[2 + (newsubseg).ssorient] = (subseg) tridest; (newsubseg).ss[3 - (newsubseg).ssorient] = (subseg) triorg; (*tri).tri[6 + (*tri).orient] = (triangle) (subseg) ((unsigned long) (newsubseg).ss | (unsigned long) (newsubseg).ssorient); (newsubseg).ss[4 + (newsubseg).ssorient] = (subseg) (triangle) ((unsigned long) (*tri).tri | (unsigned long) (*tri).orient); ptr = (*tri).tri[(*tri).orient]; (oppotri).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (oppotri).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (oppotri).orient);; (newsubseg).ssorient = 1 - (newsubseg).ssorient; (oppotri).tri[6 + (oppotri).orient] = (triangle) (subseg) ((unsigned long) (newsubseg).ss | (unsigned long) (newsubseg).ssorient); (newsubseg).ss[4 + (newsubseg).ssorient] = (subseg) (triangle) ((unsigned long) (oppotri).tri | (unsigned long) (oppotri).orient); * (int *) ((newsubseg).ss + 6) = subsegmark; if (b->verbose > 2) { fprintf(stderr, " Inserting new "); printsubseg(m, b, &newsubseg); } } else { if ((* (int *) ((newsubseg).ss + 6)) == 0) { * (int *) ((newsubseg).ss + 6) = subsegmark; } } } # 7872 "triangle.c" void flip(m, b, flipedge) struct mesh *m; struct behavior *b; struct otri *flipedge; { struct otri botleft, botright; struct otri topleft, topright; struct otri top; struct otri botlcasing, botrcasing; struct otri toplcasing, toprcasing; struct osub botlsubseg, botrsubseg; struct osub toplsubseg, toprsubseg; vertex leftvertex, rightvertex, botvertex; vertex farvertex; triangle ptr; subseg sptr; rightvertex = (vertex) (*flipedge).tri[plus1mod3[(*flipedge).orient] + 3]; leftvertex = (vertex) (*flipedge).tri[minus1mod3[(*flipedge).orient] + 3]; botvertex = (vertex) (*flipedge).tri[(*flipedge).orient + 3]; ptr = (*flipedge).tri[(*flipedge).orient]; (top).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (top).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (top).orient);; # 7911 "triangle.c" farvertex = (vertex) (top).tri[(top).orient + 3]; (topleft).tri = (top).tri; (topleft).orient = minus1mod3[(top).orient]; ptr = (topleft).tri[(topleft).orient]; (toplcasing).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (toplcasing).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (toplcasing).orient);; (topright).tri = (top).tri; (topright).orient = plus1mod3[(top).orient]; ptr = (topright).tri[(topright).orient]; (toprcasing).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (toprcasing).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (toprcasing).orient);; (botleft).tri = (*flipedge).tri; (botleft).orient = plus1mod3[(*flipedge).orient]; ptr = (botleft).tri[(botleft).orient]; (botlcasing).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (botlcasing).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (botlcasing).orient);; (botright).tri = (*flipedge).tri; (botright).orient = minus1mod3[(*flipedge).orient]; ptr = (botright).tri[(botright).orient]; (botrcasing).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (botrcasing).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (botrcasing).orient);; (topleft).tri[(topleft).orient] = (triangle) ((unsigned long) (botlcasing).tri | (unsigned long) (botlcasing).orient); (botlcasing).tri[(botlcasing).orient] = (triangle) ((unsigned long) (topleft).tri | (unsigned long) (topleft).orient); (botleft).tri[(botleft).orient] = (triangle) ((unsigned long) (botrcasing).tri | (unsigned long) (botrcasing).orient); (botrcasing).tri[(botrcasing).orient] = (triangle) ((unsigned long) (botleft).tri | (unsigned long) (botleft).orient); (botright).tri[(botright).orient] = (triangle) ((unsigned long) (toprcasing).tri | (unsigned long) (toprcasing).orient); (toprcasing).tri[(toprcasing).orient] = (triangle) ((unsigned long) (botright).tri | (unsigned long) (botright).orient); (topright).tri[(topright).orient] = (triangle) ((unsigned long) (toplcasing).tri | (unsigned long) (toplcasing).orient); (toplcasing).tri[(toplcasing).orient] = (triangle) ((unsigned long) (topright).tri | (unsigned long) (topright).orient); if (m->checksegments) { sptr = (subseg) (topleft).tri[6 + (topleft).orient]; (toplsubseg).ssorient = (int) ((unsigned long) (sptr) & (unsigned long) 1l); (toplsubseg).ss = (subseg *) ((unsigned long) (sptr) & ~ (unsigned long) 3l); sptr = (subseg) (botleft).tri[6 + (botleft).orient]; (botlsubseg).ssorient = (int) ((unsigned long) (sptr) & (unsigned long) 1l); (botlsubseg).ss = (subseg *) ((unsigned long) (sptr) & ~ (unsigned long) 3l); sptr = (subseg) (botright).tri[6 + (botright).orient]; (botrsubseg).ssorient = (int) ((unsigned long) (sptr) & (unsigned long) 1l); (botrsubseg).ss = (subseg *) ((unsigned long) (sptr) & ~ (unsigned long) 3l); sptr = (subseg) (topright).tri[6 + (topright).orient]; (toprsubseg).ssorient = (int) ((unsigned long) (sptr) & (unsigned long) 1l); (toprsubseg).ss = (subseg *) ((unsigned long) (sptr) & ~ (unsigned long) 3l); if (toplsubseg.ss == m->dummysub) { (topright).tri[6 + (topright).orient] = (triangle) m->dummysub; } else { (topright).tri[6 + (topright).orient] = (triangle) (subseg) ((unsigned long) (toplsubseg).ss | (unsigned long) (toplsubseg).ssorient); (toplsubseg).ss[4 + (toplsubseg).ssorient] = (subseg) (triangle) ((unsigned long) (topright).tri | (unsigned long) (topright).orient); } if (botlsubseg.ss == m->dummysub) { (topleft).tri[6 + (topleft).orient] = (triangle) m->dummysub; } else { (topleft).tri[6 + (topleft).orient] = (triangle) (subseg) ((unsigned long) (botlsubseg).ss | (unsigned long) (botlsubseg).ssorient); (botlsubseg).ss[4 + (botlsubseg).ssorient] = (subseg) (triangle) ((unsigned long) (topleft).tri | (unsigned long) (topleft).orient); } if (botrsubseg.ss == m->dummysub) { (botleft).tri[6 + (botleft).orient] = (triangle) m->dummysub; } else { (botleft).tri[6 + (botleft).orient] = (triangle) (subseg) ((unsigned long) (botrsubseg).ss | (unsigned long) (botrsubseg).ssorient); (botrsubseg).ss[4 + (botrsubseg).ssorient] = (subseg) (triangle) ((unsigned long) (botleft).tri | (unsigned long) (botleft).orient); } if (toprsubseg.ss == m->dummysub) { (botright).tri[6 + (botright).orient] = (triangle) m->dummysub; } else { (botright).tri[6 + (botright).orient] = (triangle) (subseg) ((unsigned long) (toprsubseg).ss | (unsigned long) (toprsubseg).ssorient); (toprsubseg).ss[4 + (toprsubseg).ssorient] = (subseg) (triangle) ((unsigned long) (botright).tri | (unsigned long) (botright).orient); } } (*flipedge).tri[plus1mod3[(*flipedge).orient] + 3] = (triangle) farvertex; (*flipedge).tri[minus1mod3[(*flipedge).orient] + 3] = (triangle) botvertex; (*flipedge).tri[(*flipedge).orient + 3] = (triangle) rightvertex; (top).tri[plus1mod3[(top).orient] + 3] = (triangle) botvertex; (top).tri[minus1mod3[(top).orient] + 3] = (triangle) farvertex; (top).tri[(top).orient + 3] = (triangle) leftvertex; if (b->verbose > 2) { fprintf(stderr, " Edge flip results in left "); printtriangle(m, b, &top); fprintf(stderr, " and right "); printtriangle(m, b, flipedge); } } # 8007 "triangle.c" void unflip(m, b, flipedge) struct mesh *m; struct behavior *b; struct otri *flipedge; { struct otri botleft, botright; struct otri topleft, topright; struct otri top; struct otri botlcasing, botrcasing; struct otri toplcasing, toprcasing; struct osub botlsubseg, botrsubseg; struct osub toplsubseg, toprsubseg; vertex leftvertex, rightvertex, botvertex; vertex farvertex; triangle ptr; subseg sptr; rightvertex = (vertex) (*flipedge).tri[plus1mod3[(*flipedge).orient] + 3]; leftvertex = (vertex) (*flipedge).tri[minus1mod3[(*flipedge).orient] + 3]; botvertex = (vertex) (*flipedge).tri[(*flipedge).orient + 3]; ptr = (*flipedge).tri[(*flipedge).orient]; (top).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (top).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (top).orient);; # 8046 "triangle.c" farvertex = (vertex) (top).tri[(top).orient + 3]; (topleft).tri = (top).tri; (topleft).orient = minus1mod3[(top).orient]; ptr = (topleft).tri[(topleft).orient]; (toplcasing).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (toplcasing).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (toplcasing).orient);; (topright).tri = (top).tri; (topright).orient = plus1mod3[(top).orient]; ptr = (topright).tri[(topright).orient]; (toprcasing).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (toprcasing).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (toprcasing).orient);; (botleft).tri = (*flipedge).tri; (botleft).orient = plus1mod3[(*flipedge).orient]; ptr = (botleft).tri[(botleft).orient]; (botlcasing).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (botlcasing).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (botlcasing).orient);; (botright).tri = (*flipedge).tri; (botright).orient = minus1mod3[(*flipedge).orient]; ptr = (botright).tri[(botright).orient]; (botrcasing).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (botrcasing).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (botrcasing).orient);; (topleft).tri[(topleft).orient] = (triangle) ((unsigned long) (toprcasing).tri | (unsigned long) (toprcasing).orient); (toprcasing).tri[(toprcasing).orient] = (triangle) ((unsigned long) (topleft).tri | (unsigned long) (topleft).orient); (botleft).tri[(botleft).orient] = (triangle) ((unsigned long) (toplcasing).tri | (unsigned long) (toplcasing).orient); (toplcasing).tri[(toplcasing).orient] = (triangle) ((unsigned long) (botleft).tri | (unsigned long) (botleft).orient); (botright).tri[(botright).orient] = (triangle) ((unsigned long) (botlcasing).tri | (unsigned long) (botlcasing).orient); (botlcasing).tri[(botlcasing).orient] = (triangle) ((unsigned long) (botright).tri | (unsigned long) (botright).orient); (topright).tri[(topright).orient] = (triangle) ((unsigned long) (botrcasing).tri | (unsigned long) (botrcasing).orient); (botrcasing).tri[(botrcasing).orient] = (triangle) ((unsigned long) (topright).tri | (unsigned long) (topright).orient); if (m->checksegments) { sptr = (subseg) (topleft).tri[6 + (topleft).orient]; (toplsubseg).ssorient = (int) ((unsigned long) (sptr) & (unsigned long) 1l); (toplsubseg).ss = (subseg *) ((unsigned long) (sptr) & ~ (unsigned long) 3l); sptr = (subseg) (botleft).tri[6 + (botleft).orient]; (botlsubseg).ssorient = (int) ((unsigned long) (sptr) & (unsigned long) 1l); (botlsubseg).ss = (subseg *) ((unsigned long) (sptr) & ~ (unsigned long) 3l); sptr = (subseg) (botright).tri[6 + (botright).orient]; (botrsubseg).ssorient = (int) ((unsigned long) (sptr) & (unsigned long) 1l); (botrsubseg).ss = (subseg *) ((unsigned long) (sptr) & ~ (unsigned long) 3l); sptr = (subseg) (topright).tri[6 + (topright).orient]; (toprsubseg).ssorient = (int) ((unsigned long) (sptr) & (unsigned long) 1l); (toprsubseg).ss = (subseg *) ((unsigned long) (sptr) & ~ (unsigned long) 3l); if (toplsubseg.ss == m->dummysub) { (botleft).tri[6 + (botleft).orient] = (triangle) m->dummysub; } else { (botleft).tri[6 + (botleft).orient] = (triangle) (subseg) ((unsigned long) (toplsubseg).ss | (unsigned long) (toplsubseg).ssorient); (toplsubseg).ss[4 + (toplsubseg).ssorient] = (subseg) (triangle) ((unsigned long) (botleft).tri | (unsigned long) (botleft).orient); } if (botlsubseg.ss == m->dummysub) { (botright).tri[6 + (botright).orient] = (triangle) m->dummysub; } else { (botright).tri[6 + (botright).orient] = (triangle) (subseg) ((unsigned long) (botlsubseg).ss | (unsigned long) (botlsubseg).ssorient); (botlsubseg).ss[4 + (botlsubseg).ssorient] = (subseg) (triangle) ((unsigned long) (botright).tri | (unsigned long) (botright).orient); } if (botrsubseg.ss == m->dummysub) { (topright).tri[6 + (topright).orient] = (triangle) m->dummysub; } else { (topright).tri[6 + (topright).orient] = (triangle) (subseg) ((unsigned long) (botrsubseg).ss | (unsigned long) (botrsubseg).ssorient); (botrsubseg).ss[4 + (botrsubseg).ssorient] = (subseg) (triangle) ((unsigned long) (topright).tri | (unsigned long) (topright).orient); } if (toprsubseg.ss == m->dummysub) { (topleft).tri[6 + (topleft).orient] = (triangle) m->dummysub; } else { (topleft).tri[6 + (topleft).orient] = (triangle) (subseg) ((unsigned long) (toprsubseg).ss | (unsigned long) (toprsubseg).ssorient); (toprsubseg).ss[4 + (toprsubseg).ssorient] = (subseg) (triangle) ((unsigned long) (topleft).tri | (unsigned long) (topleft).orient); } } (*flipedge).tri[plus1mod3[(*flipedge).orient] + 3] = (triangle) botvertex; (*flipedge).tri[minus1mod3[(*flipedge).orient] + 3] = (triangle) farvertex; (*flipedge).tri[(*flipedge).orient + 3] = (triangle) leftvertex; (top).tri[plus1mod3[(top).orient] + 3] = (triangle) farvertex; (top).tri[minus1mod3[(top).orient] + 3] = (triangle) botvertex; (top).tri[(top).orient + 3] = (triangle) rightvertex; if (b->verbose > 2) { fprintf(stderr, " Edge unflip results in left "); printtriangle(m, b, flipedge); fprintf(stderr, " and right "); printtriangle(m, b, &top); } } # 8160 "triangle.c" enum insertvertexresult insertvertex(m, b, newvertex, searchtri, splitseg, segmentflaws, triflaws, iradius) struct mesh *m; struct behavior *b; vertex newvertex; struct otri *searchtri; struct osub *splitseg; int segmentflaws; int triflaws; double iradius; { struct otri horiz; struct otri top; struct otri botleft, botright; struct otri topleft, topright; struct otri newbotleft, newbotright; struct otri newtopright; struct otri botlcasing, botrcasing; struct otri toplcasing, toprcasing; struct otri testtri; struct osub botlsubseg, botrsubseg; struct osub toplsubseg, toprsubseg; struct osub brokensubseg; struct osub checksubseg; struct osub rightsubseg; struct osub newsubseg; struct badsubseg *encroached; struct flipstacker *newflip; vertex first; vertex leftvertex, rightvertex, botvertex, topvertex, farvertex; double attrib; double area; enum insertvertexresult success; enum locateresult intersect; int doflip; int mirrorflag; int enq; int i; triangle ptr; subseg sptr; if (b->verbose > 1) { fprintf(stderr, " Inserting (%.12g, %.12g).\n", newvertex[0], newvertex[1]); } if (splitseg == (struct osub *) ((void *)0)) { if (searchtri->tri == m->dummytri) { horiz.tri = m->dummytri; horiz.orient = 0; ptr = (horiz).tri[(horiz).orient]; (horiz).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (horiz).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (horiz).orient);; intersect = locate(m, b, newvertex, &horiz); } else { (horiz).tri = (*searchtri).tri; (horiz).orient = (*searchtri).orient; intersect = preciselocate(m, b, newvertex, &horiz, 1); } } else { (horiz).tri = (*searchtri).tri; (horiz).orient = (*searchtri).orient; intersect = ONEDGE; } if (intersect == ONVERTEX) { (*searchtri).tri = (horiz).tri; (*searchtri).orient = (horiz).orient; (m->recenttri).tri = (horiz).tri; (m->recenttri).orient = (horiz).orient; return DUPLICATEVERTEX; } if ((intersect == ONEDGE) || (intersect == OUTSIDE)) { if (m->checksegments && (splitseg == (struct osub *) ((void *)0))) { sptr = (subseg) (horiz).tri[6 + (horiz).orient]; (brokensubseg).ssorient = (int) ((unsigned long) (sptr) & (unsigned long) 1l); (brokensubseg).ss = (subseg *) ((unsigned long) (sptr) & ~ (unsigned long) 3l); if (brokensubseg.ss != m->dummysub) { if (segmentflaws) { if (b->nobisect == 2) { enq = 0; } else if (iradius > 0.0) { enq = splitpermitted(m, &brokensubseg, iradius); } else { enq = 1; } if (enq && (b->nobisect == 1)) { ptr = (horiz).tri[(horiz).orient]; (testtri).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (testtri).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (testtri).orient);; enq = testtri.tri != m->dummytri; } if (enq) { encroached = (struct badsubseg *) poolalloc(&m->badsubsegs); encroached->encsubseg = (subseg) ((unsigned long) (brokensubseg).ss | (unsigned long) (brokensubseg).ssorient); encroached->subsegorg = (vertex) (brokensubseg).ss[2 + (brokensubseg).ssorient]; encroached->subsegdest = (vertex) (brokensubseg).ss[3 - (brokensubseg).ssorient]; if (b->verbose > 2) { fprintf(stderr, " Queueing encroached subsegment (%.12g, %.12g) (%.12g, %.12g).\n", encroached->subsegorg[0], encroached->subsegorg[1], encroached->subsegdest[0], encroached->subsegdest[1]); } } } (*searchtri).tri = (horiz).tri; (*searchtri).orient = (horiz).orient; (m->recenttri).tri = (horiz).tri; (m->recenttri).orient = (horiz).orient; return VIOLATINGVERTEX; } } (botright).tri = (horiz).tri; (botright).orient = minus1mod3[(horiz).orient]; ptr = (botright).tri[(botright).orient]; (botrcasing).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (botrcasing).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (botrcasing).orient);; ptr = (horiz).tri[(horiz).orient]; (topright).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (topright).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (topright).orient);; mirrorflag = topright.tri != m->dummytri; if (mirrorflag) { (topright).orient = plus1mod3[(topright).orient]; ptr = (topright).tri[(topright).orient]; (toprcasing).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (toprcasing).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (toprcasing).orient);; maketriangle(m, b, &newtopright); } else { m->hullsize++; } maketriangle(m, b, &newbotright); rightvertex = (vertex) (horiz).tri[plus1mod3[(horiz).orient] + 3]; leftvertex = (vertex) (horiz).tri[minus1mod3[(horiz).orient] + 3]; botvertex = (vertex) (horiz).tri[(horiz).orient + 3]; (newbotright).tri[plus1mod3[(newbotright).orient] + 3] = (triangle) botvertex; (newbotright).tri[minus1mod3[(newbotright).orient] + 3] = (triangle) rightvertex; (newbotright).tri[(newbotright).orient + 3] = (triangle) newvertex; (horiz).tri[plus1mod3[(horiz).orient] + 3] = (triangle) newvertex; for (i = 0; i < m->eextras; i++) { ((double *) (newbotright).tri)[m->elemattribindex + (i)] = ((double *) (botright).tri)[m->elemattribindex + (i)]; } if (b->vararea) { ((double *) (newbotright).tri)[m->areaboundindex] = ((double *) (botright).tri)[m->areaboundindex]; } if (mirrorflag) { topvertex = (vertex) (topright).tri[minus1mod3[(topright).orient] + 3]; (newtopright).tri[plus1mod3[(newtopright).orient] + 3] = (triangle) rightvertex; (newtopright).tri[minus1mod3[(newtopright).orient] + 3] = (triangle) topvertex; (newtopright).tri[(newtopright).orient + 3] = (triangle) newvertex; (topright).tri[plus1mod3[(topright).orient] + 3] = (triangle) newvertex; for (i = 0; i < m->eextras; i++) { ((double *) (newtopright).tri)[m->elemattribindex + (i)] = ((double *) (topright).tri)[m->elemattribindex + (i)]; } if (b->vararea) { ((double *) (newtopright).tri)[m->areaboundindex] = ((double *) (topright).tri)[m->areaboundindex]; } } if (m->checksegments) { sptr = (subseg) (botright).tri[6 + (botright).orient]; (botrsubseg).ssorient = (int) ((unsigned long) (sptr) & (unsigned long) 1l); (botrsubseg).ss = (subseg *) ((unsigned long) (sptr) & ~ (unsigned long) 3l); if (botrsubseg.ss != m->dummysub) { (botright).tri[6 + (botright).orient] = (triangle) m->dummysub; (newbotright).tri[6 + (newbotright).orient] = (triangle) (subseg) ((unsigned long) (botrsubseg).ss | (unsigned long) (botrsubseg).ssorient); (botrsubseg).ss[4 + (botrsubseg).ssorient] = (subseg) (triangle) ((unsigned long) (newbotright).tri | (unsigned long) (newbotright).orient); } if (mirrorflag) { sptr = (subseg) (topright).tri[6 + (topright).orient]; (toprsubseg).ssorient = (int) ((unsigned long) (sptr) & (unsigned long) 1l); (toprsubseg).ss = (subseg *) ((unsigned long) (sptr) & ~ (unsigned long) 3l); if (toprsubseg.ss != m->dummysub) { (topright).tri[6 + (topright).orient] = (triangle) m->dummysub; (newtopright).tri[6 + (newtopright).orient] = (triangle) (subseg) ((unsigned long) (toprsubseg).ss | (unsigned long) (toprsubseg).ssorient); (toprsubseg).ss[4 + (toprsubseg).ssorient] = (subseg) (triangle) ((unsigned long) (newtopright).tri | (unsigned long) (newtopright).orient); } } } (newbotright).tri[(newbotright).orient] = (triangle) ((unsigned long) (botrcasing).tri | (unsigned long) (botrcasing).orient); (botrcasing).tri[(botrcasing).orient] = (triangle) ((unsigned long) (newbotright).tri | (unsigned long) (newbotright).orient); (newbotright).orient = minus1mod3[(newbotright).orient]; (newbotright).tri[(newbotright).orient] = (triangle) ((unsigned long) (botright).tri | (unsigned long) (botright).orient); (botright).tri[(botright).orient] = (triangle) ((unsigned long) (newbotright).tri | (unsigned long) (newbotright).orient); (newbotright).orient = minus1mod3[(newbotright).orient]; if (mirrorflag) { (newtopright).tri[(newtopright).orient] = (triangle) ((unsigned long) (toprcasing).tri | (unsigned long) (toprcasing).orient); (toprcasing).tri[(toprcasing).orient] = (triangle) ((unsigned long) (newtopright).tri | (unsigned long) (newtopright).orient); (newtopright).orient = plus1mod3[(newtopright).orient]; (newtopright).tri[(newtopright).orient] = (triangle) ((unsigned long) (topright).tri | (unsigned long) (topright).orient); (topright).tri[(topright).orient] = (triangle) ((unsigned long) (newtopright).tri | (unsigned long) (newtopright).orient); (newtopright).orient = plus1mod3[(newtopright).orient]; (newtopright).tri[(newtopright).orient] = (triangle) ((unsigned long) (newbotright).tri | (unsigned long) (newbotright).orient); (newbotright).tri[(newbotright).orient] = (triangle) ((unsigned long) (newtopright).tri | (unsigned long) (newtopright).orient); } if (splitseg != (struct osub *) ((void *)0)) { (*splitseg).ss[3 - (*splitseg).ssorient] = (subseg) newvertex; (*splitseg).ssorient = 1 - (*splitseg).ssorient; sptr = (*splitseg).ss[(*splitseg).ssorient]; (rightsubseg).ssorient = (int) ((unsigned long) (sptr) & (unsigned long) 1l); (rightsubseg).ss = (subseg *) ((unsigned long) (sptr) & ~ (unsigned long) 3l); insertsubseg(m, b, &newbotright, (* (int *) ((*splitseg).ss + 6))); sptr = (subseg) (newbotright).tri[6 + (newbotright).orient]; (newsubseg).ssorient = (int) ((unsigned long) (sptr) & (unsigned long) 1l); (newsubseg).ss = (subseg *) ((unsigned long) (sptr) & ~ (unsigned long) 3l); (*splitseg).ss[(*splitseg).ssorient] = (subseg) ((unsigned long) (newsubseg).ss | (unsigned long) (newsubseg).ssorient); (newsubseg).ss[(newsubseg).ssorient] = (subseg) ((unsigned long) (*splitseg).ss | (unsigned long) (*splitseg).ssorient); (newsubseg).ssorient = 1 - (newsubseg).ssorient; (newsubseg).ss[(newsubseg).ssorient] = (subseg) ((unsigned long) (rightsubseg).ss | (unsigned long) (rightsubseg).ssorient); (rightsubseg).ss[(rightsubseg).ssorient] = (subseg) ((unsigned long) (newsubseg).ss | (unsigned long) (newsubseg).ssorient); (*splitseg).ssorient = 1 - (*splitseg).ssorient; if (((int *) (newvertex))[m->vertexmarkindex] == 0) { ((int *) (newvertex))[m->vertexmarkindex] = (* (int *) ((*splitseg).ss + 6)); } } if (m->checkquality) { poolrestart(&m->flipstackers); m->lastflip = (struct flipstacker *) poolalloc(&m->flipstackers); m->lastflip->flippedtri = (triangle) ((unsigned long) (horiz).tri | (unsigned long) (horiz).orient); m->lastflip->prevflip = (struct flipstacker *) &insertvertex; } # 8417 "triangle.c" if (b->verbose > 2) { fprintf(stderr, " Updating bottom left "); printtriangle(m, b, &botright); if (mirrorflag) { fprintf(stderr, " Updating top left "); printtriangle(m, b, &topright); fprintf(stderr, " Creating top right "); printtriangle(m, b, &newtopright); } fprintf(stderr, " Creating bottom right "); printtriangle(m, b, &newbotright); } (horiz).orient = plus1mod3[(horiz).orient]; } else { (botleft).tri = (horiz).tri; (botleft).orient = plus1mod3[(horiz).orient]; (botright).tri = (horiz).tri; (botright).orient = minus1mod3[(horiz).orient]; ptr = (botleft).tri[(botleft).orient]; (botlcasing).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (botlcasing).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (botlcasing).orient);; ptr = (botright).tri[(botright).orient]; (botrcasing).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (botrcasing).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (botrcasing).orient);; maketriangle(m, b, &newbotleft); maketriangle(m, b, &newbotright); rightvertex = (vertex) (horiz).tri[plus1mod3[(horiz).orient] + 3]; leftvertex = (vertex) (horiz).tri[minus1mod3[(horiz).orient] + 3]; botvertex = (vertex) (horiz).tri[(horiz).orient + 3]; (newbotleft).tri[plus1mod3[(newbotleft).orient] + 3] = (triangle) leftvertex; (newbotleft).tri[minus1mod3[(newbotleft).orient] + 3] = (triangle) botvertex; (newbotleft).tri[(newbotleft).orient + 3] = (triangle) newvertex; (newbotright).tri[plus1mod3[(newbotright).orient] + 3] = (triangle) botvertex; (newbotright).tri[minus1mod3[(newbotright).orient] + 3] = (triangle) rightvertex; (newbotright).tri[(newbotright).orient + 3] = (triangle) newvertex; (horiz).tri[(horiz).orient + 3] = (triangle) newvertex; for (i = 0; i < m->eextras; i++) { attrib = ((double *) (horiz).tri)[m->elemattribindex + (i)]; ((double *) (newbotleft).tri)[m->elemattribindex + (i)] = attrib; ((double *) (newbotright).tri)[m->elemattribindex + (i)] = attrib; } if (b->vararea) { area = ((double *) (horiz).tri)[m->areaboundindex]; ((double *) (newbotleft).tri)[m->areaboundindex] = area; ((double *) (newbotright).tri)[m->areaboundindex] = area; } if (m->checksegments) { sptr = (subseg) (botleft).tri[6 + (botleft).orient]; (botlsubseg).ssorient = (int) ((unsigned long) (sptr) & (unsigned long) 1l); (botlsubseg).ss = (subseg *) ((unsigned long) (sptr) & ~ (unsigned long) 3l); if (botlsubseg.ss != m->dummysub) { (botleft).tri[6 + (botleft).orient] = (triangle) m->dummysub; (newbotleft).tri[6 + (newbotleft).orient] = (triangle) (subseg) ((unsigned long) (botlsubseg).ss | (unsigned long) (botlsubseg).ssorient); (botlsubseg).ss[4 + (botlsubseg).ssorient] = (subseg) (triangle) ((unsigned long) (newbotleft).tri | (unsigned long) (newbotleft).orient); } sptr = (subseg) (botright).tri[6 + (botright).orient]; (botrsubseg).ssorient = (int) ((unsigned long) (sptr) & (unsigned long) 1l); (botrsubseg).ss = (subseg *) ((unsigned long) (sptr) & ~ (unsigned long) 3l); if (botrsubseg.ss != m->dummysub) { (botright).tri[6 + (botright).orient] = (triangle) m->dummysub; (newbotright).tri[6 + (newbotright).orient] = (triangle) (subseg) ((unsigned long) (botrsubseg).ss | (unsigned long) (botrsubseg).ssorient); (botrsubseg).ss[4 + (botrsubseg).ssorient] = (subseg) (triangle) ((unsigned long) (newbotright).tri | (unsigned long) (newbotright).orient); } } (newbotleft).tri[(newbotleft).orient] = (triangle) ((unsigned long) (botlcasing).tri | (unsigned long) (botlcasing).orient); (botlcasing).tri[(botlcasing).orient] = (triangle) ((unsigned long) (newbotleft).tri | (unsigned long) (newbotleft).orient); (newbotright).tri[(newbotright).orient] = (triangle) ((unsigned long) (botrcasing).tri | (unsigned long) (botrcasing).orient); (botrcasing).tri[(botrcasing).orient] = (triangle) ((unsigned long) (newbotright).tri | (unsigned long) (newbotright).orient); (newbotleft).orient = plus1mod3[(newbotleft).orient]; (newbotright).orient = minus1mod3[(newbotright).orient]; (newbotleft).tri[(newbotleft).orient] = (triangle) ((unsigned long) (newbotright).tri | (unsigned long) (newbotright).orient); (newbotright).tri[(newbotright).orient] = (triangle) ((unsigned long) (newbotleft).tri | (unsigned long) (newbotleft).orient); (newbotleft).orient = plus1mod3[(newbotleft).orient]; (botleft).tri[(botleft).orient] = (triangle) ((unsigned long) (newbotleft).tri | (unsigned long) (newbotleft).orient); (newbotleft).tri[(newbotleft).orient] = (triangle) ((unsigned long) (botleft).tri | (unsigned long) (botleft).orient); (newbotright).orient = minus1mod3[(newbotright).orient]; (botright).tri[(botright).orient] = (triangle) ((unsigned long) (newbotright).tri | (unsigned long) (newbotright).orient); (newbotright).tri[(newbotright).orient] = (triangle) ((unsigned long) (botright).tri | (unsigned long) (botright).orient); if (m->checkquality) { poolrestart(&m->flipstackers); m->lastflip = (struct flipstacker *) poolalloc(&m->flipstackers); m->lastflip->flippedtri = (triangle) ((unsigned long) (horiz).tri | (unsigned long) (horiz).orient); m->lastflip->prevflip = (struct flipstacker *) ((void *)0); } # 8517 "triangle.c" if (b->verbose > 2) { fprintf(stderr, " Updating top "); printtriangle(m, b, &horiz); fprintf(stderr, " Creating left "); printtriangle(m, b, &newbotleft); fprintf(stderr, " Creating right "); printtriangle(m, b, &newbotright); } } success = SUCCESSFULVERTEX; first = (vertex) (horiz).tri[plus1mod3[(horiz).orient] + 3]; rightvertex = first; leftvertex = (vertex) (horiz).tri[minus1mod3[(horiz).orient] + 3]; while (1) { doflip = 1; if (m->checksegments) { sptr = (subseg) (horiz).tri[6 + (horiz).orient]; (checksubseg).ssorient = (int) ((unsigned long) (sptr) & (unsigned long) 1l); (checksubseg).ss = (subseg *) ((unsigned long) (sptr) & ~ (unsigned long) 3l); if (checksubseg.ss != m->dummysub) { doflip = 0; if (segmentflaws) { if (checkseg4encroach(m, b, &checksubseg, iradius)) { success = ENCROACHINGVERTEX; } } } } if (doflip) { ptr = (horiz).tri[(horiz).orient]; (top).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (top).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (top).orient);; if (top.tri == m->dummytri) { doflip = 0; } else { farvertex = (vertex) (top).tri[(top).orient + 3]; if ((leftvertex == m->infvertex1) || (leftvertex == m->infvertex2) || (leftvertex == m->infvertex3)) { doflip = counterclockwise(m, b, newvertex, rightvertex, farvertex) > 0.0; } else if ((rightvertex == m->infvertex1) || (rightvertex == m->infvertex2) || (rightvertex == m->infvertex3)) { doflip = counterclockwise(m, b, farvertex, leftvertex, newvertex) > 0.0; } else if ((farvertex == m->infvertex1) || (farvertex == m->infvertex2) || (farvertex == m->infvertex3)) { doflip = 0; } else { doflip = incircle(m, b, leftvertex, newvertex, rightvertex, farvertex) > 0.0; } if (doflip) { (topleft).tri = (top).tri; (topleft).orient = minus1mod3[(top).orient]; ptr = (topleft).tri[(topleft).orient]; (toplcasing).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (toplcasing).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (toplcasing).orient);; (topright).tri = (top).tri; (topright).orient = plus1mod3[(top).orient]; ptr = (topright).tri[(topright).orient]; (toprcasing).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (toprcasing).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (toprcasing).orient);; (botleft).tri = (horiz).tri; (botleft).orient = plus1mod3[(horiz).orient]; ptr = (botleft).tri[(botleft).orient]; (botlcasing).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (botlcasing).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (botlcasing).orient);; (botright).tri = (horiz).tri; (botright).orient = minus1mod3[(horiz).orient]; ptr = (botright).tri[(botright).orient]; (botrcasing).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (botrcasing).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (botrcasing).orient);; (topleft).tri[(topleft).orient] = (triangle) ((unsigned long) (botlcasing).tri | (unsigned long) (botlcasing).orient); (botlcasing).tri[(botlcasing).orient] = (triangle) ((unsigned long) (topleft).tri | (unsigned long) (topleft).orient); (botleft).tri[(botleft).orient] = (triangle) ((unsigned long) (botrcasing).tri | (unsigned long) (botrcasing).orient); (botrcasing).tri[(botrcasing).orient] = (triangle) ((unsigned long) (botleft).tri | (unsigned long) (botleft).orient); (botright).tri[(botright).orient] = (triangle) ((unsigned long) (toprcasing).tri | (unsigned long) (toprcasing).orient); (toprcasing).tri[(toprcasing).orient] = (triangle) ((unsigned long) (botright).tri | (unsigned long) (botright).orient); (topright).tri[(topright).orient] = (triangle) ((unsigned long) (toplcasing).tri | (unsigned long) (toplcasing).orient); (toplcasing).tri[(toplcasing).orient] = (triangle) ((unsigned long) (topright).tri | (unsigned long) (topright).orient); if (m->checksegments) { sptr = (subseg) (topleft).tri[6 + (topleft).orient]; (toplsubseg).ssorient = (int) ((unsigned long) (sptr) & (unsigned long) 1l); (toplsubseg).ss = (subseg *) ((unsigned long) (sptr) & ~ (unsigned long) 3l); sptr = (subseg) (botleft).tri[6 + (botleft).orient]; (botlsubseg).ssorient = (int) ((unsigned long) (sptr) & (unsigned long) 1l); (botlsubseg).ss = (subseg *) ((unsigned long) (sptr) & ~ (unsigned long) 3l); sptr = (subseg) (botright).tri[6 + (botright).orient]; (botrsubseg).ssorient = (int) ((unsigned long) (sptr) & (unsigned long) 1l); (botrsubseg).ss = (subseg *) ((unsigned long) (sptr) & ~ (unsigned long) 3l); sptr = (subseg) (topright).tri[6 + (topright).orient]; (toprsubseg).ssorient = (int) ((unsigned long) (sptr) & (unsigned long) 1l); (toprsubseg).ss = (subseg *) ((unsigned long) (sptr) & ~ (unsigned long) 3l); if (toplsubseg.ss == m->dummysub) { (topright).tri[6 + (topright).orient] = (triangle) m->dummysub; } else { (topright).tri[6 + (topright).orient] = (triangle) (subseg) ((unsigned long) (toplsubseg).ss | (unsigned long) (toplsubseg).ssorient); (toplsubseg).ss[4 + (toplsubseg).ssorient] = (subseg) (triangle) ((unsigned long) (topright).tri | (unsigned long) (topright).orient); } if (botlsubseg.ss == m->dummysub) { (topleft).tri[6 + (topleft).orient] = (triangle) m->dummysub; } else { (topleft).tri[6 + (topleft).orient] = (triangle) (subseg) ((unsigned long) (botlsubseg).ss | (unsigned long) (botlsubseg).ssorient); (botlsubseg).ss[4 + (botlsubseg).ssorient] = (subseg) (triangle) ((unsigned long) (topleft).tri | (unsigned long) (topleft).orient); } if (botrsubseg.ss == m->dummysub) { (botleft).tri[6 + (botleft).orient] = (triangle) m->dummysub; } else { (botleft).tri[6 + (botleft).orient] = (triangle) (subseg) ((unsigned long) (botrsubseg).ss | (unsigned long) (botrsubseg).ssorient); (botrsubseg).ss[4 + (botrsubseg).ssorient] = (subseg) (triangle) ((unsigned long) (botleft).tri | (unsigned long) (botleft).orient); } if (toprsubseg.ss == m->dummysub) { (botright).tri[6 + (botright).orient] = (triangle) m->dummysub; } else { (botright).tri[6 + (botright).orient] = (triangle) (subseg) ((unsigned long) (toprsubseg).ss | (unsigned long) (toprsubseg).ssorient); (toprsubseg).ss[4 + (toprsubseg).ssorient] = (subseg) (triangle) ((unsigned long) (botright).tri | (unsigned long) (botright).orient); } } (horiz).tri[plus1mod3[(horiz).orient] + 3] = (triangle) farvertex; (horiz).tri[minus1mod3[(horiz).orient] + 3] = (triangle) newvertex; (horiz).tri[(horiz).orient + 3] = (triangle) rightvertex; (top).tri[plus1mod3[(top).orient] + 3] = (triangle) newvertex; (top).tri[minus1mod3[(top).orient] + 3] = (triangle) farvertex; (top).tri[(top).orient + 3] = (triangle) leftvertex; for (i = 0; i < m->eextras; i++) { attrib = 0.5 * (((double *) (top).tri)[m->elemattribindex + (i)] + ((double *) (horiz).tri)[m->elemattribindex + (i)]); ((double *) (top).tri)[m->elemattribindex + (i)] = attrib; ((double *) (horiz).tri)[m->elemattribindex + (i)] = attrib; } if (b->vararea) { if ((((double *) (top).tri)[m->areaboundindex] <= 0.0) || (((double *) (horiz).tri)[m->areaboundindex] <= 0.0)) { area = -1.0; } else { area = 0.5 * (((double *) (top).tri)[m->areaboundindex] + ((double *) (horiz).tri)[m->areaboundindex]); } ((double *) (top).tri)[m->areaboundindex] = area; ((double *) (horiz).tri)[m->areaboundindex] = area; } if (m->checkquality) { newflip = (struct flipstacker *) poolalloc(&m->flipstackers); newflip->flippedtri = (triangle) ((unsigned long) (horiz).tri | (unsigned long) (horiz).orient); newflip->prevflip = m->lastflip; m->lastflip = newflip; } # 8707 "triangle.c" if (b->verbose > 2) { fprintf(stderr, " Edge flip results in left "); (topleft).orient = plus1mod3[(topleft).orient]; printtriangle(m, b, &topleft); fprintf(stderr, " and right "); printtriangle(m, b, &horiz); } (horiz).orient = minus1mod3[(horiz).orient]; leftvertex = farvertex; } } } if (!doflip) { if (triflaws) { testtriangle(m, b, &horiz); } (horiz).orient = plus1mod3[(horiz).orient]; ptr = (horiz).tri[(horiz).orient]; (testtri).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (testtri).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (testtri).orient);; if ((leftvertex == first) || (testtri.tri == m->dummytri)) { (*searchtri).tri = (horiz).tri; (*searchtri).orient = plus1mod3[(horiz).orient]; (m->recenttri).tri = (horiz).tri; (m->recenttri).orient = plus1mod3[(horiz).orient]; return success; } (horiz).tri = (testtri).tri; (horiz).orient = plus1mod3[(testtri).orient]; rightvertex = leftvertex; leftvertex = (vertex) (horiz).tri[minus1mod3[(horiz).orient] + 3]; } } } # 8819 "triangle.c" void triangulatepolygon(m, b, firstedge, lastedge, edgecount, doflip, triflaws) struct mesh *m; struct behavior *b; struct otri *firstedge; struct otri *lastedge; int edgecount; int doflip; int triflaws; { struct otri testtri; struct otri besttri; struct otri tempedge; vertex leftbasevertex, rightbasevertex; vertex testvertex; vertex bestvertex; int bestnumber; int i; triangle ptr; leftbasevertex = (vertex) (*lastedge).tri[(*lastedge).orient + 3]; rightbasevertex = (vertex) (*firstedge).tri[minus1mod3[(*firstedge).orient] + 3]; if (b->verbose > 2) { fprintf(stderr, " Triangulating interior polygon at edge\n"); fprintf(stderr, " (%.12g, %.12g) (%.12g, %.12g)\n", leftbasevertex[0], leftbasevertex[1], rightbasevertex[0], rightbasevertex[1]); } (besttri).tri = (*firstedge).tri; (besttri).orient = minus1mod3[(*firstedge).orient]; ptr = (besttri).tri[(besttri).orient]; (besttri).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (besttri).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (besttri).orient);;; bestvertex = (vertex) (besttri).tri[minus1mod3[(besttri).orient] + 3]; (testtri).tri = (besttri).tri; (testtri).orient = (besttri).orient; bestnumber = 1; for (i = 2; i <= edgecount - 2; i++) { (testtri).orient = minus1mod3[(testtri).orient]; ptr = (testtri).tri[(testtri).orient]; (testtri).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (testtri).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (testtri).orient);;; testvertex = (vertex) (testtri).tri[minus1mod3[(testtri).orient] + 3]; if (incircle(m, b, leftbasevertex, rightbasevertex, bestvertex, testvertex) > 0.0) { (besttri).tri = (testtri).tri; (besttri).orient = (testtri).orient; bestvertex = testvertex; bestnumber = i; } } if (b->verbose > 2) { fprintf(stderr, " Connecting edge to (%.12g, %.12g)\n", bestvertex[0], bestvertex[1]); } if (bestnumber > 1) { ptr = (besttri).tri[(besttri).orient]; (tempedge).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (tempedge).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (tempedge).orient);; (tempedge).orient = plus1mod3[(tempedge).orient];; triangulatepolygon(m, b, firstedge, &tempedge, bestnumber + 1, 1, triflaws); } if (bestnumber < edgecount - 2) { ptr = (besttri).tri[(besttri).orient]; (tempedge).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (tempedge).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (tempedge).orient);; triangulatepolygon(m, b, &besttri, lastedge, edgecount - bestnumber, 1, triflaws); ptr = (tempedge).tri[(tempedge).orient]; (besttri).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (besttri).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (besttri).orient);; } if (doflip) { flip(m, b, &besttri); if (triflaws) { ptr = (besttri).tri[(besttri).orient]; (testtri).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (testtri).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (testtri).orient);; testtriangle(m, b, &testtri); } } (*lastedge).tri = (besttri).tri; (*lastedge).orient = (besttri).orient; } # 8916 "triangle.c" void deletevertex(m, b, deltri) struct mesh *m; struct behavior *b; struct otri *deltri; { struct otri countingtri; struct otri firstedge, lastedge; struct otri deltriright; struct otri lefttri, righttri; struct otri leftcasing, rightcasing; struct osub leftsubseg, rightsubseg; vertex delvertex; vertex neworg; int edgecount; triangle ptr; subseg sptr; delvertex = (vertex) (*deltri).tri[plus1mod3[(*deltri).orient] + 3]; if (b->verbose > 1) { fprintf(stderr, " Deleting (%.12g, %.12g).\n", delvertex[0], delvertex[1]); } vertexdealloc(m, delvertex); (countingtri).tri = (*deltri).tri; (countingtri).orient = minus1mod3[(*deltri).orient]; ptr = (countingtri).tri[(countingtri).orient]; (countingtri).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (countingtri).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (countingtri).orient);;; edgecount = 1; while (!(((*deltri).tri == (countingtri).tri) && ((*deltri).orient == (countingtri).orient))) { edgecount++; (countingtri).orient = minus1mod3[(countingtri).orient]; ptr = (countingtri).tri[(countingtri).orient]; (countingtri).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (countingtri).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (countingtri).orient);;; } # 8963 "triangle.c" if (edgecount > 3) { (firstedge).tri = (*deltri).tri; (firstedge).orient = minus1mod3[(*deltri).orient]; ptr = (firstedge).tri[(firstedge).orient]; (firstedge).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (firstedge).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (firstedge).orient);;; ptr = (*deltri).tri[(*deltri).orient]; (lastedge).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (lastedge).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (lastedge).orient);; (lastedge).orient = plus1mod3[(lastedge).orient];; triangulatepolygon(m, b, &firstedge, &lastedge, edgecount, 0, !b->nobisect); } (deltriright).tri = (*deltri).tri; (deltriright).orient = minus1mod3[(*deltri).orient]; ptr = (*deltri).tri[(*deltri).orient]; (lefttri).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (lefttri).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (lefttri).orient);; (lefttri).orient = minus1mod3[(lefttri).orient];; ptr = (lefttri).tri[(lefttri).orient]; (leftcasing).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (leftcasing).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (leftcasing).orient);; ptr = (deltriright).tri[(deltriright).orient]; (righttri).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (righttri).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (righttri).orient);; (righttri).orient = plus1mod3[(righttri).orient];; ptr = (righttri).tri[(righttri).orient]; (rightcasing).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (rightcasing).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (rightcasing).orient);; (*deltri).tri[(*deltri).orient] = (triangle) ((unsigned long) (leftcasing).tri | (unsigned long) (leftcasing).orient); (leftcasing).tri[(leftcasing).orient] = (triangle) ((unsigned long) (*deltri).tri | (unsigned long) (*deltri).orient); (deltriright).tri[(deltriright).orient] = (triangle) ((unsigned long) (rightcasing).tri | (unsigned long) (rightcasing).orient); (rightcasing).tri[(rightcasing).orient] = (triangle) ((unsigned long) (deltriright).tri | (unsigned long) (deltriright).orient); sptr = (subseg) (lefttri).tri[6 + (lefttri).orient]; (leftsubseg).ssorient = (int) ((unsigned long) (sptr) & (unsigned long) 1l); (leftsubseg).ss = (subseg *) ((unsigned long) (sptr) & ~ (unsigned long) 3l); if (leftsubseg.ss != m->dummysub) { (*deltri).tri[6 + (*deltri).orient] = (triangle) (subseg) ((unsigned long) (leftsubseg).ss | (unsigned long) (leftsubseg).ssorient); (leftsubseg).ss[4 + (leftsubseg).ssorient] = (subseg) (triangle) ((unsigned long) (*deltri).tri | (unsigned long) (*deltri).orient); } sptr = (subseg) (righttri).tri[6 + (righttri).orient]; (rightsubseg).ssorient = (int) ((unsigned long) (sptr) & (unsigned long) 1l); (rightsubseg).ss = (subseg *) ((unsigned long) (sptr) & ~ (unsigned long) 3l); if (rightsubseg.ss != m->dummysub) { (deltriright).tri[6 + (deltriright).orient] = (triangle) (subseg) ((unsigned long) (rightsubseg).ss | (unsigned long) (rightsubseg).ssorient); (rightsubseg).ss[4 + (rightsubseg).ssorient] = (subseg) (triangle) ((unsigned long) (deltriright).tri | (unsigned long) (deltriright).orient); } neworg = (vertex) (lefttri).tri[plus1mod3[(lefttri).orient] + 3]; (*deltri).tri[plus1mod3[(*deltri).orient] + 3] = (triangle) neworg; if (!b->nobisect) { testtriangle(m, b, deltri); } triangledealloc(m, lefttri.tri); triangledealloc(m, righttri.tri); } # 9019 "triangle.c" void undovertex(m, b) struct mesh *m; struct behavior *b; { struct otri fliptri; struct otri botleft, botright, topright; struct otri botlcasing, botrcasing, toprcasing; struct otri gluetri; struct osub botlsubseg, botrsubseg, toprsubseg; vertex botvertex, rightvertex; triangle ptr; subseg sptr; while (m->lastflip != (struct flipstacker *) ((void *)0)) { (fliptri).orient = (int) ((unsigned long) (m->lastflip->flippedtri) & (unsigned long) 3l); (fliptri).tri = (triangle *) ((unsigned long) (m->lastflip->flippedtri) ^ (unsigned long) (fliptri).orient); if (m->lastflip->prevflip == (struct flipstacker *) ((void *)0)) { (botleft).tri = (fliptri).tri; (botleft).orient = plus1mod3[(fliptri).orient]; ptr = (botleft).tri[(botleft).orient]; (botleft).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (botleft).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (botleft).orient);;; (botleft).orient = plus1mod3[(botleft).orient]; (botright).tri = (fliptri).tri; (botright).orient = minus1mod3[(fliptri).orient]; ptr = (botright).tri[(botright).orient]; (botright).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (botright).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (botright).orient);;; (botright).orient = minus1mod3[(botright).orient]; ptr = (botleft).tri[(botleft).orient]; (botlcasing).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (botlcasing).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (botlcasing).orient);; ptr = (botright).tri[(botright).orient]; (botrcasing).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (botrcasing).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (botrcasing).orient);; botvertex = (vertex) (botleft).tri[minus1mod3[(botleft).orient] + 3]; (fliptri).tri[(fliptri).orient + 3] = (triangle) botvertex; (fliptri).orient = plus1mod3[(fliptri).orient]; (fliptri).tri[(fliptri).orient] = (triangle) ((unsigned long) (botlcasing).tri | (unsigned long) (botlcasing).orient); (botlcasing).tri[(botlcasing).orient] = (triangle) ((unsigned long) (fliptri).tri | (unsigned long) (fliptri).orient); sptr = (subseg) (botleft).tri[6 + (botleft).orient]; (botlsubseg).ssorient = (int) ((unsigned long) (sptr) & (unsigned long) 1l); (botlsubseg).ss = (subseg *) ((unsigned long) (sptr) & ~ (unsigned long) 3l); (fliptri).tri[6 + (fliptri).orient] = (triangle) (subseg) ((unsigned long) (botlsubseg).ss | (unsigned long) (botlsubseg).ssorient); (botlsubseg).ss[4 + (botlsubseg).ssorient] = (subseg) (triangle) ((unsigned long) (fliptri).tri | (unsigned long) (fliptri).orient); (fliptri).orient = plus1mod3[(fliptri).orient]; (fliptri).tri[(fliptri).orient] = (triangle) ((unsigned long) (botrcasing).tri | (unsigned long) (botrcasing).orient); (botrcasing).tri[(botrcasing).orient] = (triangle) ((unsigned long) (fliptri).tri | (unsigned long) (fliptri).orient); sptr = (subseg) (botright).tri[6 + (botright).orient]; (botrsubseg).ssorient = (int) ((unsigned long) (sptr) & (unsigned long) 1l); (botrsubseg).ss = (subseg *) ((unsigned long) (sptr) & ~ (unsigned long) 3l); (fliptri).tri[6 + (fliptri).orient] = (triangle) (subseg) ((unsigned long) (botrsubseg).ss | (unsigned long) (botrsubseg).ssorient); (botrsubseg).ss[4 + (botrsubseg).ssorient] = (subseg) (triangle) ((unsigned long) (fliptri).tri | (unsigned long) (fliptri).orient); triangledealloc(m, botleft.tri); triangledealloc(m, botright.tri); } else if (m->lastflip->prevflip == (struct flipstacker *) &insertvertex) { (gluetri).tri = (fliptri).tri; (gluetri).orient = minus1mod3[(fliptri).orient]; ptr = (gluetri).tri[(gluetri).orient]; (botright).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (botright).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (botright).orient);; (botright).orient = plus1mod3[(botright).orient]; ptr = (botright).tri[(botright).orient]; (botrcasing).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (botrcasing).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (botrcasing).orient);; rightvertex = (vertex) (botright).tri[minus1mod3[(botright).orient] + 3]; (fliptri).tri[plus1mod3[(fliptri).orient] + 3] = (triangle) rightvertex; (gluetri).tri[(gluetri).orient] = (triangle) ((unsigned long) (botrcasing).tri | (unsigned long) (botrcasing).orient); (botrcasing).tri[(botrcasing).orient] = (triangle) ((unsigned long) (gluetri).tri | (unsigned long) (gluetri).orient); sptr = (subseg) (botright).tri[6 + (botright).orient]; (botrsubseg).ssorient = (int) ((unsigned long) (sptr) & (unsigned long) 1l); (botrsubseg).ss = (subseg *) ((unsigned long) (sptr) & ~ (unsigned long) 3l); (gluetri).tri[6 + (gluetri).orient] = (triangle) (subseg) ((unsigned long) (botrsubseg).ss | (unsigned long) (botrsubseg).ssorient); (botrsubseg).ss[4 + (botrsubseg).ssorient] = (subseg) (triangle) ((unsigned long) (gluetri).tri | (unsigned long) (gluetri).orient); triangledealloc(m, botright.tri); ptr = (fliptri).tri[(fliptri).orient]; (gluetri).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (gluetri).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (gluetri).orient);; if (gluetri.tri != m->dummytri) { (gluetri).orient = plus1mod3[(gluetri).orient]; ptr = (gluetri).tri[(gluetri).orient]; (topright).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (topright).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (topright).orient);; (topright).orient = minus1mod3[(topright).orient];; ptr = (topright).tri[(topright).orient]; (toprcasing).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (toprcasing).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (toprcasing).orient);; (gluetri).tri[plus1mod3[(gluetri).orient] + 3] = (triangle) rightvertex; (gluetri).tri[(gluetri).orient] = (triangle) ((unsigned long) (toprcasing).tri | (unsigned long) (toprcasing).orient); (toprcasing).tri[(toprcasing).orient] = (triangle) ((unsigned long) (gluetri).tri | (unsigned long) (gluetri).orient); sptr = (subseg) (topright).tri[6 + (topright).orient]; (toprsubseg).ssorient = (int) ((unsigned long) (sptr) & (unsigned long) 1l); (toprsubseg).ss = (subseg *) ((unsigned long) (sptr) & ~ (unsigned long) 3l); (gluetri).tri[6 + (gluetri).orient] = (triangle) (subseg) ((unsigned long) (toprsubseg).ss | (unsigned long) (toprsubseg).ssorient); (toprsubseg).ss[4 + (toprsubseg).ssorient] = (subseg) (triangle) ((unsigned long) (gluetri).tri | (unsigned long) (gluetri).orient); triangledealloc(m, topright.tri); } m->lastflip->prevflip = (struct flipstacker *) ((void *)0); } else { unflip(m, b, &fliptri); } m->lastflip = m->lastflip->prevflip; } } # 9166 "triangle.c" void vertexsort(sortarray, arraysize) vertex *sortarray; int arraysize; { int left, right; int pivot; double pivotx, pivoty; vertex temp; if (arraysize == 2) { if ((sortarray[0][0] > sortarray[1][0]) || ((sortarray[0][0] == sortarray[1][0]) && (sortarray[0][1] > sortarray[1][1]))) { temp = sortarray[1]; sortarray[1] = sortarray[0]; sortarray[0] = temp; } return; } pivot = (int) randomnation(arraysize); pivotx = sortarray[pivot][0]; pivoty = sortarray[pivot][1]; left = -1; right = arraysize; while (left < right) { do { left++; } while ((left <= right) && ((sortarray[left][0] < pivotx) || ((sortarray[left][0] == pivotx) && (sortarray[left][1] < pivoty)))); do { right--; } while ((left <= right) && ((sortarray[right][0] > pivotx) || ((sortarray[right][0] == pivotx) && (sortarray[right][1] > pivoty)))); if (left < right) { temp = sortarray[left]; sortarray[left] = sortarray[right]; sortarray[right] = temp; } } if (left > 1) { vertexsort(sortarray, left); } if (right < arraysize - 2) { vertexsort(&sortarray[right + 1], arraysize - right - 1); } } # 9240 "triangle.c" void vertexmedian(sortarray, arraysize, median, axis) vertex *sortarray; int arraysize; int median; int axis; { int left, right; int pivot; double pivot1, pivot2; vertex temp; if (arraysize == 2) { if ((sortarray[0][axis] > sortarray[1][axis]) || ((sortarray[0][axis] == sortarray[1][axis]) && (sortarray[0][1 - axis] > sortarray[1][1 - axis]))) { temp = sortarray[1]; sortarray[1] = sortarray[0]; sortarray[0] = temp; } return; } pivot = (int) randomnation(arraysize); pivot1 = sortarray[pivot][axis]; pivot2 = sortarray[pivot][1 - axis]; left = -1; right = arraysize; while (left < right) { do { left++; } while ((left <= right) && ((sortarray[left][axis] < pivot1) || ((sortarray[left][axis] == pivot1) && (sortarray[left][1 - axis] < pivot2)))); do { right--; } while ((left <= right) && ((sortarray[right][axis] > pivot1) || ((sortarray[right][axis] == pivot1) && (sortarray[right][1 - axis] > pivot2)))); if (left < right) { temp = sortarray[left]; sortarray[left] = sortarray[right]; sortarray[right] = temp; } } if (left > median) { vertexmedian(sortarray, left, median, axis); } if (right < median - 1) { vertexmedian(&sortarray[right + 1], arraysize - right - 1, median - right - 1, axis); } } # 9318 "triangle.c" void alternateaxes(sortarray, arraysize, axis) vertex *sortarray; int arraysize; int axis; { int divider; divider = arraysize >> 1; if (arraysize <= 3) { axis = 0; } vertexmedian(sortarray, arraysize, divider, axis); if (arraysize - divider >= 2) { if (divider >= 2) { alternateaxes(sortarray, divider, 1 - axis); } alternateaxes(&sortarray[divider], arraysize - divider, 1 - axis); } } # 9384 "triangle.c" void mergehulls(m, b, farleft, innerleft, innerright, farright, axis) struct mesh *m; struct behavior *b; struct otri *farleft; struct otri *innerleft; struct otri *innerright; struct otri *farright; int axis; { struct otri leftcand, rightcand; struct otri baseedge; struct otri nextedge; struct otri sidecasing, topcasing, outercasing; struct otri checkedge; vertex innerleftdest; vertex innerrightorg; vertex innerleftapex, innerrightapex; vertex farleftpt, farrightpt; vertex farleftapex, farrightapex; vertex lowerleft, lowerright; vertex upperleft, upperright; vertex nextapex; vertex checkvertex; int changemade; int badedge; int leftfinished, rightfinished; triangle ptr; innerleftdest = (vertex) (*innerleft).tri[minus1mod3[(*innerleft).orient] + 3]; innerleftapex = (vertex) (*innerleft).tri[(*innerleft).orient + 3]; innerrightorg = (vertex) (*innerright).tri[plus1mod3[(*innerright).orient] + 3]; innerrightapex = (vertex) (*innerright).tri[(*innerright).orient + 3]; if (b->dwyer && (axis == 1)) { farleftpt = (vertex) (*farleft).tri[plus1mod3[(*farleft).orient] + 3]; farleftapex = (vertex) (*farleft).tri[(*farleft).orient + 3]; farrightpt = (vertex) (*farright).tri[minus1mod3[(*farright).orient] + 3]; farrightapex = (vertex) (*farright).tri[(*farright).orient + 3]; while (farleftapex[1] < farleftpt[1]) { (*farleft).orient = plus1mod3[(*farleft).orient]; ptr = (*farleft).tri[(*farleft).orient]; (*farleft).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (*farleft).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (*farleft).orient);; farleftpt = farleftapex; farleftapex = (vertex) (*farleft).tri[(*farleft).orient + 3]; } ptr = (*innerleft).tri[(*innerleft).orient]; (checkedge).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (checkedge).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (checkedge).orient);; checkvertex = (vertex) (checkedge).tri[(checkedge).orient + 3]; while (checkvertex[1] > innerleftdest[1]) { (*innerleft).tri = (checkedge).tri; (*innerleft).orient = plus1mod3[(checkedge).orient]; innerleftapex = innerleftdest; innerleftdest = checkvertex; ptr = (*innerleft).tri[(*innerleft).orient]; (checkedge).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (checkedge).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (checkedge).orient);; checkvertex = (vertex) (checkedge).tri[(checkedge).orient + 3]; } while (innerrightapex[1] < innerrightorg[1]) { (*innerright).orient = plus1mod3[(*innerright).orient]; ptr = (*innerright).tri[(*innerright).orient]; (*innerright).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (*innerright).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (*innerright).orient);; innerrightorg = innerrightapex; innerrightapex = (vertex) (*innerright).tri[(*innerright).orient + 3]; } ptr = (*farright).tri[(*farright).orient]; (checkedge).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (checkedge).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (checkedge).orient);; checkvertex = (vertex) (checkedge).tri[(checkedge).orient + 3]; while (checkvertex[1] > farrightpt[1]) { (*farright).tri = (checkedge).tri; (*farright).orient = plus1mod3[(checkedge).orient]; farrightapex = farrightpt; farrightpt = checkvertex; ptr = (*farright).tri[(*farright).orient]; (checkedge).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (checkedge).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (checkedge).orient);; checkvertex = (vertex) (checkedge).tri[(checkedge).orient + 3]; } } do { changemade = 0; if (counterclockwise(m, b, innerleftdest, innerleftapex, innerrightorg) > 0.0) { (*innerleft).orient = minus1mod3[(*innerleft).orient]; ptr = (*innerleft).tri[(*innerleft).orient]; (*innerleft).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (*innerleft).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (*innerleft).orient);; innerleftdest = innerleftapex; innerleftapex = (vertex) (*innerleft).tri[(*innerleft).orient + 3]; changemade = 1; } if (counterclockwise(m, b, innerrightapex, innerrightorg, innerleftdest) > 0.0) { (*innerright).orient = plus1mod3[(*innerright).orient]; ptr = (*innerright).tri[(*innerright).orient]; (*innerright).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (*innerright).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (*innerright).orient);; innerrightorg = innerrightapex; innerrightapex = (vertex) (*innerright).tri[(*innerright).orient + 3]; changemade = 1; } } while (changemade); ptr = (*innerleft).tri[(*innerleft).orient]; (leftcand).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (leftcand).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (leftcand).orient);; ptr = (*innerright).tri[(*innerright).orient]; (rightcand).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (rightcand).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (rightcand).orient);; maketriangle(m, b, &baseedge); (baseedge).tri[(baseedge).orient] = (triangle) ((unsigned long) (*innerleft).tri | (unsigned long) (*innerleft).orient); (*innerleft).tri[(*innerleft).orient] = (triangle) ((unsigned long) (baseedge).tri | (unsigned long) (baseedge).orient); (baseedge).orient = plus1mod3[(baseedge).orient]; (baseedge).tri[(baseedge).orient] = (triangle) ((unsigned long) (*innerright).tri | (unsigned long) (*innerright).orient); (*innerright).tri[(*innerright).orient] = (triangle) ((unsigned long) (baseedge).tri | (unsigned long) (baseedge).orient); (baseedge).orient = plus1mod3[(baseedge).orient]; (baseedge).tri[plus1mod3[(baseedge).orient] + 3] = (triangle) innerrightorg; (baseedge).tri[minus1mod3[(baseedge).orient] + 3] = (triangle) innerleftdest; if (b->verbose > 2) { fprintf(stderr, " Creating base bounding "); printtriangle(m, b, &baseedge); } farleftpt = (vertex) (*farleft).tri[plus1mod3[(*farleft).orient] + 3]; if (innerleftdest == farleftpt) { (*farleft).tri = (baseedge).tri; (*farleft).orient = plus1mod3[(baseedge).orient]; } farrightpt = (vertex) (*farright).tri[minus1mod3[(*farright).orient] + 3]; if (innerrightorg == farrightpt) { (*farright).tri = (baseedge).tri; (*farright).orient = minus1mod3[(baseedge).orient]; } lowerleft = innerleftdest; lowerright = innerrightorg; upperleft = (vertex) (leftcand).tri[(leftcand).orient + 3]; upperright = (vertex) (rightcand).tri[(rightcand).orient + 3]; while (1) { leftfinished = counterclockwise(m, b, upperleft, lowerleft, lowerright) <= 0.0; rightfinished = counterclockwise(m, b, upperright, lowerleft, lowerright) <= 0.0; if (leftfinished && rightfinished) { maketriangle(m, b, &nextedge); (nextedge).tri[plus1mod3[(nextedge).orient] + 3] = (triangle) lowerleft; (nextedge).tri[minus1mod3[(nextedge).orient] + 3] = (triangle) lowerright; (nextedge).tri[(nextedge).orient] = (triangle) ((unsigned long) (baseedge).tri | (unsigned long) (baseedge).orient); (baseedge).tri[(baseedge).orient] = (triangle) ((unsigned long) (nextedge).tri | (unsigned long) (nextedge).orient); (nextedge).orient = plus1mod3[(nextedge).orient]; (nextedge).tri[(nextedge).orient] = (triangle) ((unsigned long) (rightcand).tri | (unsigned long) (rightcand).orient); (rightcand).tri[(rightcand).orient] = (triangle) ((unsigned long) (nextedge).tri | (unsigned long) (nextedge).orient); (nextedge).orient = plus1mod3[(nextedge).orient]; (nextedge).tri[(nextedge).orient] = (triangle) ((unsigned long) (leftcand).tri | (unsigned long) (leftcand).orient); (leftcand).tri[(leftcand).orient] = (triangle) ((unsigned long) (nextedge).tri | (unsigned long) (nextedge).orient); if (b->verbose > 2) { fprintf(stderr, " Creating top bounding "); printtriangle(m, b, &nextedge); } if (b->dwyer && (axis == 1)) { farleftpt = (vertex) (*farleft).tri[plus1mod3[(*farleft).orient] + 3]; farleftapex = (vertex) (*farleft).tri[(*farleft).orient + 3]; farrightpt = (vertex) (*farright).tri[minus1mod3[(*farright).orient] + 3]; farrightapex = (vertex) (*farright).tri[(*farright).orient + 3]; ptr = (*farleft).tri[(*farleft).orient]; (checkedge).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (checkedge).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (checkedge).orient);; checkvertex = (vertex) (checkedge).tri[(checkedge).orient + 3]; while (checkvertex[0] < farleftpt[0]) { (*farleft).tri = (checkedge).tri; (*farleft).orient = minus1mod3[(checkedge).orient]; farleftapex = farleftpt; farleftpt = checkvertex; ptr = (*farleft).tri[(*farleft).orient]; (checkedge).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (checkedge).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (checkedge).orient);; checkvertex = (vertex) (checkedge).tri[(checkedge).orient + 3]; } while (farrightapex[0] > farrightpt[0]) { (*farright).orient = minus1mod3[(*farright).orient]; ptr = (*farright).tri[(*farright).orient]; (*farright).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (*farright).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (*farright).orient);; farrightpt = farrightapex; farrightapex = (vertex) (*farright).tri[(*farright).orient + 3]; } } return; } if (!leftfinished) { (nextedge).tri = (leftcand).tri; (nextedge).orient = minus1mod3[(leftcand).orient]; ptr = (nextedge).tri[(nextedge).orient]; (nextedge).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (nextedge).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (nextedge).orient);; nextapex = (vertex) (nextedge).tri[(nextedge).orient + 3]; if (nextapex != (vertex) ((void *)0)) { badedge = incircle(m, b, lowerleft, lowerright, upperleft, nextapex) > 0.0; while (badedge) { (nextedge).orient = plus1mod3[(nextedge).orient]; ptr = (nextedge).tri[(nextedge).orient]; (topcasing).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (topcasing).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (topcasing).orient);; (nextedge).orient = plus1mod3[(nextedge).orient]; ptr = (nextedge).tri[(nextedge).orient]; (sidecasing).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (sidecasing).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (sidecasing).orient);; (nextedge).tri[(nextedge).orient] = (triangle) ((unsigned long) (topcasing).tri | (unsigned long) (topcasing).orient); (topcasing).tri[(topcasing).orient] = (triangle) ((unsigned long) (nextedge).tri | (unsigned long) (nextedge).orient); (leftcand).tri[(leftcand).orient] = (triangle) ((unsigned long) (sidecasing).tri | (unsigned long) (sidecasing).orient); (sidecasing).tri[(sidecasing).orient] = (triangle) ((unsigned long) (leftcand).tri | (unsigned long) (leftcand).orient); (leftcand).orient = plus1mod3[(leftcand).orient]; ptr = (leftcand).tri[(leftcand).orient]; (outercasing).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (outercasing).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (outercasing).orient);; (nextedge).orient = minus1mod3[(nextedge).orient]; (nextedge).tri[(nextedge).orient] = (triangle) ((unsigned long) (outercasing).tri | (unsigned long) (outercasing).orient); (outercasing).tri[(outercasing).orient] = (triangle) ((unsigned long) (nextedge).tri | (unsigned long) (nextedge).orient); (leftcand).tri[plus1mod3[(leftcand).orient] + 3] = (triangle) lowerleft; (leftcand).tri[minus1mod3[(leftcand).orient] + 3] = (triangle) ((void *)0); (leftcand).tri[(leftcand).orient + 3] = (triangle) nextapex; (nextedge).tri[plus1mod3[(nextedge).orient] + 3] = (triangle) ((void *)0); (nextedge).tri[minus1mod3[(nextedge).orient] + 3] = (triangle) upperleft; (nextedge).tri[(nextedge).orient + 3] = (triangle) nextapex; upperleft = nextapex; (nextedge).tri = (sidecasing).tri; (nextedge).orient = (sidecasing).orient; nextapex = (vertex) (nextedge).tri[(nextedge).orient + 3]; if (nextapex != (vertex) ((void *)0)) { badedge = incircle(m, b, lowerleft, lowerright, upperleft, nextapex) > 0.0; } else { badedge = 0; } } } } if (!rightfinished) { (nextedge).tri = (rightcand).tri; (nextedge).orient = plus1mod3[(rightcand).orient]; ptr = (nextedge).tri[(nextedge).orient]; (nextedge).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (nextedge).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (nextedge).orient);; nextapex = (vertex) (nextedge).tri[(nextedge).orient + 3]; if (nextapex != (vertex) ((void *)0)) { badedge = incircle(m, b, lowerleft, lowerright, upperright, nextapex) > 0.0; while (badedge) { (nextedge).orient = minus1mod3[(nextedge).orient]; ptr = (nextedge).tri[(nextedge).orient]; (topcasing).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (topcasing).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (topcasing).orient);; (nextedge).orient = minus1mod3[(nextedge).orient]; ptr = (nextedge).tri[(nextedge).orient]; (sidecasing).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (sidecasing).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (sidecasing).orient);; (nextedge).tri[(nextedge).orient] = (triangle) ((unsigned long) (topcasing).tri | (unsigned long) (topcasing).orient); (topcasing).tri[(topcasing).orient] = (triangle) ((unsigned long) (nextedge).tri | (unsigned long) (nextedge).orient); (rightcand).tri[(rightcand).orient] = (triangle) ((unsigned long) (sidecasing).tri | (unsigned long) (sidecasing).orient); (sidecasing).tri[(sidecasing).orient] = (triangle) ((unsigned long) (rightcand).tri | (unsigned long) (rightcand).orient); (rightcand).orient = minus1mod3[(rightcand).orient]; ptr = (rightcand).tri[(rightcand).orient]; (outercasing).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (outercasing).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (outercasing).orient);; (nextedge).orient = plus1mod3[(nextedge).orient]; (nextedge).tri[(nextedge).orient] = (triangle) ((unsigned long) (outercasing).tri | (unsigned long) (outercasing).orient); (outercasing).tri[(outercasing).orient] = (triangle) ((unsigned long) (nextedge).tri | (unsigned long) (nextedge).orient); (rightcand).tri[plus1mod3[(rightcand).orient] + 3] = (triangle) ((void *)0); (rightcand).tri[minus1mod3[(rightcand).orient] + 3] = (triangle) lowerright; (rightcand).tri[(rightcand).orient + 3] = (triangle) nextapex; (nextedge).tri[plus1mod3[(nextedge).orient] + 3] = (triangle) upperright; (nextedge).tri[minus1mod3[(nextedge).orient] + 3] = (triangle) ((void *)0); (nextedge).tri[(nextedge).orient + 3] = (triangle) nextapex; upperright = nextapex; (nextedge).tri = (sidecasing).tri; (nextedge).orient = (sidecasing).orient; nextapex = (vertex) (nextedge).tri[(nextedge).orient + 3]; if (nextapex != (vertex) ((void *)0)) { badedge = incircle(m, b, lowerleft, lowerright, upperright, nextapex) > 0.0; } else { badedge = 0; } } } } if (leftfinished || (!rightfinished && (incircle(m, b, upperleft, lowerleft, lowerright, upperright) > 0.0))) { (baseedge).tri[(baseedge).orient] = (triangle) ((unsigned long) (rightcand).tri | (unsigned long) (rightcand).orient); (rightcand).tri[(rightcand).orient] = (triangle) ((unsigned long) (baseedge).tri | (unsigned long) (baseedge).orient); (baseedge).tri = (rightcand).tri; (baseedge).orient = minus1mod3[(rightcand).orient]; (baseedge).tri[minus1mod3[(baseedge).orient] + 3] = (triangle) lowerleft; lowerright = upperright; ptr = (baseedge).tri[(baseedge).orient]; (rightcand).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (rightcand).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (rightcand).orient);; upperright = (vertex) (rightcand).tri[(rightcand).orient + 3]; } else { (baseedge).tri[(baseedge).orient] = (triangle) ((unsigned long) (leftcand).tri | (unsigned long) (leftcand).orient); (leftcand).tri[(leftcand).orient] = (triangle) ((unsigned long) (baseedge).tri | (unsigned long) (baseedge).orient); (baseedge).tri = (leftcand).tri; (baseedge).orient = plus1mod3[(leftcand).orient]; (baseedge).tri[plus1mod3[(baseedge).orient] + 3] = (triangle) lowerright; lowerleft = upperleft; ptr = (baseedge).tri[(baseedge).orient]; (leftcand).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (leftcand).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (leftcand).orient);; upperleft = (vertex) (leftcand).tri[(leftcand).orient + 3]; } if (b->verbose > 2) { fprintf(stderr, " Connecting "); printtriangle(m, b, &baseedge); } } } # 9711 "triangle.c" void divconqrecurse(m, b, sortarray, vertices, axis, farleft, farright) struct mesh *m; struct behavior *b; vertex *sortarray; int vertices; int axis; struct otri *farleft; struct otri *farright; { struct otri midtri, tri1, tri2, tri3; struct otri innerleft, innerright; double area; int divider; if (b->verbose > 2) { fprintf(stderr, " Triangulating %d vertices.\n", vertices); } if (vertices == 2) { maketriangle(m, b, farleft); (*farleft).tri[plus1mod3[(*farleft).orient] + 3] = (triangle) sortarray[0]; (*farleft).tri[minus1mod3[(*farleft).orient] + 3] = (triangle) sortarray[1]; maketriangle(m, b, farright); (*farright).tri[plus1mod3[(*farright).orient] + 3] = (triangle) sortarray[1]; (*farright).tri[minus1mod3[(*farright).orient] + 3] = (triangle) sortarray[0]; (*farleft).tri[(*farleft).orient] = (triangle) ((unsigned long) (*farright).tri | (unsigned long) (*farright).orient); (*farright).tri[(*farright).orient] = (triangle) ((unsigned long) (*farleft).tri | (unsigned long) (*farleft).orient); (*farleft).orient = minus1mod3[(*farleft).orient]; (*farright).orient = plus1mod3[(*farright).orient]; (*farleft).tri[(*farleft).orient] = (triangle) ((unsigned long) (*farright).tri | (unsigned long) (*farright).orient); (*farright).tri[(*farright).orient] = (triangle) ((unsigned long) (*farleft).tri | (unsigned long) (*farleft).orient); (*farleft).orient = minus1mod3[(*farleft).orient]; (*farright).orient = plus1mod3[(*farright).orient]; (*farleft).tri[(*farleft).orient] = (triangle) ((unsigned long) (*farright).tri | (unsigned long) (*farright).orient); (*farright).tri[(*farright).orient] = (triangle) ((unsigned long) (*farleft).tri | (unsigned long) (*farleft).orient); if (b->verbose > 2) { fprintf(stderr, " Creating "); printtriangle(m, b, farleft); fprintf(stderr, " Creating "); printtriangle(m, b, farright); } (*farleft).tri = (*farright).tri; (*farleft).orient = minus1mod3[(*farright).orient]; return; } else if (vertices == 3) { maketriangle(m, b, &midtri); maketriangle(m, b, &tri1); maketriangle(m, b, &tri2); maketriangle(m, b, &tri3); area = counterclockwise(m, b, sortarray[0], sortarray[1], sortarray[2]); if (area == 0.0) { (midtri).tri[plus1mod3[(midtri).orient] + 3] = (triangle) sortarray[0]; (midtri).tri[minus1mod3[(midtri).orient] + 3] = (triangle) sortarray[1]; (tri1).tri[plus1mod3[(tri1).orient] + 3] = (triangle) sortarray[1]; (tri1).tri[minus1mod3[(tri1).orient] + 3] = (triangle) sortarray[0]; (tri2).tri[plus1mod3[(tri2).orient] + 3] = (triangle) sortarray[2]; (tri2).tri[minus1mod3[(tri2).orient] + 3] = (triangle) sortarray[1]; (tri3).tri[plus1mod3[(tri3).orient] + 3] = (triangle) sortarray[1]; (tri3).tri[minus1mod3[(tri3).orient] + 3] = (triangle) sortarray[2]; (midtri).tri[(midtri).orient] = (triangle) ((unsigned long) (tri1).tri | (unsigned long) (tri1).orient); (tri1).tri[(tri1).orient] = (triangle) ((unsigned long) (midtri).tri | (unsigned long) (midtri).orient); (tri2).tri[(tri2).orient] = (triangle) ((unsigned long) (tri3).tri | (unsigned long) (tri3).orient); (tri3).tri[(tri3).orient] = (triangle) ((unsigned long) (tri2).tri | (unsigned long) (tri2).orient); (midtri).orient = plus1mod3[(midtri).orient]; (tri1).orient = minus1mod3[(tri1).orient]; (tri2).orient = plus1mod3[(tri2).orient]; (tri3).orient = minus1mod3[(tri3).orient]; (midtri).tri[(midtri).orient] = (triangle) ((unsigned long) (tri3).tri | (unsigned long) (tri3).orient); (tri3).tri[(tri3).orient] = (triangle) ((unsigned long) (midtri).tri | (unsigned long) (midtri).orient); (tri1).tri[(tri1).orient] = (triangle) ((unsigned long) (tri2).tri | (unsigned long) (tri2).orient); (tri2).tri[(tri2).orient] = (triangle) ((unsigned long) (tri1).tri | (unsigned long) (tri1).orient); (midtri).orient = plus1mod3[(midtri).orient]; (tri1).orient = minus1mod3[(tri1).orient]; (tri2).orient = plus1mod3[(tri2).orient]; (tri3).orient = minus1mod3[(tri3).orient]; (midtri).tri[(midtri).orient] = (triangle) ((unsigned long) (tri1).tri | (unsigned long) (tri1).orient); (tri1).tri[(tri1).orient] = (triangle) ((unsigned long) (midtri).tri | (unsigned long) (midtri).orient); (tri2).tri[(tri2).orient] = (triangle) ((unsigned long) (tri3).tri | (unsigned long) (tri3).orient); (tri3).tri[(tri3).orient] = (triangle) ((unsigned long) (tri2).tri | (unsigned long) (tri2).orient); (*farleft).tri = (tri1).tri; (*farleft).orient = (tri1).orient; (*farright).tri = (tri2).tri; (*farright).orient = (tri2).orient; } else { (midtri).tri[plus1mod3[(midtri).orient] + 3] = (triangle) sortarray[0]; (tri1).tri[minus1mod3[(tri1).orient] + 3] = (triangle) sortarray[0]; (tri3).tri[plus1mod3[(tri3).orient] + 3] = (triangle) sortarray[0]; if (area > 0.0) { (midtri).tri[minus1mod3[(midtri).orient] + 3] = (triangle) sortarray[1]; (tri1).tri[plus1mod3[(tri1).orient] + 3] = (triangle) sortarray[1]; (tri2).tri[minus1mod3[(tri2).orient] + 3] = (triangle) sortarray[1]; (midtri).tri[(midtri).orient + 3] = (triangle) sortarray[2]; (tri2).tri[plus1mod3[(tri2).orient] + 3] = (triangle) sortarray[2]; (tri3).tri[minus1mod3[(tri3).orient] + 3] = (triangle) sortarray[2]; } else { (midtri).tri[minus1mod3[(midtri).orient] + 3] = (triangle) sortarray[2]; (tri1).tri[plus1mod3[(tri1).orient] + 3] = (triangle) sortarray[2]; (tri2).tri[minus1mod3[(tri2).orient] + 3] = (triangle) sortarray[2]; (midtri).tri[(midtri).orient + 3] = (triangle) sortarray[1]; (tri2).tri[plus1mod3[(tri2).orient] + 3] = (triangle) sortarray[1]; (tri3).tri[minus1mod3[(tri3).orient] + 3] = (triangle) sortarray[1]; } (midtri).tri[(midtri).orient] = (triangle) ((unsigned long) (tri1).tri | (unsigned long) (tri1).orient); (tri1).tri[(tri1).orient] = (triangle) ((unsigned long) (midtri).tri | (unsigned long) (midtri).orient); (midtri).orient = plus1mod3[(midtri).orient]; (midtri).tri[(midtri).orient] = (triangle) ((unsigned long) (tri2).tri | (unsigned long) (tri2).orient); (tri2).tri[(tri2).orient] = (triangle) ((unsigned long) (midtri).tri | (unsigned long) (midtri).orient); (midtri).orient = plus1mod3[(midtri).orient]; (midtri).tri[(midtri).orient] = (triangle) ((unsigned long) (tri3).tri | (unsigned long) (tri3).orient); (tri3).tri[(tri3).orient] = (triangle) ((unsigned long) (midtri).tri | (unsigned long) (midtri).orient); (tri1).orient = minus1mod3[(tri1).orient]; (tri2).orient = plus1mod3[(tri2).orient]; (tri1).tri[(tri1).orient] = (triangle) ((unsigned long) (tri2).tri | (unsigned long) (tri2).orient); (tri2).tri[(tri2).orient] = (triangle) ((unsigned long) (tri1).tri | (unsigned long) (tri1).orient); (tri1).orient = minus1mod3[(tri1).orient]; (tri3).orient = minus1mod3[(tri3).orient]; (tri1).tri[(tri1).orient] = (triangle) ((unsigned long) (tri3).tri | (unsigned long) (tri3).orient); (tri3).tri[(tri3).orient] = (triangle) ((unsigned long) (tri1).tri | (unsigned long) (tri1).orient); (tri2).orient = plus1mod3[(tri2).orient]; (tri3).orient = minus1mod3[(tri3).orient]; (tri2).tri[(tri2).orient] = (triangle) ((unsigned long) (tri3).tri | (unsigned long) (tri3).orient); (tri3).tri[(tri3).orient] = (triangle) ((unsigned long) (tri2).tri | (unsigned long) (tri2).orient); (*farleft).tri = (tri1).tri; (*farleft).orient = (tri1).orient; if (area > 0.0) { (*farright).tri = (tri2).tri; (*farright).orient = (tri2).orient; } else { (*farright).tri = (*farleft).tri; (*farright).orient = plus1mod3[(*farleft).orient]; } } if (b->verbose > 2) { fprintf(stderr, " Creating "); printtriangle(m, b, &midtri); fprintf(stderr, " Creating "); printtriangle(m, b, &tri1); fprintf(stderr, " Creating "); printtriangle(m, b, &tri2); fprintf(stderr, " Creating "); printtriangle(m, b, &tri3); } return; } else { divider = vertices >> 1; divconqrecurse(m, b, sortarray, divider, 1 - axis, farleft, &innerleft); divconqrecurse(m, b, &sortarray[divider], vertices - divider, 1 - axis, &innerright, farright); if (b->verbose > 1) { fprintf(stderr, " Joining triangulations with %d and %d vertices.\n", divider, vertices - divider); } mergehulls(m, b, farleft, &innerleft, &innerright, farright, axis); } } long removeghosts(m, b, startghost) struct mesh *m; struct behavior *b; struct otri *startghost; { struct otri searchedge; struct otri dissolveedge; struct otri deadtriangle; vertex markorg; long hullsize; triangle ptr; if (b->verbose) { fprintf(stderr, " Removing ghost triangles.\n"); } (searchedge).tri = (*startghost).tri; (searchedge).orient = minus1mod3[(*startghost).orient]; ptr = (searchedge).tri[(searchedge).orient]; (searchedge).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (searchedge).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (searchedge).orient);; m->dummytri[0] = (triangle) ((unsigned long) (searchedge).tri | (unsigned long) (searchedge).orient); (dissolveedge).tri = (*startghost).tri; (dissolveedge).orient = (*startghost).orient; hullsize = 0; do { hullsize++; (deadtriangle).tri = (dissolveedge).tri; (deadtriangle).orient = plus1mod3[(dissolveedge).orient]; (dissolveedge).orient = minus1mod3[(dissolveedge).orient]; ptr = (dissolveedge).tri[(dissolveedge).orient]; (dissolveedge).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (dissolveedge).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (dissolveedge).orient);; if (!b->poly) { if (dissolveedge.tri != m->dummytri) { markorg = (vertex) (dissolveedge).tri[plus1mod3[(dissolveedge).orient] + 3]; if (((int *) (markorg))[m->vertexmarkindex] == 0) { ((int *) (markorg))[m->vertexmarkindex] = 1; } } } (dissolveedge).tri[(dissolveedge).orient] = (triangle) m->dummytri; ptr = (deadtriangle).tri[(deadtriangle).orient]; (dissolveedge).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (dissolveedge).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (dissolveedge).orient);; triangledealloc(m, deadtriangle.tri); } while (!(((dissolveedge).tri == (*startghost).tri) && ((dissolveedge).orient == (*startghost).orient))); return hullsize; } # 9936 "triangle.c" long divconqdelaunay(m, b) struct mesh *m; struct behavior *b; { vertex *sortarray; struct otri hullleft, hullright; int divider; int i, j; if (b->verbose) { fprintf(stderr, " Sorting vertices.\n"); } sortarray = (vertex *) trimalloc(m->invertices * sizeof(vertex)); traversalinit(&m->vertices); for (i = 0; i < m->invertices; i++) { sortarray[i] = vertextraverse(m); } vertexsort(sortarray, m->invertices); i = 0; for (j = 1; j < m->invertices; j++) { if ((sortarray[i][0] == sortarray[j][0]) && (sortarray[i][1] == sortarray[j][1])) { if (!b->quiet) { fprintf(stderr, "Warning: A duplicate vertex at (%.12g, %.12g) appeared and was ignored.\n", sortarray[j][0], sortarray[j][1]); } ((int *) (sortarray[j]))[m->vertexmarkindex + 1] = -32767; m->undeads++; } else { i++; sortarray[i] = sortarray[j]; } } i++; if (b->dwyer) { divider = i >> 1; if (i - divider >= 2) { if (divider >= 2) { alternateaxes(sortarray, divider, 1); } alternateaxes(&sortarray[divider], i - divider, 1); } } if (b->verbose) { fprintf(stderr, " Forming triangulation.\n"); } divconqrecurse(m, b, sortarray, i, 0, &hullleft, &hullright); trifree((int *) sortarray); return removeghosts(m, b, &hullleft); } # 10023 "triangle.c" void boundingbox(m, b) struct mesh *m; struct behavior *b; { struct otri inftri; double width; if (b->verbose) { fprintf(stderr, " Creating triangular bounding box.\n"); } width = m->xmax - m->xmin; if (m->ymax - m->ymin > width) { width = m->ymax - m->ymin; } if (width == 0.0) { width = 1.0; } m->infvertex1 = (vertex) trimalloc(m->vertices.itembytes); m->infvertex2 = (vertex) trimalloc(m->vertices.itembytes); m->infvertex3 = (vertex) trimalloc(m->vertices.itembytes); m->infvertex1[0] = m->xmin - 50.0 * width; m->infvertex1[1] = m->ymin - 40.0 * width; m->infvertex2[0] = m->xmax + 50.0 * width; m->infvertex2[1] = m->ymin - 40.0 * width; m->infvertex3[0] = 0.5 * (m->xmin + m->xmax); m->infvertex3[1] = m->ymax + 60.0 * width; maketriangle(m, b, &inftri); (inftri).tri[plus1mod3[(inftri).orient] + 3] = (triangle) m->infvertex1; (inftri).tri[minus1mod3[(inftri).orient] + 3] = (triangle) m->infvertex2; (inftri).tri[(inftri).orient + 3] = (triangle) m->infvertex3; m->dummytri[0] = (triangle) inftri.tri; if (b->verbose > 2) { fprintf(stderr, " Creating "); printtriangle(m, b, &inftri); } } # 10089 "triangle.c" long removebox(m, b) struct mesh *m; struct behavior *b; { struct otri deadtriangle; struct otri searchedge; struct otri checkedge; struct otri nextedge, finaledge, dissolveedge; vertex markorg; long hullsize; triangle ptr; if (b->verbose) { fprintf(stderr, " Removing triangular bounding box.\n"); } nextedge.tri = m->dummytri; nextedge.orient = 0; ptr = (nextedge).tri[(nextedge).orient]; (nextedge).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (nextedge).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (nextedge).orient);; (finaledge).tri = (nextedge).tri; (finaledge).orient = minus1mod3[(nextedge).orient]; (nextedge).orient = plus1mod3[(nextedge).orient]; ptr = (nextedge).tri[(nextedge).orient]; (nextedge).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (nextedge).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (nextedge).orient);; (searchedge).tri = (nextedge).tri; (searchedge).orient = minus1mod3[(nextedge).orient]; ptr = (searchedge).tri[(searchedge).orient]; (searchedge).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (searchedge).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (searchedge).orient);; (checkedge).tri = (nextedge).tri; (checkedge).orient = plus1mod3[(nextedge).orient]; ptr = (checkedge).tri[(checkedge).orient]; (checkedge).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (checkedge).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (checkedge).orient);; if (checkedge.tri == m->dummytri) { (searchedge).orient = minus1mod3[(searchedge).orient]; ptr = (searchedge).tri[(searchedge).orient]; (searchedge).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (searchedge).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (searchedge).orient);; } m->dummytri[0] = (triangle) ((unsigned long) (searchedge).tri | (unsigned long) (searchedge).orient); hullsize = -2l; while (!(((nextedge).tri == (finaledge).tri) && ((nextedge).orient == (finaledge).orient))) { hullsize++; (dissolveedge).tri = (nextedge).tri; (dissolveedge).orient = minus1mod3[(nextedge).orient]; ptr = (dissolveedge).tri[(dissolveedge).orient]; (dissolveedge).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (dissolveedge).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (dissolveedge).orient);; if (!b->poly) { if (dissolveedge.tri != m->dummytri) { markorg = (vertex) (dissolveedge).tri[plus1mod3[(dissolveedge).orient] + 3]; if (((int *) (markorg))[m->vertexmarkindex] == 0) { ((int *) (markorg))[m->vertexmarkindex] = 1; } } } (dissolveedge).tri[(dissolveedge).orient] = (triangle) m->dummytri; (deadtriangle).tri = (nextedge).tri; (deadtriangle).orient = plus1mod3[(nextedge).orient]; ptr = (deadtriangle).tri[(deadtriangle).orient]; (nextedge).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (nextedge).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (nextedge).orient);; triangledealloc(m, deadtriangle.tri); if (nextedge.tri == m->dummytri) { (nextedge).tri = (dissolveedge).tri; (nextedge).orient = (dissolveedge).orient; } } triangledealloc(m, finaledge.tri); trifree((int *) m->infvertex1); trifree((int *) m->infvertex2); trifree((int *) m->infvertex3); return hullsize; } # 10188 "triangle.c" long incrementaldelaunay(m, b) struct mesh *m; struct behavior *b; { struct otri starttri; vertex vertexloop; boundingbox(m, b); if (b->verbose) { fprintf(stderr, " Incrementally inserting vertices.\n"); } traversalinit(&m->vertices); vertexloop = vertextraverse(m); while (vertexloop != (vertex) ((void *)0)) { starttri.tri = m->dummytri; if (insertvertex(m, b, vertexloop, &starttri, (struct osub *) ((void *)0), 0, 0, 0.0) == DUPLICATEVERTEX) { if (!b->quiet) { fprintf(stderr, "Warning: A duplicate vertex at (%.12g, %.12g) appeared and was ignored.\n", vertexloop[0], vertexloop[1]); } ((int *) (vertexloop))[m->vertexmarkindex + 1] = -32767; m->undeads++; } vertexloop = vertextraverse(m); } return removebox(m, b); } # 10237 "triangle.c" void eventheapinsert(heap, heapsize, newevent) struct event **heap; int heapsize; struct event *newevent; { double eventx, eventy; int eventnum; int parent; int notdone; eventx = newevent->xkey; eventy = newevent->ykey; eventnum = heapsize; notdone = eventnum > 0; while (notdone) { parent = (eventnum - 1) >> 1; if ((heap[parent]->ykey < eventy) || ((heap[parent]->ykey == eventy) && (heap[parent]->xkey <= eventx))) { notdone = 0; } else { heap[eventnum] = heap[parent]; heap[eventnum]->heapposition = eventnum; eventnum = parent; notdone = eventnum > 0; } } heap[eventnum] = newevent; newevent->heapposition = eventnum; } # 10278 "triangle.c" void eventheapify(heap, heapsize, eventnum) struct event **heap; int heapsize; int eventnum; { struct event *thisevent; double eventx, eventy; int leftchild, rightchild; int smallest; int notdone; thisevent = heap[eventnum]; eventx = thisevent->xkey; eventy = thisevent->ykey; leftchild = 2 * eventnum + 1; notdone = leftchild < heapsize; while (notdone) { if ((heap[leftchild]->ykey < eventy) || ((heap[leftchild]->ykey == eventy) && (heap[leftchild]->xkey < eventx))) { smallest = leftchild; } else { smallest = eventnum; } rightchild = leftchild + 1; if (rightchild < heapsize) { if ((heap[rightchild]->ykey < heap[smallest]->ykey) || ((heap[rightchild]->ykey == heap[smallest]->ykey) && (heap[rightchild]->xkey < heap[smallest]->xkey))) { smallest = rightchild; } } if (smallest == eventnum) { notdone = 0; } else { heap[eventnum] = heap[smallest]; heap[eventnum]->heapposition = eventnum; heap[smallest] = thisevent; thisevent->heapposition = smallest; eventnum = smallest; leftchild = 2 * eventnum + 1; notdone = leftchild < heapsize; } } } # 10334 "triangle.c" void eventheapdelete(heap, heapsize, eventnum) struct event **heap; int heapsize; int eventnum; { struct event *moveevent; double eventx, eventy; int parent; int notdone; moveevent = heap[heapsize - 1]; if (eventnum > 0) { eventx = moveevent->xkey; eventy = moveevent->ykey; do { parent = (eventnum - 1) >> 1; if ((heap[parent]->ykey < eventy) || ((heap[parent]->ykey == eventy) && (heap[parent]->xkey <= eventx))) { notdone = 0; } else { heap[eventnum] = heap[parent]; heap[eventnum]->heapposition = eventnum; eventnum = parent; notdone = eventnum > 0; } } while (notdone); } heap[eventnum] = moveevent; moveevent->heapposition = eventnum; eventheapify(heap, heapsize - 1, eventnum); } # 10378 "triangle.c" void createeventheap(m, eventheap, events, freeevents) struct mesh *m; struct event ***eventheap; struct event **events; struct event **freeevents; { vertex thisvertex; int maxevents; int i; maxevents = (3 * m->invertices) / 2; *eventheap = (struct event **) trimalloc(maxevents * sizeof(struct event *)); *events = (struct event *) trimalloc(maxevents * sizeof(struct event)); traversalinit(&m->vertices); for (i = 0; i < m->invertices; i++) { thisvertex = vertextraverse(m); (*events)[i].eventptr = (int *) thisvertex; (*events)[i].xkey = thisvertex[0]; (*events)[i].ykey = thisvertex[1]; eventheapinsert(*eventheap, i, *events + i); } *freeevents = (struct event *) ((void *)0); for (i = maxevents - 1; i >= m->invertices; i--) { (*events)[i].eventptr = (int *) *freeevents; *freeevents = *events + i; } } # 10415 "triangle.c" int rightofhyperbola(m, fronttri, newsite) struct mesh *m; struct otri *fronttri; vertex newsite; { vertex leftvertex, rightvertex; double dxa, dya, dxb, dyb; m->hyperbolacount++; leftvertex = (vertex) (*fronttri).tri[minus1mod3[(*fronttri).orient] + 3]; rightvertex = (vertex) (*fronttri).tri[(*fronttri).orient + 3]; if ((leftvertex[1] < rightvertex[1]) || ((leftvertex[1] == rightvertex[1]) && (leftvertex[0] < rightvertex[0]))) { if (newsite[0] >= rightvertex[0]) { return 1; } } else { if (newsite[0] <= leftvertex[0]) { return 0; } } dxa = leftvertex[0] - newsite[0]; dya = leftvertex[1] - newsite[1]; dxb = rightvertex[0] - newsite[0]; dyb = rightvertex[1] - newsite[1]; return dya * (dxb * dxb + dyb * dyb) > dyb * (dxa * dxa + dya * dya); } # 10454 "triangle.c" double circletop(m, pa, pb, pc, ccwabc) struct mesh *m; vertex pa; vertex pb; vertex pc; double ccwabc; { double xac, yac, xbc, ybc, xab, yab; double aclen2, bclen2, ablen2; m->circletopcount++; xac = pa[0] - pc[0]; yac = pa[1] - pc[1]; xbc = pb[0] - pc[0]; ybc = pb[1] - pc[1]; xab = pa[0] - pb[0]; yab = pa[1] - pb[1]; aclen2 = xac * xac + yac * yac; bclen2 = xbc * xbc + ybc * ybc; ablen2 = xab * xab + yab * yab; return pc[1] + (xac * bclen2 - xbc * aclen2 + sqrt(aclen2 * bclen2 * ablen2)) / (2.0 * ccwabc); } # 10489 "triangle.c" void check4deadevent(checktri, freeevents, eventheap, heapsize) struct otri *checktri; struct event **freeevents; struct event **eventheap; int *heapsize; { struct event *deadevent; vertex eventvertex; int eventnum; eventvertex = (vertex) (*checktri).tri[plus1mod3[(*checktri).orient] + 3]; if (eventvertex != (vertex) ((void *)0)) { deadevent = (struct event *) eventvertex; eventnum = deadevent->heapposition; deadevent->eventptr = (int *) *freeevents; *freeevents = deadevent; eventheapdelete(eventheap, *heapsize, eventnum); (*heapsize)--; (*checktri).tri[plus1mod3[(*checktri).orient] + 3] = (triangle) ((void *)0); } } # 10521 "triangle.c" struct splaynode *splay(m, splaytree, searchpoint, searchtri) struct mesh *m; struct splaynode *splaytree; vertex searchpoint; struct otri *searchtri; { struct splaynode *child, *grandchild; struct splaynode *lefttree, *righttree; struct splaynode *leftright; vertex checkvertex; int rightofroot, rightofchild; if (splaytree == (struct splaynode *) ((void *)0)) { return (struct splaynode *) ((void *)0); } checkvertex = (vertex) (splaytree->keyedge).tri[minus1mod3[(splaytree->keyedge).orient] + 3]; if (checkvertex == splaytree->keydest) { rightofroot = rightofhyperbola(m, &splaytree->keyedge, searchpoint); if (rightofroot) { (*searchtri).tri = (splaytree->keyedge).tri; (*searchtri).orient = (splaytree->keyedge).orient; child = splaytree->rchild; } else { child = splaytree->lchild; } if (child == (struct splaynode *) ((void *)0)) { return splaytree; } checkvertex = (vertex) (child->keyedge).tri[minus1mod3[(child->keyedge).orient] + 3]; if (checkvertex != child->keydest) { child = splay(m, child, searchpoint, searchtri); if (child == (struct splaynode *) ((void *)0)) { if (rightofroot) { splaytree->rchild = (struct splaynode *) ((void *)0); } else { splaytree->lchild = (struct splaynode *) ((void *)0); } return splaytree; } } rightofchild = rightofhyperbola(m, &child->keyedge, searchpoint); if (rightofchild) { (*searchtri).tri = (child->keyedge).tri; (*searchtri).orient = (child->keyedge).orient; grandchild = splay(m, child->rchild, searchpoint, searchtri); child->rchild = grandchild; } else { grandchild = splay(m, child->lchild, searchpoint, searchtri); child->lchild = grandchild; } if (grandchild == (struct splaynode *) ((void *)0)) { if (rightofroot) { splaytree->rchild = child->lchild; child->lchild = splaytree; } else { splaytree->lchild = child->rchild; child->rchild = splaytree; } return child; } if (rightofchild) { if (rightofroot) { splaytree->rchild = child->lchild; child->lchild = splaytree; } else { splaytree->lchild = grandchild->rchild; grandchild->rchild = splaytree; } child->rchild = grandchild->lchild; grandchild->lchild = child; } else { if (rightofroot) { splaytree->rchild = grandchild->lchild; grandchild->lchild = splaytree; } else { splaytree->lchild = child->rchild; child->rchild = splaytree; } child->lchild = grandchild->rchild; grandchild->rchild = child; } return grandchild; } else { lefttree = splay(m, splaytree->lchild, searchpoint, searchtri); righttree = splay(m, splaytree->rchild, searchpoint, searchtri); pooldealloc(&m->splaynodes, (int *) splaytree); if (lefttree == (struct splaynode *) ((void *)0)) { return righttree; } else if (righttree == (struct splaynode *) ((void *)0)) { return lefttree; } else if (lefttree->rchild == (struct splaynode *) ((void *)0)) { lefttree->rchild = righttree->lchild; righttree->lchild = lefttree; return righttree; } else if (righttree->lchild == (struct splaynode *) ((void *)0)) { righttree->lchild = lefttree->rchild; lefttree->rchild = righttree; return lefttree; } else { leftright = lefttree->rchild; while (leftright->rchild != (struct splaynode *) ((void *)0)) { leftright = leftright->rchild; } leftright->rchild = righttree; return lefttree; } } } # 10640 "triangle.c" struct splaynode *splayinsert(m, splayroot, newkey, searchpoint) struct mesh *m; struct splaynode *splayroot; struct otri *newkey; vertex searchpoint; { struct splaynode *newsplaynode; newsplaynode = (struct splaynode *) poolalloc(&m->splaynodes); (newsplaynode->keyedge).tri = (*newkey).tri; (newsplaynode->keyedge).orient = (*newkey).orient; newsplaynode->keydest = (vertex) (*newkey).tri[minus1mod3[(*newkey).orient] + 3]; if (splayroot == (struct splaynode *) ((void *)0)) { newsplaynode->lchild = (struct splaynode *) ((void *)0); newsplaynode->rchild = (struct splaynode *) ((void *)0); } else if (rightofhyperbola(m, &splayroot->keyedge, searchpoint)) { newsplaynode->lchild = splayroot; newsplaynode->rchild = splayroot->rchild; splayroot->rchild = (struct splaynode *) ((void *)0); } else { newsplaynode->lchild = splayroot->lchild; newsplaynode->rchild = splayroot; splayroot->lchild = (struct splaynode *) ((void *)0); } return newsplaynode; } # 10678 "triangle.c" struct splaynode *circletopinsert(m, b, splayroot, newkey, pa, pb, pc, topy) struct mesh *m; struct behavior *b; struct splaynode *splayroot; struct otri *newkey; vertex pa; vertex pb; vertex pc; double topy; { double ccwabc; double xac, yac, xbc, ybc; double aclen2, bclen2; double searchpoint[2]; struct otri dummytri; ccwabc = counterclockwise(m, b, pa, pb, pc); xac = pa[0] - pc[0]; yac = pa[1] - pc[1]; xbc = pb[0] - pc[0]; ybc = pb[1] - pc[1]; aclen2 = xac * xac + yac * yac; bclen2 = xbc * xbc + ybc * ybc; searchpoint[0] = pc[0] - (yac * bclen2 - ybc * aclen2) / (2.0 * ccwabc); searchpoint[1] = topy; return splayinsert(m, splay(m, splayroot, (vertex) searchpoint, &dummytri), newkey, (vertex) searchpoint); } # 10718 "triangle.c" struct splaynode *frontlocate(m, splayroot, bottommost, searchvertex, searchtri, farright) struct mesh *m; struct splaynode *splayroot; struct otri *bottommost; vertex searchvertex; struct otri *searchtri; int *farright; { int farrightflag; triangle ptr; (*searchtri).tri = (*bottommost).tri; (*searchtri).orient = (*bottommost).orient; splayroot = splay(m, splayroot, searchvertex, searchtri); farrightflag = 0; while (!farrightflag && rightofhyperbola(m, searchtri, searchvertex)) { (*searchtri).orient = minus1mod3[(*searchtri).orient]; ptr = (*searchtri).tri[(*searchtri).orient]; (*searchtri).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (*searchtri).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (*searchtri).orient);;; farrightflag = (((*searchtri).tri == (*bottommost).tri) && ((*searchtri).orient == (*bottommost).orient)); } *farright = farrightflag; return splayroot; } # 10751 "triangle.c" long sweeplinedelaunay(m, b) struct mesh *m; struct behavior *b; { struct event **eventheap; struct event *events; struct event *freeevents; struct event *nextevent; struct event *newevent; struct splaynode *splayroot; struct otri bottommost; struct otri searchtri; struct otri fliptri; struct otri lefttri, righttri, farlefttri, farrighttri; struct otri inserttri; vertex firstvertex, secondvertex; vertex nextvertex, lastvertex; vertex connectvertex; vertex leftvertex, midvertex, rightvertex; double lefttest, righttest; int heapsize; int check4events, farrightflag; triangle ptr; poolinit(&m->splaynodes, sizeof(struct splaynode), 508, POINTER, 0); splayroot = (struct splaynode *) ((void *)0); if (b->verbose) { fprintf(stderr, " Placing vertices in event heap.\n"); } createeventheap(m, &eventheap, &events, &freeevents); heapsize = m->invertices; if (b->verbose) { fprintf(stderr, " Forming triangulation.\n"); } maketriangle(m, b, &lefttri); maketriangle(m, b, &righttri); (lefttri).tri[(lefttri).orient] = (triangle) ((unsigned long) (righttri).tri | (unsigned long) (righttri).orient); (righttri).tri[(righttri).orient] = (triangle) ((unsigned long) (lefttri).tri | (unsigned long) (lefttri).orient); (lefttri).orient = plus1mod3[(lefttri).orient]; (righttri).orient = minus1mod3[(righttri).orient]; (lefttri).tri[(lefttri).orient] = (triangle) ((unsigned long) (righttri).tri | (unsigned long) (righttri).orient); (righttri).tri[(righttri).orient] = (triangle) ((unsigned long) (lefttri).tri | (unsigned long) (lefttri).orient); (lefttri).orient = plus1mod3[(lefttri).orient]; (righttri).orient = minus1mod3[(righttri).orient]; (lefttri).tri[(lefttri).orient] = (triangle) ((unsigned long) (righttri).tri | (unsigned long) (righttri).orient); (righttri).tri[(righttri).orient] = (triangle) ((unsigned long) (lefttri).tri | (unsigned long) (lefttri).orient); firstvertex = (vertex) eventheap[0]->eventptr; eventheap[0]->eventptr = (int *) freeevents; freeevents = eventheap[0]; eventheapdelete(eventheap, heapsize, 0); heapsize--; do { if (heapsize == 0) { fprintf(stderr, "Error: Input vertices are all identical.\n"); exit(1); } secondvertex = (vertex) eventheap[0]->eventptr; eventheap[0]->eventptr = (int *) freeevents; freeevents = eventheap[0]; eventheapdelete(eventheap, heapsize, 0); heapsize--; if ((firstvertex[0] == secondvertex[0]) && (firstvertex[1] == secondvertex[1])) { if (!b->quiet) { fprintf(stderr, "Warning: A duplicate vertex at (%.12g, %.12g) appeared and was ignored.\n", secondvertex[0], secondvertex[1]); } ((int *) (secondvertex))[m->vertexmarkindex + 1] = -32767; m->undeads++; } } while ((firstvertex[0] == secondvertex[0]) && (firstvertex[1] == secondvertex[1])); (lefttri).tri[plus1mod3[(lefttri).orient] + 3] = (triangle) firstvertex; (lefttri).tri[minus1mod3[(lefttri).orient] + 3] = (triangle) secondvertex; (righttri).tri[plus1mod3[(righttri).orient] + 3] = (triangle) secondvertex; (righttri).tri[minus1mod3[(righttri).orient] + 3] = (triangle) firstvertex; (bottommost).tri = (lefttri).tri; (bottommost).orient = minus1mod3[(lefttri).orient]; lastvertex = secondvertex; while (heapsize > 0) { nextevent = eventheap[0]; eventheapdelete(eventheap, heapsize, 0); heapsize--; check4events = 1; if (nextevent->xkey < m->xmin) { (fliptri).orient = (int) ((unsigned long) (nextevent->eventptr) & (unsigned long) 3l); (fliptri).tri = (triangle *) ((unsigned long) (nextevent->eventptr) ^ (unsigned long) (fliptri).orient); ptr = (fliptri).tri[(fliptri).orient]; (farlefttri).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (farlefttri).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (farlefttri).orient);; (farlefttri).orient = plus1mod3[(farlefttri).orient];; check4deadevent(&farlefttri, &freeevents, eventheap, &heapsize); (farrighttri).tri = (fliptri).tri; (farrighttri).orient = minus1mod3[(fliptri).orient]; ptr = (farrighttri).tri[(farrighttri).orient]; (farrighttri).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (farrighttri).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (farrighttri).orient);;; check4deadevent(&farrighttri, &freeevents, eventheap, &heapsize); if ((((farlefttri).tri == (bottommost).tri) && ((farlefttri).orient == (bottommost).orient))) { (bottommost).tri = (fliptri).tri; (bottommost).orient = minus1mod3[(fliptri).orient]; } flip(m, b, &fliptri); (fliptri).tri[(fliptri).orient + 3] = (triangle) ((void *)0); (lefttri).tri = (fliptri).tri; (lefttri).orient = minus1mod3[(fliptri).orient]; (righttri).tri = (fliptri).tri; (righttri).orient = plus1mod3[(fliptri).orient]; ptr = (lefttri).tri[(lefttri).orient]; (farlefttri).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (farlefttri).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (farlefttri).orient);; if (randomnation(10) == 0) { ptr = (fliptri).tri[(fliptri).orient]; (fliptri).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (fliptri).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (fliptri).orient);; leftvertex = (vertex) (fliptri).tri[minus1mod3[(fliptri).orient] + 3]; midvertex = (vertex) (fliptri).tri[(fliptri).orient + 3]; rightvertex = (vertex) (fliptri).tri[plus1mod3[(fliptri).orient] + 3]; splayroot = circletopinsert(m, b, splayroot, &lefttri, leftvertex, midvertex, rightvertex, nextevent->ykey); } } else { nextvertex = (vertex) nextevent->eventptr; if ((nextvertex[0] == lastvertex[0]) && (nextvertex[1] == lastvertex[1])) { if (!b->quiet) { fprintf(stderr, "Warning: A duplicate vertex at (%.12g, %.12g) appeared and was ignored.\n", nextvertex[0], nextvertex[1]); } ((int *) (nextvertex))[m->vertexmarkindex + 1] = -32767; m->undeads++; check4events = 0; } else { lastvertex = nextvertex; splayroot = frontlocate(m, splayroot, &bottommost, nextvertex, &searchtri, &farrightflag); # 10887 "triangle.c" check4deadevent(&searchtri, &freeevents, eventheap, &heapsize); (farrighttri).tri = (searchtri).tri; (farrighttri).orient = (searchtri).orient; ptr = (searchtri).tri[(searchtri).orient]; (farlefttri).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (farlefttri).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (farlefttri).orient);; maketriangle(m, b, &lefttri); maketriangle(m, b, &righttri); connectvertex = (vertex) (farrighttri).tri[minus1mod3[(farrighttri).orient] + 3]; (lefttri).tri[plus1mod3[(lefttri).orient] + 3] = (triangle) connectvertex; (lefttri).tri[minus1mod3[(lefttri).orient] + 3] = (triangle) nextvertex; (righttri).tri[plus1mod3[(righttri).orient] + 3] = (triangle) nextvertex; (righttri).tri[minus1mod3[(righttri).orient] + 3] = (triangle) connectvertex; (lefttri).tri[(lefttri).orient] = (triangle) ((unsigned long) (righttri).tri | (unsigned long) (righttri).orient); (righttri).tri[(righttri).orient] = (triangle) ((unsigned long) (lefttri).tri | (unsigned long) (lefttri).orient); (lefttri).orient = plus1mod3[(lefttri).orient]; (righttri).orient = minus1mod3[(righttri).orient]; (lefttri).tri[(lefttri).orient] = (triangle) ((unsigned long) (righttri).tri | (unsigned long) (righttri).orient); (righttri).tri[(righttri).orient] = (triangle) ((unsigned long) (lefttri).tri | (unsigned long) (lefttri).orient); (lefttri).orient = plus1mod3[(lefttri).orient]; (righttri).orient = minus1mod3[(righttri).orient]; (lefttri).tri[(lefttri).orient] = (triangle) ((unsigned long) (farlefttri).tri | (unsigned long) (farlefttri).orient); (farlefttri).tri[(farlefttri).orient] = (triangle) ((unsigned long) (lefttri).tri | (unsigned long) (lefttri).orient); (righttri).tri[(righttri).orient] = (triangle) ((unsigned long) (farrighttri).tri | (unsigned long) (farrighttri).orient); (farrighttri).tri[(farrighttri).orient] = (triangle) ((unsigned long) (righttri).tri | (unsigned long) (righttri).orient); if (!farrightflag && (((farrighttri).tri == (bottommost).tri) && ((farrighttri).orient == (bottommost).orient))) { (bottommost).tri = (lefttri).tri; (bottommost).orient = (lefttri).orient; } if (randomnation(10) == 0) { splayroot = splayinsert(m, splayroot, &lefttri, nextvertex); } else if (randomnation(10) == 0) { (inserttri).tri = (righttri).tri; (inserttri).orient = plus1mod3[(righttri).orient]; splayroot = splayinsert(m, splayroot, &inserttri, nextvertex); } } } nextevent->eventptr = (int *) freeevents; freeevents = nextevent; if (check4events) { leftvertex = (vertex) (farlefttri).tri[(farlefttri).orient + 3]; midvertex = (vertex) (lefttri).tri[minus1mod3[(lefttri).orient] + 3]; rightvertex = (vertex) (lefttri).tri[(lefttri).orient + 3]; lefttest = counterclockwise(m, b, leftvertex, midvertex, rightvertex); if (lefttest > 0.0) { newevent = freeevents; freeevents = (struct event *) freeevents->eventptr; newevent->xkey = m->xminextreme; newevent->ykey = circletop(m, leftvertex, midvertex, rightvertex, lefttest); newevent->eventptr = (int *) (triangle) ((unsigned long) (lefttri).tri | (unsigned long) (lefttri).orient); eventheapinsert(eventheap, heapsize, newevent); heapsize++; (lefttri).tri[plus1mod3[(lefttri).orient] + 3] = (triangle) newevent; } leftvertex = (vertex) (righttri).tri[(righttri).orient + 3]; midvertex = (vertex) (righttri).tri[plus1mod3[(righttri).orient] + 3]; rightvertex = (vertex) (farrighttri).tri[(farrighttri).orient + 3]; righttest = counterclockwise(m, b, leftvertex, midvertex, rightvertex); if (righttest > 0.0) { newevent = freeevents; freeevents = (struct event *) freeevents->eventptr; newevent->xkey = m->xminextreme; newevent->ykey = circletop(m, leftvertex, midvertex, rightvertex, righttest); newevent->eventptr = (int *) (triangle) ((unsigned long) (farrighttri).tri | (unsigned long) (farrighttri).orient); eventheapinsert(eventheap, heapsize, newevent); heapsize++; (farrighttri).tri[plus1mod3[(farrighttri).orient] + 3] = (triangle) newevent; } } } pooldeinit(&m->splaynodes); (bottommost).orient = minus1mod3[(bottommost).orient]; return removeghosts(m, b, &bottommost); } # 10979 "triangle.c" long delaunay(m, b) struct mesh *m; struct behavior *b; { long hulledges; m->eextras = 0; initializetrisubpools(m, b); # 10997 "triangle.c" if (!b->quiet) { fprintf(stderr, "Constructing Delaunay triangulation "); if (b->incremental) { fprintf(stderr, "by incremental method.\n"); } else if (b->sweepline) { fprintf(stderr, "by sweepline method.\n"); } else { fprintf(stderr, "by divide-and-conquer method.\n"); } } if (b->incremental) { hulledges = incrementaldelaunay(m, b); } else if (b->sweepline) { hulledges = sweeplinedelaunay(m, b); } else { hulledges = divconqdelaunay(m, b); } if (m->triangles.items == 0) { return 0l; } else { return hulledges; } } # 11059 "triangle.c" int reconstruct(m, b, trianglelist, triangleattriblist, trianglearealist, elements, corners, attribs, segmentlist, segmentmarkerlist, numberofsegments) struct mesh *m; struct behavior *b; int *trianglelist; double *triangleattriblist; double *trianglearealist; int elements; int corners; int attribs; int *segmentlist; int *segmentmarkerlist; int numberofsegments; # 11092 "triangle.c" { int vertexindex; int attribindex; struct otri triangleloop; struct otri triangleleft; struct otri checktri; struct otri checkleft; struct otri checkneighbor; struct osub subsegloop; triangle *vertexarray; triangle *prevlink; triangle nexttri; vertex tdest, tapex; vertex checkdest, checkapex; vertex shorg; vertex killvertex; double area; int corner[3]; int end[2]; int killvertexindex; int incorners; int segmentmarkers; int boundmarker; int aroundvertex; long hullsize; int notfound; long elementnumber, segmentnumber; int i, j; triangle ptr; m->inelements = elements; incorners = corners; if (incorners < 3) { fprintf(stderr, "Error: Triangles must have at least 3 vertices.\n"); exit(1); } m->eextras = attribs; # 11171 "triangle.c" initializetrisubpools(m, b); for (elementnumber = 1; elementnumber <= m->inelements; elementnumber++) { maketriangle(m, b, &triangleloop); triangleloop.tri[3] = (triangle) triangleloop.tri; } if (b->poly) { m->insegments = numberofsegments; segmentmarkers = segmentmarkerlist != (int *) ((void *)0); # 11198 "triangle.c" for (segmentnumber = 1; segmentnumber <= m->insegments; segmentnumber++) { makesubseg(m, &subsegloop); subsegloop.ss[2] = (subseg) subsegloop.ss; } } vertexindex = 0; attribindex = 0; # 11229 "triangle.c" if (!b->quiet) { fprintf(stderr, "Reconstructing mesh.\n"); } vertexarray = (triangle *) trimalloc(m->vertices.items * sizeof(triangle)); for (i = 0; i < m->vertices.items; i++) { vertexarray[i] = (triangle) m->dummytri; } if (b->verbose) { fprintf(stderr, " Assembling triangles.\n"); } traversalinit(&m->triangles); triangleloop.tri = triangletraverse(m); elementnumber = b->firstnumber; while (triangleloop.tri != (triangle *) ((void *)0)) { for (j = 0; j < 3; j++) { corner[j] = trianglelist[vertexindex++]; if ((corner[j] < b->firstnumber) || (corner[j] >= b->firstnumber + m->invertices)) { fprintf(stderr, "Error: Triangle %ld has an invalid vertex index.\n", elementnumber); exit(1); } } # 11283 "triangle.c" for (j = 3; j < incorners; j++) { killvertexindex = trianglelist[vertexindex++]; if ((killvertexindex >= b->firstnumber) && (killvertexindex < b->firstnumber + m->invertices)) { killvertex = getvertex(m, b, killvertexindex); if (((int *) (killvertex))[m->vertexmarkindex + 1] != -32768) { vertexdealloc(m, killvertex); } } } for (j = 0; j < m->eextras; j++) { ((double *) (triangleloop).tri)[m->elemattribindex + (j)] = triangleattriblist[attribindex++]; # 11317 "triangle.c" } if (b->vararea) { area = trianglearealist[elementnumber - b->firstnumber]; # 11332 "triangle.c" ((double *) (triangleloop).tri)[m->areaboundindex] = area; } triangleloop.orient = 0; (triangleloop).tri[plus1mod3[(triangleloop).orient] + 3] = (triangle) getvertex(m, b, corner[0]); (triangleloop).tri[minus1mod3[(triangleloop).orient] + 3] = (triangle) getvertex(m, b, corner[1]); (triangleloop).tri[(triangleloop).orient + 3] = (triangle) getvertex(m, b, corner[2]); for (triangleloop.orient = 0; triangleloop.orient < 3; triangleloop.orient++) { aroundvertex = corner[triangleloop.orient]; nexttri = vertexarray[aroundvertex - b->firstnumber]; triangleloop.tri[6 + triangleloop.orient] = nexttri; vertexarray[aroundvertex - b->firstnumber] = (triangle) ((unsigned long) (triangleloop).tri | (unsigned long) (triangleloop).orient); (checktri).orient = (int) ((unsigned long) (nexttri) & (unsigned long) 3l); (checktri).tri = (triangle *) ((unsigned long) (nexttri) ^ (unsigned long) (checktri).orient); if (checktri.tri != m->dummytri) { tdest = (vertex) (triangleloop).tri[minus1mod3[(triangleloop).orient] + 3]; tapex = (vertex) (triangleloop).tri[(triangleloop).orient + 3]; do { checkdest = (vertex) (checktri).tri[minus1mod3[(checktri).orient] + 3]; checkapex = (vertex) (checktri).tri[(checktri).orient + 3]; if (tapex == checkdest) { (triangleleft).tri = (triangleloop).tri; (triangleleft).orient = minus1mod3[(triangleloop).orient]; (triangleleft).tri[(triangleleft).orient] = (triangle) ((unsigned long) (checktri).tri | (unsigned long) (checktri).orient); (checktri).tri[(checktri).orient] = (triangle) ((unsigned long) (triangleleft).tri | (unsigned long) (triangleleft).orient); } if (tdest == checkapex) { (checkleft).tri = (checktri).tri; (checkleft).orient = minus1mod3[(checktri).orient]; (triangleloop).tri[(triangleloop).orient] = (triangle) ((unsigned long) (checkleft).tri | (unsigned long) (checkleft).orient); (checkleft).tri[(checkleft).orient] = (triangle) ((unsigned long) (triangleloop).tri | (unsigned long) (triangleloop).orient); } nexttri = checktri.tri[6 + checktri.orient]; (checktri).orient = (int) ((unsigned long) (nexttri) & (unsigned long) 3l); (checktri).tri = (triangle *) ((unsigned long) (nexttri) ^ (unsigned long) (checktri).orient); } while (checktri.tri != m->dummytri); } } triangleloop.tri = triangletraverse(m); elementnumber++; } vertexindex = 0; hullsize = 0; if (b->poly) { if (b->verbose) { fprintf(stderr, " Marking segments in triangulation.\n"); } boundmarker = 0; traversalinit(&m->subsegs); subsegloop.ss = subsegtraverse(m); segmentnumber = b->firstnumber; while (subsegloop.ss != (subseg *) ((void *)0)) { end[0] = segmentlist[vertexindex++]; end[1] = segmentlist[vertexindex++]; if (segmentmarkers) { boundmarker = segmentmarkerlist[segmentnumber - b->firstnumber]; } # 11435 "triangle.c" for (j = 0; j < 2; j++) { if ((end[j] < b->firstnumber) || (end[j] >= b->firstnumber + m->invertices)) { fprintf(stderr, "Error: Segment %ld has an invalid vertex index.\n", segmentnumber); exit(1); } } subsegloop.ssorient = 0; (subsegloop).ss[2 + (subsegloop).ssorient] = (subseg) getvertex(m, b, end[0]); (subsegloop).ss[3 - (subsegloop).ssorient] = (subseg) getvertex(m, b, end[1]); * (int *) ((subsegloop).ss + 6) = boundmarker; for (subsegloop.ssorient = 0; subsegloop.ssorient < 2; subsegloop.ssorient++) { aroundvertex = end[1 - subsegloop.ssorient]; prevlink = &vertexarray[aroundvertex - b->firstnumber]; nexttri = vertexarray[aroundvertex - b->firstnumber]; (checktri).orient = (int) ((unsigned long) (nexttri) & (unsigned long) 3l); (checktri).tri = (triangle *) ((unsigned long) (nexttri) ^ (unsigned long) (checktri).orient); shorg = (vertex) (subsegloop).ss[2 + (subsegloop).ssorient]; notfound = 1; while (notfound && (checktri.tri != m->dummytri)) { checkdest = (vertex) (checktri).tri[minus1mod3[(checktri).orient] + 3]; if (shorg == checkdest) { *prevlink = checktri.tri[6 + checktri.orient]; (checktri).tri[6 + (checktri).orient] = (triangle) (subseg) ((unsigned long) (subsegloop).ss | (unsigned long) (subsegloop).ssorient); (subsegloop).ss[4 + (subsegloop).ssorient] = (subseg) (triangle) ((unsigned long) (checktri).tri | (unsigned long) (checktri).orient); ptr = (checktri).tri[(checktri).orient]; (checkneighbor).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (checkneighbor).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (checkneighbor).orient);; if (checkneighbor.tri == m->dummytri) { insertsubseg(m, b, &checktri, 1); hullsize++; } notfound = 0; } prevlink = &checktri.tri[6 + checktri.orient]; nexttri = checktri.tri[6 + checktri.orient]; (checktri).orient = (int) ((unsigned long) (nexttri) & (unsigned long) 3l); (checktri).tri = (triangle *) ((unsigned long) (nexttri) ^ (unsigned long) (checktri).orient); } } subsegloop.ss = subsegtraverse(m); segmentnumber++; } } for (i = 0; i < m->vertices.items; i++) { nexttri = vertexarray[i]; (checktri).orient = (int) ((unsigned long) (nexttri) & (unsigned long) 3l); (checktri).tri = (triangle *) ((unsigned long) (nexttri) ^ (unsigned long) (checktri).orient); while (checktri.tri != m->dummytri) { nexttri = checktri.tri[6 + checktri.orient]; (checktri).tri[6 + (checktri).orient] = (triangle) m->dummysub; ptr = (checktri).tri[(checktri).orient]; (checkneighbor).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (checkneighbor).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (checkneighbor).orient);; if (checkneighbor.tri == m->dummytri) { insertsubseg(m, b, &checktri, 1); hullsize++; } (checktri).orient = (int) ((unsigned long) (nexttri) & (unsigned long) 3l); (checktri).tri = (triangle *) ((unsigned long) (nexttri) ^ (unsigned long) (checktri).orient); } } trifree((int *) vertexarray); return hullsize; } # 11553 "triangle.c" enum finddirectionresult finddirection(m, b, searchtri, searchpoint) struct mesh *m; struct behavior *b; struct otri *searchtri; vertex searchpoint; { struct otri checktri; vertex startvertex; vertex leftvertex, rightvertex; double leftccw, rightccw; int leftflag, rightflag; triangle ptr; startvertex = (vertex) (*searchtri).tri[plus1mod3[(*searchtri).orient] + 3]; rightvertex = (vertex) (*searchtri).tri[minus1mod3[(*searchtri).orient] + 3]; leftvertex = (vertex) (*searchtri).tri[(*searchtri).orient + 3]; leftccw = counterclockwise(m, b, searchpoint, startvertex, leftvertex); leftflag = leftccw > 0.0; rightccw = counterclockwise(m, b, startvertex, searchpoint, rightvertex); rightflag = rightccw > 0.0; if (leftflag && rightflag) { (checktri).tri = (*searchtri).tri; (checktri).orient = minus1mod3[(*searchtri).orient]; ptr = (checktri).tri[(checktri).orient]; (checktri).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (checktri).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (checktri).orient);;; if (checktri.tri == m->dummytri) { leftflag = 0; } else { rightflag = 0; } } while (leftflag) { (*searchtri).orient = minus1mod3[(*searchtri).orient]; ptr = (*searchtri).tri[(*searchtri).orient]; (*searchtri).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (*searchtri).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (*searchtri).orient);;; if (searchtri->tri == m->dummytri) { fprintf(stderr, "Internal error in finddirection(): Unable to find a\n"); fprintf(stderr, " triangle leading from (%.12g, %.12g) to", startvertex[0], startvertex[1]); fprintf(stderr, " (%.12g, %.12g).\n", searchpoint[0], searchpoint[1]); internalerror(); } leftvertex = (vertex) (*searchtri).tri[(*searchtri).orient + 3]; rightccw = leftccw; leftccw = counterclockwise(m, b, searchpoint, startvertex, leftvertex); leftflag = leftccw > 0.0; } while (rightflag) { ptr = (*searchtri).tri[(*searchtri).orient]; (*searchtri).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (*searchtri).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (*searchtri).orient);; (*searchtri).orient = plus1mod3[(*searchtri).orient];; if (searchtri->tri == m->dummytri) { fprintf(stderr, "Internal error in finddirection(): Unable to find a\n"); fprintf(stderr, " triangle leading from (%.12g, %.12g) to", startvertex[0], startvertex[1]); fprintf(stderr, " (%.12g, %.12g).\n", searchpoint[0], searchpoint[1]); internalerror(); } rightvertex = (vertex) (*searchtri).tri[minus1mod3[(*searchtri).orient] + 3]; leftccw = rightccw; rightccw = counterclockwise(m, b, startvertex, searchpoint, rightvertex); rightflag = rightccw > 0.0; } if (leftccw == 0.0) { return LEFTCOLLINEAR; } else if (rightccw == 0.0) { return RIGHTCOLLINEAR; } else { return WITHIN; } } # 11648 "triangle.c" void segmentintersection(m, b, splittri, splitsubseg, endpoint2) struct mesh *m; struct behavior *b; struct otri *splittri; struct osub *splitsubseg; vertex endpoint2; { vertex endpoint1; vertex torg, tdest; vertex leftvertex, rightvertex; vertex newvertex; enum insertvertexresult success; enum finddirectionresult collinear; double ex, ey; double tx, ty; double etx, ety; double split, denom; int i; triangle ptr; endpoint1 = (vertex) (*splittri).tri[(*splittri).orient + 3]; torg = (vertex) (*splittri).tri[plus1mod3[(*splittri).orient] + 3]; tdest = (vertex) (*splittri).tri[minus1mod3[(*splittri).orient] + 3]; tx = tdest[0] - torg[0]; ty = tdest[1] - torg[1]; ex = endpoint2[0] - endpoint1[0]; ey = endpoint2[1] - endpoint1[1]; etx = torg[0] - endpoint2[0]; ety = torg[1] - endpoint2[1]; denom = ty * ex - tx * ey; if (denom == 0.0) { fprintf(stderr, "Internal error in segmentintersection():"); fprintf(stderr, " Attempt to find intersection of parallel segments.\n"); internalerror(); } split = (ey * etx - ex * ety) / denom; newvertex = (vertex) poolalloc(&m->vertices); for (i = 0; i < 2 + m->nextras; i++) { newvertex[i] = torg[i] + split * (tdest[i] - torg[i]); } ((int *) (newvertex))[m->vertexmarkindex] = (* (int *) ((*splitsubseg).ss + 6)); ((int *) (newvertex))[m->vertexmarkindex + 1] = 0; if (b->verbose > 1) { fprintf(stderr, " Splitting subsegment (%.12g, %.12g) (%.12g, %.12g) at (%.12g, %.12g).\n", torg[0], torg[1], tdest[0], tdest[1], newvertex[0], newvertex[1]); } success = insertvertex(m, b, newvertex, splittri, splitsubseg, 0, 0, 0.0); if (success != SUCCESSFULVERTEX) { fprintf(stderr, "Internal error in segmentintersection():\n"); fprintf(stderr, " Failure to split a segment.\n"); internalerror(); } if (m->steinerleft > 0) { m->steinerleft--; } collinear = finddirection(m, b, splittri, endpoint1); rightvertex = (vertex) (*splittri).tri[minus1mod3[(*splittri).orient] + 3]; leftvertex = (vertex) (*splittri).tri[(*splittri).orient + 3]; if ((leftvertex[0] == endpoint1[0]) && (leftvertex[1] == endpoint1[1])) { (*splittri).orient = minus1mod3[(*splittri).orient]; ptr = (*splittri).tri[(*splittri).orient]; (*splittri).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (*splittri).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (*splittri).orient);;; } else if ((rightvertex[0] != endpoint1[0]) || (rightvertex[1] != endpoint1[1])) { fprintf(stderr, "Internal error in segmentintersection():\n"); fprintf(stderr, " Topological inconsistency after splitting a segment.\n"); internalerror(); } } # 11755 "triangle.c" int scoutsegment(m, b, searchtri, endpoint2, newmark) struct mesh *m; struct behavior *b; struct otri *searchtri; vertex endpoint2; int newmark; { struct otri crosstri; struct osub crosssubseg; vertex leftvertex, rightvertex; enum finddirectionresult collinear; subseg sptr; collinear = finddirection(m, b, searchtri, endpoint2); rightvertex = (vertex) (*searchtri).tri[minus1mod3[(*searchtri).orient] + 3]; leftvertex = (vertex) (*searchtri).tri[(*searchtri).orient + 3]; if (((leftvertex[0] == endpoint2[0]) && (leftvertex[1] == endpoint2[1])) || ((rightvertex[0] == endpoint2[0]) && (rightvertex[1] == endpoint2[1]))) { if ((leftvertex[0] == endpoint2[0]) && (leftvertex[1] == endpoint2[1])) { (*searchtri).orient = minus1mod3[(*searchtri).orient]; } insertsubseg(m, b, searchtri, newmark); return 1; } else if (collinear == LEFTCOLLINEAR) { (*searchtri).orient = minus1mod3[(*searchtri).orient]; insertsubseg(m, b, searchtri, newmark); return scoutsegment(m, b, searchtri, endpoint2, newmark); } else if (collinear == RIGHTCOLLINEAR) { insertsubseg(m, b, searchtri, newmark); (*searchtri).orient = plus1mod3[(*searchtri).orient]; return scoutsegment(m, b, searchtri, endpoint2, newmark); } else { (crosstri).tri = (*searchtri).tri; (crosstri).orient = plus1mod3[(*searchtri).orient]; sptr = (subseg) (crosstri).tri[6 + (crosstri).orient]; (crosssubseg).ssorient = (int) ((unsigned long) (sptr) & (unsigned long) 1l); (crosssubseg).ss = (subseg *) ((unsigned long) (sptr) & ~ (unsigned long) 3l); if (crosssubseg.ss == m->dummysub) { return 0; } else { segmentintersection(m, b, &crosstri, &crosssubseg, endpoint2); (*searchtri).tri = (crosstri).tri; (*searchtri).orient = (crosstri).orient; insertsubseg(m, b, searchtri, newmark); return scoutsegment(m, b, searchtri, endpoint2, newmark); } } } # 11839 "triangle.c" void conformingedge(m, b, endpoint1, endpoint2, newmark) struct mesh *m; struct behavior *b; vertex endpoint1; vertex endpoint2; int newmark; { struct otri searchtri1, searchtri2; struct osub brokensubseg; vertex newvertex; vertex midvertex1, midvertex2; enum insertvertexresult success; int i; subseg sptr; if (b->verbose > 2) { fprintf(stderr, "Forcing segment into triangulation by recursive splitting:\n"); fprintf(stderr, " (%.12g, %.12g) (%.12g, %.12g)\n", endpoint1[0], endpoint1[1], endpoint2[0], endpoint2[1]); } newvertex = (vertex) poolalloc(&m->vertices); for (i = 0; i < 2 + m->nextras; i++) { newvertex[i] = 0.5 * (endpoint1[i] + endpoint2[i]); } ((int *) (newvertex))[m->vertexmarkindex] = newmark; ((int *) (newvertex))[m->vertexmarkindex + 1] = 1; searchtri1.tri = m->dummytri; success = insertvertex(m, b, newvertex, &searchtri1, (struct osub *) ((void *)0), 0, 0, 0.0); if (success == DUPLICATEVERTEX) { if (b->verbose > 2) { fprintf(stderr, " Segment intersects existing vertex (%.12g, %.12g).\n", newvertex[0], newvertex[1]); } vertexdealloc(m, newvertex); newvertex = (vertex) (searchtri1).tri[plus1mod3[(searchtri1).orient] + 3]; } else { if (success == VIOLATINGVERTEX) { if (b->verbose > 2) { fprintf(stderr, " Two segments intersect at (%.12g, %.12g).\n", newvertex[0], newvertex[1]); } sptr = (subseg) (searchtri1).tri[6 + (searchtri1).orient]; (brokensubseg).ssorient = (int) ((unsigned long) (sptr) & (unsigned long) 1l); (brokensubseg).ss = (subseg *) ((unsigned long) (sptr) & ~ (unsigned long) 3l); success = insertvertex(m, b, newvertex, &searchtri1, &brokensubseg, 0, 0, 0.0); if (success != SUCCESSFULVERTEX) { fprintf(stderr, "Internal error in conformingedge():\n"); fprintf(stderr, " Failure to split a segment.\n"); internalerror(); } } if (m->steinerleft > 0) { m->steinerleft--; } } (searchtri2).tri = (searchtri1).tri; (searchtri2).orient = (searchtri1).orient; finddirection(m, b, &searchtri2, endpoint2); if (!scoutsegment(m, b, &searchtri1, endpoint1, newmark)) { midvertex1 = (vertex) (searchtri1).tri[plus1mod3[(searchtri1).orient] + 3]; conformingedge(m, b, midvertex1, endpoint1, newmark); } if (!scoutsegment(m, b, &searchtri2, endpoint2, newmark)) { midvertex2 = (vertex) (searchtri2).tri[plus1mod3[(searchtri2).orient] + 3]; conformingedge(m, b, midvertex2, endpoint2, newmark); } } # 11969 "triangle.c" void delaunayfixup(m, b, fixuptri, leftside) struct mesh *m; struct behavior *b; struct otri *fixuptri; int leftside; { struct otri neartri; struct otri fartri; struct osub faredge; vertex nearvertex, leftvertex, rightvertex, farvertex; triangle ptr; subseg sptr; (neartri).tri = (*fixuptri).tri; (neartri).orient = plus1mod3[(*fixuptri).orient]; ptr = (neartri).tri[(neartri).orient]; (fartri).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (fartri).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (fartri).orient);; if (fartri.tri == m->dummytri) { return; } sptr = (subseg) (neartri).tri[6 + (neartri).orient]; (faredge).ssorient = (int) ((unsigned long) (sptr) & (unsigned long) 1l); (faredge).ss = (subseg *) ((unsigned long) (sptr) & ~ (unsigned long) 3l); if (faredge.ss != m->dummysub) { return; } nearvertex = (vertex) (neartri).tri[(neartri).orient + 3]; leftvertex = (vertex) (neartri).tri[plus1mod3[(neartri).orient] + 3]; rightvertex = (vertex) (neartri).tri[minus1mod3[(neartri).orient] + 3]; farvertex = (vertex) (fartri).tri[(fartri).orient + 3]; if (leftside) { if (counterclockwise(m, b, nearvertex, leftvertex, farvertex) <= 0.0) { return; } } else { if (counterclockwise(m, b, farvertex, rightvertex, nearvertex) <= 0.0) { return; } } if (counterclockwise(m, b, rightvertex, leftvertex, farvertex) > 0.0) { if (incircle(m, b, leftvertex, farvertex, rightvertex, nearvertex) <= 0.0) { return; } } flip(m, b, &neartri); (*fixuptri).orient = minus1mod3[(*fixuptri).orient]; delaunayfixup(m, b, fixuptri, leftside); delaunayfixup(m, b, &fartri, leftside); } # 12089 "triangle.c" void constrainededge(m, b, starttri, endpoint2, newmark) struct mesh *m; struct behavior *b; struct otri *starttri; vertex endpoint2; int newmark; { struct otri fixuptri, fixuptri2; struct osub crosssubseg; vertex endpoint1; vertex farvertex; double area; int collision; int done; triangle ptr; subseg sptr; endpoint1 = (vertex) (*starttri).tri[plus1mod3[(*starttri).orient] + 3]; (fixuptri).tri = (*starttri).tri; (fixuptri).orient = plus1mod3[(*starttri).orient]; flip(m, b, &fixuptri); collision = 0; done = 0; do { farvertex = (vertex) (fixuptri).tri[plus1mod3[(fixuptri).orient] + 3]; if ((farvertex[0] == endpoint2[0]) && (farvertex[1] == endpoint2[1])) { ptr = (fixuptri).tri[(fixuptri).orient]; (fixuptri2).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (fixuptri2).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (fixuptri2).orient);; (fixuptri2).orient = plus1mod3[(fixuptri2).orient];; delaunayfixup(m, b, &fixuptri, 0); delaunayfixup(m, b, &fixuptri2, 1); done = 1; } else { area = counterclockwise(m, b, endpoint1, endpoint2, farvertex); if (area == 0.0) { collision = 1; ptr = (fixuptri).tri[(fixuptri).orient]; (fixuptri2).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (fixuptri2).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (fixuptri2).orient);; (fixuptri2).orient = plus1mod3[(fixuptri2).orient];; delaunayfixup(m, b, &fixuptri, 0); delaunayfixup(m, b, &fixuptri2, 1); done = 1; } else { if (area > 0.0) { ptr = (fixuptri).tri[(fixuptri).orient]; (fixuptri2).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (fixuptri2).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (fixuptri2).orient);; (fixuptri2).orient = plus1mod3[(fixuptri2).orient];; delaunayfixup(m, b, &fixuptri2, 1); (fixuptri).orient = minus1mod3[(fixuptri).orient]; } else { delaunayfixup(m, b, &fixuptri, 0); ptr = (fixuptri).tri[(fixuptri).orient]; (fixuptri).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (fixuptri).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (fixuptri).orient);; (fixuptri).orient = plus1mod3[(fixuptri).orient];; } sptr = (subseg) (fixuptri).tri[6 + (fixuptri).orient]; (crosssubseg).ssorient = (int) ((unsigned long) (sptr) & (unsigned long) 1l); (crosssubseg).ss = (subseg *) ((unsigned long) (sptr) & ~ (unsigned long) 3l); if (crosssubseg.ss == m->dummysub) { flip(m, b, &fixuptri); } else { collision = 1; segmentintersection(m, b, &fixuptri, &crosssubseg, endpoint2); done = 1; } } } } while (!done); insertsubseg(m, b, &fixuptri, newmark); if (collision) { if (!scoutsegment(m, b, &fixuptri, endpoint2, newmark)) { constrainededge(m, b, &fixuptri, endpoint2, newmark); } } } # 12191 "triangle.c" void insertsegment(m, b, endpoint1, endpoint2, newmark) struct mesh *m; struct behavior *b; vertex endpoint1; vertex endpoint2; int newmark; { struct otri searchtri1, searchtri2; triangle encodedtri; vertex checkvertex; triangle ptr; if (b->verbose > 1) { fprintf(stderr, " Connecting (%.12g, %.12g) to (%.12g, %.12g).\n", endpoint1[0], endpoint1[1], endpoint2[0], endpoint2[1]); } checkvertex = (vertex) ((void *)0); encodedtri = ((triangle *) (endpoint1))[m->vertex2triindex]; if (encodedtri != (triangle) ((void *)0)) { (searchtri1).orient = (int) ((unsigned long) (encodedtri) & (unsigned long) 3l); (searchtri1).tri = (triangle *) ((unsigned long) (encodedtri) ^ (unsigned long) (searchtri1).orient); checkvertex = (vertex) (searchtri1).tri[plus1mod3[(searchtri1).orient] + 3]; } if (checkvertex != endpoint1) { searchtri1.tri = m->dummytri; searchtri1.orient = 0; ptr = (searchtri1).tri[(searchtri1).orient]; (searchtri1).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (searchtri1).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (searchtri1).orient);; if (locate(m, b, endpoint1, &searchtri1) != ONVERTEX) { fprintf(stderr, "Internal error in insertsegment(): Unable to locate PSLG vertex\n"); fprintf(stderr, " (%.12g, %.12g) in triangulation.\n", endpoint1[0], endpoint1[1]); internalerror(); } } (m->recenttri).tri = (searchtri1).tri; (m->recenttri).orient = (searchtri1).orient; if (scoutsegment(m, b, &searchtri1, endpoint2, newmark)) { return; } endpoint1 = (vertex) (searchtri1).tri[plus1mod3[(searchtri1).orient] + 3]; checkvertex = (vertex) ((void *)0); encodedtri = ((triangle *) (endpoint2))[m->vertex2triindex]; if (encodedtri != (triangle) ((void *)0)) { (searchtri2).orient = (int) ((unsigned long) (encodedtri) & (unsigned long) 3l); (searchtri2).tri = (triangle *) ((unsigned long) (encodedtri) ^ (unsigned long) (searchtri2).orient); checkvertex = (vertex) (searchtri2).tri[plus1mod3[(searchtri2).orient] + 3]; } if (checkvertex != endpoint2) { searchtri2.tri = m->dummytri; searchtri2.orient = 0; ptr = (searchtri2).tri[(searchtri2).orient]; (searchtri2).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (searchtri2).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (searchtri2).orient);; if (locate(m, b, endpoint2, &searchtri2) != ONVERTEX) { fprintf(stderr, "Internal error in insertsegment(): Unable to locate PSLG vertex\n"); fprintf(stderr, " (%.12g, %.12g) in triangulation.\n", endpoint2[0], endpoint2[1]); internalerror(); } } (m->recenttri).tri = (searchtri2).tri; (m->recenttri).orient = (searchtri2).orient; if (scoutsegment(m, b, &searchtri2, endpoint1, newmark)) { return; } endpoint2 = (vertex) (searchtri2).tri[plus1mod3[(searchtri2).orient] + 3]; if (b->splitseg) { conformingedge(m, b, endpoint1, endpoint2, newmark); } else { constrainededge(m, b, &searchtri1, endpoint2, newmark); } } # 12302 "triangle.c" void markhull(m, b) struct mesh *m; struct behavior *b; { struct otri hulltri; struct otri nexttri; struct otri starttri; triangle ptr; hulltri.tri = m->dummytri; hulltri.orient = 0; ptr = (hulltri).tri[(hulltri).orient]; (hulltri).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (hulltri).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (hulltri).orient);; (starttri).tri = (hulltri).tri; (starttri).orient = (hulltri).orient; do { insertsubseg(m, b, &hulltri, 1); (hulltri).orient = plus1mod3[(hulltri).orient]; ptr = (hulltri).tri[(hulltri).orient]; (nexttri).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (nexttri).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (nexttri).orient);; (nexttri).orient = plus1mod3[(nexttri).orient];; while (nexttri.tri != m->dummytri) { (hulltri).tri = (nexttri).tri; (hulltri).orient = (nexttri).orient; ptr = (hulltri).tri[(hulltri).orient]; (nexttri).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (nexttri).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (nexttri).orient);; (nexttri).orient = plus1mod3[(nexttri).orient];; } } while (!(((hulltri).tri == (starttri).tri) && ((hulltri).orient == (starttri).orient))); } # 12349 "triangle.c" void formskeleton(m, b, segmentlist, segmentmarkerlist, numberofsegments) struct mesh *m; struct behavior *b; int *segmentlist; int *segmentmarkerlist; int numberofsegments; # 12372 "triangle.c" { char polyfilename[6]; int index; vertex endpoint1, endpoint2; int segmentmarkers; int end1, end2; int boundmarker; int i; if (b->poly) { if (!b->quiet) { fprintf(stderr, "Recovering segments in Delaunay triangulation.\n"); } strcpy(polyfilename, "input"); m->insegments = numberofsegments; segmentmarkers = segmentmarkerlist != (int *) ((void *)0); index = 0; # 12409 "triangle.c" if (m->triangles.items == 0) { return; } if (m->insegments > 0) { makevertexmap(m, b); if (b->verbose) { fprintf(stderr, " Recovering PSLG segments.\n"); } } boundmarker = 0; for (i = 0; i < m->insegments; i++) { end1 = segmentlist[index++]; end2 = segmentlist[index++]; if (segmentmarkers) { boundmarker = segmentmarkerlist[i]; } # 12458 "triangle.c" if ((end1 < b->firstnumber) || (end1 >= b->firstnumber + m->invertices)) { if (!b->quiet) { fprintf(stderr, "Warning: Invalid first endpoint of segment %d in %s.\n", b->firstnumber + i, polyfilename); } } else if ((end2 < b->firstnumber) || (end2 >= b->firstnumber + m->invertices)) { if (!b->quiet) { fprintf(stderr, "Warning: Invalid second endpoint of segment %d in %s.\n", b->firstnumber + i, polyfilename); } } else { endpoint1 = getvertex(m, b, end1); endpoint2 = getvertex(m, b, end2); if ((endpoint1[0] == endpoint2[0]) && (endpoint1[1] == endpoint2[1])) { if (!b->quiet) { fprintf(stderr, "Warning: Endpoints of segment %d are coincident in %s.\n", b->firstnumber + i, polyfilename); } } else { insertsegment(m, b, endpoint1, endpoint2, boundmarker); } } } } else { m->insegments = 0; } if (b->convex || !b->poly) { if (b->verbose) { fprintf(stderr, " Enclosing convex hull with segments.\n"); } markhull(m, b); } } # 12514 "triangle.c" void infecthull(m, b) struct mesh *m; struct behavior *b; { struct otri hulltri; struct otri nexttri; struct otri starttri; struct osub hullsubseg; triangle **deadtriangle; vertex horg, hdest; triangle ptr; subseg sptr; if (b->verbose) { fprintf(stderr, " Marking concavities (external triangles) for elimination.\n"); } hulltri.tri = m->dummytri; hulltri.orient = 0; ptr = (hulltri).tri[(hulltri).orient]; (hulltri).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (hulltri).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (hulltri).orient);; (starttri).tri = (hulltri).tri; (starttri).orient = (hulltri).orient; do { if (!(((unsigned long) (hulltri).tri[6] & (unsigned long) 2l) != 0l)) { sptr = (subseg) (hulltri).tri[6 + (hulltri).orient]; (hullsubseg).ssorient = (int) ((unsigned long) (sptr) & (unsigned long) 1l); (hullsubseg).ss = (subseg *) ((unsigned long) (sptr) & ~ (unsigned long) 3l); if (hullsubseg.ss == m->dummysub) { if (!(((unsigned long) (hulltri).tri[6] & (unsigned long) 2l) != 0l)) { (hulltri).tri[6] = (triangle) ((unsigned long) (hulltri).tri[6] | (unsigned long) 2l); deadtriangle = (triangle **) poolalloc(&m->viri); *deadtriangle = hulltri.tri; } } else { if ((* (int *) ((hullsubseg).ss + 6)) == 0) { * (int *) ((hullsubseg).ss + 6) = 1; horg = (vertex) (hulltri).tri[plus1mod3[(hulltri).orient] + 3]; hdest = (vertex) (hulltri).tri[minus1mod3[(hulltri).orient] + 3]; if (((int *) (horg))[m->vertexmarkindex] == 0) { ((int *) (horg))[m->vertexmarkindex] = 1; } if (((int *) (hdest))[m->vertexmarkindex] == 0) { ((int *) (hdest))[m->vertexmarkindex] = 1; } } } } (hulltri).orient = plus1mod3[(hulltri).orient]; ptr = (hulltri).tri[(hulltri).orient]; (nexttri).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (nexttri).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (nexttri).orient);; (nexttri).orient = plus1mod3[(nexttri).orient];; while (nexttri.tri != m->dummytri) { (hulltri).tri = (nexttri).tri; (hulltri).orient = (nexttri).orient; ptr = (hulltri).tri[(hulltri).orient]; (nexttri).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (nexttri).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (nexttri).orient);; (nexttri).orient = plus1mod3[(nexttri).orient];; } } while (!(((hulltri).tri == (starttri).tri) && ((hulltri).orient == (starttri).orient))); } # 12596 "triangle.c" void plague(m, b) struct mesh *m; struct behavior *b; { struct otri testtri; struct otri neighbor; triangle **virusloop; triangle **deadtriangle; struct osub neighborsubseg; vertex testvertex; vertex norg, ndest; vertex deadorg, deaddest, deadapex; int killorg; triangle ptr; subseg sptr; if (b->verbose) { fprintf(stderr, " Marking neighbors of marked triangles.\n"); } traversalinit(&m->viri); virusloop = (triangle **) traverse(&m->viri); while (virusloop != (triangle **) ((void *)0)) { testtri.tri = *virusloop; (testtri).tri[6] = (triangle) ((unsigned long) (testtri).tri[6] & ~ (unsigned long) 2l); if (b->verbose > 2) { testtri.orient = 0; deadorg = (vertex) (testtri).tri[plus1mod3[(testtri).orient] + 3]; deaddest = (vertex) (testtri).tri[minus1mod3[(testtri).orient] + 3]; deadapex = (vertex) (testtri).tri[(testtri).orient + 3]; fprintf(stderr, " Checking (%.12g, %.12g) (%.12g, %.12g) (%.12g, %.12g)\n", deadorg[0], deadorg[1], deaddest[0], deaddest[1], deadapex[0], deadapex[1]); } for (testtri.orient = 0; testtri.orient < 3; testtri.orient++) { ptr = (testtri).tri[(testtri).orient]; (neighbor).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (neighbor).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (neighbor).orient);; sptr = (subseg) (testtri).tri[6 + (testtri).orient]; (neighborsubseg).ssorient = (int) ((unsigned long) (sptr) & (unsigned long) 1l); (neighborsubseg).ss = (subseg *) ((unsigned long) (sptr) & ~ (unsigned long) 3l); if ((neighbor.tri == m->dummytri) || (((unsigned long) (neighbor).tri[6] & (unsigned long) 2l) != 0l)) { if (neighborsubseg.ss != m->dummysub) { subsegdealloc(m, neighborsubseg.ss); if (neighbor.tri != m->dummytri) { (neighbor).tri[6] = (triangle) ((unsigned long) (neighbor).tri[6] & ~ (unsigned long) 2l); (neighbor).tri[6 + (neighbor).orient] = (triangle) m->dummysub; (neighbor).tri[6] = (triangle) ((unsigned long) (neighbor).tri[6] | (unsigned long) 2l); } } } else { if (neighborsubseg.ss == m->dummysub) { if (b->verbose > 2) { deadorg = (vertex) (neighbor).tri[plus1mod3[(neighbor).orient] + 3]; deaddest = (vertex) (neighbor).tri[minus1mod3[(neighbor).orient] + 3]; deadapex = (vertex) (neighbor).tri[(neighbor).orient + 3]; fprintf(stderr, " Marking (%.12g, %.12g) (%.12g, %.12g) (%.12g, %.12g)\n", deadorg[0], deadorg[1], deaddest[0], deaddest[1], deadapex[0], deadapex[1]); } (neighbor).tri[6] = (triangle) ((unsigned long) (neighbor).tri[6] | (unsigned long) 2l); deadtriangle = (triangle **) poolalloc(&m->viri); *deadtriangle = neighbor.tri; } else { (neighborsubseg).ss[4 + (neighborsubseg).ssorient] = (subseg) m->dummytri; if ((* (int *) ((neighborsubseg).ss + 6)) == 0) { * (int *) ((neighborsubseg).ss + 6) = 1; } norg = (vertex) (neighbor).tri[plus1mod3[(neighbor).orient] + 3]; ndest = (vertex) (neighbor).tri[minus1mod3[(neighbor).orient] + 3]; if (((int *) (norg))[m->vertexmarkindex] == 0) { ((int *) (norg))[m->vertexmarkindex] = 1; } if (((int *) (ndest))[m->vertexmarkindex] == 0) { ((int *) (ndest))[m->vertexmarkindex] = 1; } } } } (testtri).tri[6] = (triangle) ((unsigned long) (testtri).tri[6] | (unsigned long) 2l); virusloop = (triangle **) traverse(&m->viri); } if (b->verbose) { fprintf(stderr, " Deleting marked triangles.\n"); } traversalinit(&m->viri); virusloop = (triangle **) traverse(&m->viri); while (virusloop != (triangle **) ((void *)0)) { testtri.tri = *virusloop; for (testtri.orient = 0; testtri.orient < 3; testtri.orient++) { testvertex = (vertex) (testtri).tri[plus1mod3[(testtri).orient] + 3]; if (testvertex != (vertex) ((void *)0)) { killorg = 1; (testtri).tri[plus1mod3[(testtri).orient] + 3] = (triangle) ((void *)0); (neighbor).tri = (testtri).tri; (neighbor).orient = minus1mod3[(testtri).orient]; ptr = (neighbor).tri[(neighbor).orient]; (neighbor).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (neighbor).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (neighbor).orient);;; while ((neighbor.tri != m->dummytri) && (!(((neighbor).tri == (testtri).tri) && ((neighbor).orient == (testtri).orient)))) { if ((((unsigned long) (neighbor).tri[6] & (unsigned long) 2l) != 0l)) { (neighbor).tri[plus1mod3[(neighbor).orient] + 3] = (triangle) ((void *)0); } else { killorg = 0; } (neighbor).orient = minus1mod3[(neighbor).orient]; ptr = (neighbor).tri[(neighbor).orient]; (neighbor).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (neighbor).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (neighbor).orient);;; } if (neighbor.tri == m->dummytri) { ptr = (testtri).tri[(testtri).orient]; (neighbor).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (neighbor).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (neighbor).orient);; (neighbor).orient = plus1mod3[(neighbor).orient];; while (neighbor.tri != m->dummytri) { if ((((unsigned long) (neighbor).tri[6] & (unsigned long) 2l) != 0l)) { (neighbor).tri[plus1mod3[(neighbor).orient] + 3] = (triangle) ((void *)0); } else { killorg = 0; } ptr = (neighbor).tri[(neighbor).orient]; (neighbor).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (neighbor).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (neighbor).orient);; (neighbor).orient = plus1mod3[(neighbor).orient];; } } if (killorg) { if (b->verbose > 1) { fprintf(stderr, " Deleting vertex (%.12g, %.12g)\n", testvertex[0], testvertex[1]); } ((int *) (testvertex))[m->vertexmarkindex + 1] = -32767; m->undeads++; } } } for (testtri.orient = 0; testtri.orient < 3; testtri.orient++) { ptr = (testtri).tri[(testtri).orient]; (neighbor).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (neighbor).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (neighbor).orient);; if (neighbor.tri == m->dummytri) { m->hullsize--; } else { (neighbor).tri[(neighbor).orient] = (triangle) m->dummytri; m->hullsize++; } } triangledealloc(m, testtri.tri); virusloop = (triangle **) traverse(&m->viri); } poolrestart(&m->viri); } # 12807 "triangle.c" void regionplague(m, b, attribute, area) struct mesh *m; struct behavior *b; double attribute; double area; { struct otri testtri; struct otri neighbor; triangle **virusloop; triangle **regiontri; struct osub neighborsubseg; vertex regionorg, regiondest, regionapex; triangle ptr; subseg sptr; if (b->verbose > 1) { fprintf(stderr, " Marking neighbors of marked triangles.\n"); } traversalinit(&m->viri); virusloop = (triangle **) traverse(&m->viri); while (virusloop != (triangle **) ((void *)0)) { testtri.tri = *virusloop; (testtri).tri[6] = (triangle) ((unsigned long) (testtri).tri[6] & ~ (unsigned long) 2l); if (b->regionattrib) { ((double *) (testtri).tri)[m->elemattribindex + (m->eextras)] = attribute; } if (b->vararea) { ((double *) (testtri).tri)[m->areaboundindex] = area; } if (b->verbose > 2) { testtri.orient = 0; regionorg = (vertex) (testtri).tri[plus1mod3[(testtri).orient] + 3]; regiondest = (vertex) (testtri).tri[minus1mod3[(testtri).orient] + 3]; regionapex = (vertex) (testtri).tri[(testtri).orient + 3]; fprintf(stderr, " Checking (%.12g, %.12g) (%.12g, %.12g) (%.12g, %.12g)\n", regionorg[0], regionorg[1], regiondest[0], regiondest[1], regionapex[0], regionapex[1]); } for (testtri.orient = 0; testtri.orient < 3; testtri.orient++) { ptr = (testtri).tri[(testtri).orient]; (neighbor).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (neighbor).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (neighbor).orient);; sptr = (subseg) (testtri).tri[6 + (testtri).orient]; (neighborsubseg).ssorient = (int) ((unsigned long) (sptr) & (unsigned long) 1l); (neighborsubseg).ss = (subseg *) ((unsigned long) (sptr) & ~ (unsigned long) 3l); if ((neighbor.tri != m->dummytri) && !(((unsigned long) (neighbor).tri[6] & (unsigned long) 2l) != 0l) && (neighborsubseg.ss == m->dummysub)) { if (b->verbose > 2) { regionorg = (vertex) (neighbor).tri[plus1mod3[(neighbor).orient] + 3]; regiondest = (vertex) (neighbor).tri[minus1mod3[(neighbor).orient] + 3]; regionapex = (vertex) (neighbor).tri[(neighbor).orient + 3]; fprintf(stderr, " Marking (%.12g, %.12g) (%.12g, %.12g) (%.12g, %.12g)\n", regionorg[0], regionorg[1], regiondest[0], regiondest[1], regionapex[0], regionapex[1]); } (neighbor).tri[6] = (triangle) ((unsigned long) (neighbor).tri[6] | (unsigned long) 2l); regiontri = (triangle **) poolalloc(&m->viri); *regiontri = neighbor.tri; } } (testtri).tri[6] = (triangle) ((unsigned long) (testtri).tri[6] | (unsigned long) 2l); virusloop = (triangle **) traverse(&m->viri); } if (b->verbose > 1) { fprintf(stderr, " Unmarking marked triangles.\n"); } traversalinit(&m->viri); virusloop = (triangle **) traverse(&m->viri); while (virusloop != (triangle **) ((void *)0)) { testtri.tri = *virusloop; (testtri).tri[6] = (triangle) ((unsigned long) (testtri).tri[6] & ~ (unsigned long) 2l); virusloop = (triangle **) traverse(&m->viri); } poolrestart(&m->viri); } # 12920 "triangle.c" void carveholes(m, b, holelist, holes, regionlist, regions) struct mesh *m; struct behavior *b; double *holelist; int holes; double *regionlist; int regions; { struct otri searchtri; struct otri triangleloop; struct otri *regiontris; triangle **holetri; triangle **regiontri; vertex searchorg, searchdest; enum locateresult intersect; int i; triangle ptr; if (!(b->quiet || (b->noholes && b->convex))) { fprintf(stderr, "Removing unwanted triangles.\n"); if (b->verbose && (holes > 0)) { fprintf(stderr, " Marking holes for elimination.\n"); } } if (regions > 0) { regiontris = (struct otri *) trimalloc(regions * sizeof(struct otri)); } if (((holes > 0) && !b->noholes) || !b->convex || (regions > 0)) { poolinit(&m->viri, sizeof(triangle *), 1020, POINTER, 0); } if (!b->convex) { infecthull(m, b); } if ((holes > 0) && !b->noholes) { for (i = 0; i < 2 * holes; i += 2) { if ((holelist[i] >= m->xmin) && (holelist[i] <= m->xmax) && (holelist[i + 1] >= m->ymin) && (holelist[i + 1] <= m->ymax)) { searchtri.tri = m->dummytri; searchtri.orient = 0; ptr = (searchtri).tri[(searchtri).orient]; (searchtri).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (searchtri).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (searchtri).orient);; searchorg = (vertex) (searchtri).tri[plus1mod3[(searchtri).orient] + 3]; searchdest = (vertex) (searchtri).tri[minus1mod3[(searchtri).orient] + 3]; if (counterclockwise(m, b, searchorg, searchdest, &holelist[i]) > 0.0) { intersect = locate(m, b, &holelist[i], &searchtri); if ((intersect != OUTSIDE) && (!(((unsigned long) (searchtri).tri[6] & (unsigned long) 2l) != 0l))) { (searchtri).tri[6] = (triangle) ((unsigned long) (searchtri).tri[6] | (unsigned long) 2l); holetri = (triangle **) poolalloc(&m->viri); *holetri = searchtri.tri; } } } } } if (regions > 0) { for (i = 0; i < regions; i++) { regiontris[i].tri = m->dummytri; if ((regionlist[4 * i] >= m->xmin) && (regionlist[4 * i] <= m->xmax) && (regionlist[4 * i + 1] >= m->ymin) && (regionlist[4 * i + 1] <= m->ymax)) { searchtri.tri = m->dummytri; searchtri.orient = 0; ptr = (searchtri).tri[(searchtri).orient]; (searchtri).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (searchtri).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (searchtri).orient);; searchorg = (vertex) (searchtri).tri[plus1mod3[(searchtri).orient] + 3]; searchdest = (vertex) (searchtri).tri[minus1mod3[(searchtri).orient] + 3]; if (counterclockwise(m, b, searchorg, searchdest, &regionlist[4 * i]) > 0.0) { intersect = locate(m, b, &regionlist[4 * i], &searchtri); if ((intersect != OUTSIDE) && (!(((unsigned long) (searchtri).tri[6] & (unsigned long) 2l) != 0l))) { (regiontris[i]).tri = (searchtri).tri; (regiontris[i]).orient = (searchtri).orient; } } } } } if (m->viri.items > 0) { plague(m, b); } if (regions > 0) { if (!b->quiet) { if (b->regionattrib) { if (b->vararea) { fprintf(stderr, "Spreading regional attributes and area constraints.\n"); } else { fprintf(stderr, "Spreading regional attributes.\n"); } } else { fprintf(stderr, "Spreading regional area constraints.\n"); } } if (b->regionattrib && !b->refine) { traversalinit(&m->triangles); triangleloop.orient = 0; triangleloop.tri = triangletraverse(m); while (triangleloop.tri != (triangle *) ((void *)0)) { ((double *) (triangleloop).tri)[m->elemattribindex + (m->eextras)] = 0.0; triangleloop.tri = triangletraverse(m); } } for (i = 0; i < regions; i++) { if (regiontris[i].tri != m->dummytri) { if (!((regiontris[i].tri)[1] == (triangle) ((void *)0))) { (regiontris[i]).tri[6] = (triangle) ((unsigned long) (regiontris[i]).tri[6] | (unsigned long) 2l); regiontri = (triangle **) poolalloc(&m->viri); *regiontri = regiontris[i].tri; regionplague(m, b, regionlist[4 * i + 2], regionlist[4 * i + 3]); } } } if (b->regionattrib && !b->refine) { m->eextras++; } } if (((holes > 0) && !b->noholes) || !b->convex || (regions > 0)) { pooldeinit(&m->viri); } if (regions > 0) { trifree((int *) regiontris); } } # 13110 "triangle.c" void tallyencs(m, b) struct mesh *m; struct behavior *b; { struct osub subsegloop; int dummy; traversalinit(&m->subsegs); subsegloop.ssorient = 0; subsegloop.ss = subsegtraverse(m); while (subsegloop.ss != (subseg *) ((void *)0)) { dummy = checkseg4encroach(m, b, &subsegloop, 0.0); subsegloop.ss = subsegtraverse(m); } } # 13139 "triangle.c" void precisionerror() { fprintf(stderr, "Try increasing the area criterion and/or reducing the minimum\n"); fprintf(stderr, " allowable angle so that tiny triangles are not created.\n"); } # 13171 "triangle.c" void splitencsegs(m, b, triflaws) struct mesh *m; struct behavior *b; int triflaws; { struct otri enctri; struct otri testtri; struct osub testsh; struct osub currentenc; struct badsubseg *encloop; vertex eorg, edest, eapex; vertex newvertex; enum insertvertexresult success; double segmentlength, nearestpoweroftwo; double split; double multiplier, divisor; int acuteorg, acuteorg2, acutedest, acutedest2; int dummy; int i; triangle ptr; subseg sptr; while ((m->badsubsegs.items > 0) && (m->steinerleft != 0)) { traversalinit(&m->badsubsegs); encloop = badsubsegtraverse(m); while ((encloop != (struct badsubseg *) ((void *)0)) && (m->steinerleft != 0)) { (currentenc).ssorient = (int) ((unsigned long) (encloop->encsubseg) & (unsigned long) 1l); (currentenc).ss = (subseg *) ((unsigned long) (encloop->encsubseg) & ~ (unsigned long) 3l); eorg = (vertex) (currentenc).ss[2 + (currentenc).ssorient]; edest = (vertex) (currentenc).ss[3 - (currentenc).ssorient]; if (!((currentenc.ss)[1] == (subseg) ((void *)0)) && (eorg == encloop->subsegorg) && (edest == encloop->subsegdest)) { # 13226 "triangle.c" ptr = (triangle) (currentenc).ss[4 + (currentenc).ssorient]; (enctri).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (enctri).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (enctri).orient); (testtri).tri = (enctri).tri; (testtri).orient = plus1mod3[(enctri).orient]; sptr = (subseg) (testtri).tri[6 + (testtri).orient]; (testsh).ssorient = (int) ((unsigned long) (sptr) & (unsigned long) 1l); (testsh).ss = (subseg *) ((unsigned long) (sptr) & ~ (unsigned long) 3l); acuteorg = testsh.ss != m->dummysub; (testtri).orient = plus1mod3[(testtri).orient]; sptr = (subseg) (testtri).tri[6 + (testtri).orient]; (testsh).ssorient = (int) ((unsigned long) (sptr) & (unsigned long) 1l); (testsh).ss = (subseg *) ((unsigned long) (sptr) & ~ (unsigned long) 3l); acutedest = testsh.ss != m->dummysub; if (!b->nolenses && !acuteorg && !acutedest) { eapex = (vertex) (enctri).tri[(enctri).orient + 3]; while ((((int *) (eapex))[m->vertexmarkindex + 1] == 2) && ((eorg[0] - eapex[0]) * (edest[0] - eapex[0]) + (eorg[1] - eapex[1]) * (edest[1] - eapex[1]) < 0.0)) { deletevertex(m, b, &testtri); ptr = (triangle) (currentenc).ss[4 + (currentenc).ssorient]; (enctri).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (enctri).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (enctri).orient); eapex = (vertex) (enctri).tri[(enctri).orient + 3]; (testtri).tri = (enctri).tri; (testtri).orient = minus1mod3[(enctri).orient]; } } ptr = (enctri).tri[(enctri).orient]; (testtri).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (testtri).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (testtri).orient);; if (testtri.tri != m->dummytri) { (testtri).orient = plus1mod3[(testtri).orient]; sptr = (subseg) (testtri).tri[6 + (testtri).orient]; (testsh).ssorient = (int) ((unsigned long) (sptr) & (unsigned long) 1l); (testsh).ss = (subseg *) ((unsigned long) (sptr) & ~ (unsigned long) 3l); acutedest2 = testsh.ss != m->dummysub; acutedest = acutedest || acutedest2; (testtri).orient = plus1mod3[(testtri).orient]; sptr = (subseg) (testtri).tri[6 + (testtri).orient]; (testsh).ssorient = (int) ((unsigned long) (sptr) & (unsigned long) 1l); (testsh).ss = (subseg *) ((unsigned long) (sptr) & ~ (unsigned long) 3l); acuteorg2 = testsh.ss != m->dummysub; acuteorg = acuteorg || acuteorg2; if (!b->nolenses && !acuteorg2 && !acutedest2) { eapex = (vertex) (testtri).tri[plus1mod3[(testtri).orient] + 3]; while ((((int *) (eapex))[m->vertexmarkindex + 1] == 2) && ((eorg[0] - eapex[0]) * (edest[0] - eapex[0]) + (eorg[1] - eapex[1]) * (edest[1] - eapex[1]) < 0.0)) { deletevertex(m, b, &testtri); ptr = (enctri).tri[(enctri).orient]; (testtri).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (testtri).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (testtri).orient);; eapex = (vertex) (testtri).tri[(testtri).orient + 3]; (testtri).orient = minus1mod3[(testtri).orient]; } } } if (acuteorg || acutedest) { segmentlength = sqrt((edest[0] - eorg[0]) * (edest[0] - eorg[0]) + (edest[1] - eorg[1]) * (edest[1] - eorg[1])); nearestpoweroftwo = 1.0; while (segmentlength > 3.0 * nearestpoweroftwo) { nearestpoweroftwo *= 2.0; } while (segmentlength < 1.5 * nearestpoweroftwo) { nearestpoweroftwo *= 0.5; } split = nearestpoweroftwo / segmentlength; if (acutedest) { split = 1.0 - split; } } else { split = 0.5; } newvertex = (vertex) poolalloc(&m->vertices); for (i = 0; i < 2 + m->nextras; i++) { newvertex[i] = eorg[i] + split * (edest[i] - eorg[i]); } if (!b->noexact) { multiplier = counterclockwise(m, b, eorg, edest, newvertex); divisor = ((eorg[0] - edest[0]) * (eorg[0] - edest[0]) + (eorg[1] - edest[1]) * (eorg[1] - edest[1])); if ((multiplier != 0.0) && (divisor != 0.0)) { multiplier = multiplier / divisor; if (multiplier == multiplier) { newvertex[0] += multiplier * (edest[1] - eorg[1]); newvertex[1] += multiplier * (eorg[0] - edest[0]); } } } ((int *) (newvertex))[m->vertexmarkindex] = (* (int *) ((currentenc).ss + 6)); ((int *) (newvertex))[m->vertexmarkindex + 1] = 1; if (b->verbose > 1) { fprintf(stderr, " Splitting subsegment (%.12g, %.12g) (%.12g, %.12g) at (%.12g, %.12g).\n", eorg[0], eorg[1], edest[0], edest[1], newvertex[0], newvertex[1]); } if (((newvertex[0] == eorg[0]) && (newvertex[1] == eorg[1])) || ((newvertex[0] == edest[0]) && (newvertex[1] == edest[1]))) { fprintf(stderr, "Error: Ran out of precision at (%.12g, %.12g).\n", newvertex[0], newvertex[1]); fprintf(stderr, "I attempted to split a segment to a smaller size than\n"); fprintf(stderr, " can be accommodated by the finite precision of\n"); fprintf(stderr, " floating point arithmetic.\n"); precisionerror(); exit(1); } success = insertvertex(m, b, newvertex, &enctri, &currentenc, 1, triflaws, 0.0); if ((success != SUCCESSFULVERTEX) && (success != ENCROACHINGVERTEX)) { fprintf(stderr, "Internal error in splitencsegs():\n"); fprintf(stderr, " Failure to split a segment.\n"); internalerror(); } if (m->steinerleft > 0) { m->steinerleft--; } dummy = checkseg4encroach(m, b, &currentenc, 0.0); sptr = (currentenc).ss[1 - (currentenc).ssorient]; (currentenc).ssorient = (int) ((unsigned long) (sptr) & (unsigned long) 1l); (currentenc).ss = (subseg *) ((unsigned long) (sptr) & ~ (unsigned long) 3l); dummy = checkseg4encroach(m, b, &currentenc, 0.0); } badsubsegdealloc(m, encloop); encloop = badsubsegtraverse(m); } } } # 13383 "triangle.c" void tallyfaces(m, b) struct mesh *m; struct behavior *b; { struct otri triangleloop; if (b->verbose) { fprintf(stderr, " Making a list of bad triangles.\n"); } traversalinit(&m->triangles); triangleloop.orient = 0; triangleloop.tri = triangletraverse(m); while (triangleloop.tri != (triangle *) ((void *)0)) { testtriangle(m, b, &triangleloop); triangleloop.tri = triangletraverse(m); } } # 13420 "triangle.c" void splittriangle(m, b, badtri) struct mesh *m; struct behavior *b; struct badtriang *badtri; { struct otri badotri; vertex borg, bdest, bapex; vertex newvertex; double xi, eta; double minedge; enum insertvertexresult success; int errorflag; int i; (badotri).orient = (int) ((unsigned long) (badtri->poortri) & (unsigned long) 3l); (badotri).tri = (triangle *) ((unsigned long) (badtri->poortri) ^ (unsigned long) (badotri).orient); borg = (vertex) (badotri).tri[plus1mod3[(badotri).orient] + 3]; bdest = (vertex) (badotri).tri[minus1mod3[(badotri).orient] + 3]; bapex = (vertex) (badotri).tri[(badotri).orient + 3]; if (!((badotri.tri)[1] == (triangle) ((void *)0)) && (borg == badtri->triangorg) && (bdest == badtri->triangdest) && (bapex == badtri->triangapex)) { if (b->verbose > 1) { fprintf(stderr, " Splitting this triangle at its circumcenter:\n"); fprintf(stderr, " (%.12g, %.12g) (%.12g, %.12g) (%.12g, %.12g)\n", borg[0], borg[1], bdest[0], bdest[1], bapex[0], bapex[1]); } errorflag = 0; newvertex = (vertex) poolalloc(&m->vertices); findcircumcenter(m, b, borg, bdest, bapex, newvertex, &xi, &eta, &minedge); if (((newvertex[0] == borg[0]) && (newvertex[1] == borg[1])) || ((newvertex[0] == bdest[0]) && (newvertex[1] == bdest[1])) || ((newvertex[0] == bapex[0]) && (newvertex[1] == bapex[1]))) { if (!b->quiet) { fprintf(stderr, "Warning: New vertex (%.12g, %.12g) falls on existing vertex.\n", newvertex[0], newvertex[1]); errorflag = 1; } vertexdealloc(m, newvertex); } else { for (i = 2; i < 2 + m->nextras; i++) { newvertex[i] = borg[i] + xi * (bdest[i] - borg[i]) + eta * (bapex[i] - borg[i]); } ((int *) (newvertex))[m->vertexmarkindex] = 0; ((int *) (newvertex))[m->vertexmarkindex + 1] = 2; # 13485 "triangle.c" if (eta < xi) { (badotri).orient = minus1mod3[(badotri).orient]; } success = insertvertex(m, b, newvertex, &badotri, (struct osub *) ((void *)0), 1, 1, minedge); if (success == SUCCESSFULVERTEX) { if (m->steinerleft > 0) { m->steinerleft--; } } else if (success == ENCROACHINGVERTEX) { undovertex(m, b); if (b->verbose > 1) { fprintf(stderr, " Rejecting (%.12g, %.12g).\n", newvertex[0], newvertex[1]); } vertexdealloc(m, newvertex); } else if (success == VIOLATINGVERTEX) { vertexdealloc(m, newvertex); } else { if (!b->quiet) { fprintf(stderr, "Warning: New vertex (%.12g, %.12g) falls on existing vertex.\n", newvertex[0], newvertex[1]); errorflag = 1; } vertexdealloc(m, newvertex); } } if (errorflag) { if (b->verbose) { fprintf(stderr, " The new vertex is at the circumcenter of triangle\n"); fprintf(stderr, " (%.12g, %.12g) (%.12g, %.12g) (%.12g, %.12g)\n", borg[0], borg[1], bdest[0], bdest[1], bapex[0], bapex[1]); } fprintf(stderr, "This probably means that I am trying to refine triangles\n"); fprintf(stderr, " to a smaller size than can be accommodated by the finite\n"); fprintf(stderr, " precision of floating point arithmetic. (You can be\n"); fprintf(stderr, " sure of this if I fail to terminate.)\n"); precisionerror(); } } } # 13549 "triangle.c" void enforcequality(m, b) struct mesh *m; struct behavior *b; { struct badtriang *badtri; int i; if (!b->quiet) { fprintf(stderr, "Adding Steiner points to enforce quality.\n"); } poolinit(&m->badsubsegs, sizeof(struct badsubseg), 252, POINTER, 0); if (b->verbose) { fprintf(stderr, " Looking for encroached subsegments.\n"); } tallyencs(m, b); if (b->verbose && (m->badsubsegs.items > 0)) { fprintf(stderr, " Splitting encroached subsegments.\n"); } splitencsegs(m, b, 0); if ((b->minangle > 0.0) || b->vararea || b->fixedarea || b->usertest) { poolinit(&m->badtriangles, sizeof(struct badtriang), 4092, POINTER, 0); for (i = 0; i < 64; i++) { m->queuefront[i] = (struct badtriang *) ((void *)0); } m->firstnonemptyq = -1; tallyfaces(m, b); poolinit(&m->flipstackers, sizeof(struct flipstacker), 252, POINTER, 0); m->checkquality = 1; if (b->verbose) { fprintf(stderr, " Splitting bad triangles.\n"); } while ((m->badtriangles.items > 0) && (m->steinerleft != 0)) { badtri = dequeuebadtriang(m); splittriangle(m, b, badtri); if (m->badsubsegs.items > 0) { enqueuebadtriang(m, b, badtri); splitencsegs(m, b, 1); } else { pooldealloc(&m->badtriangles, (int *) badtri); } } } if (!b->quiet && (m->badsubsegs.items > 0) && (m->steinerleft == 0)) { fprintf(stderr, "\nWarning: I ran out of Steiner points, but the mesh has\n"); if (m->badsubsegs.items == 1) { fprintf(stderr, " an encroached subsegment, and therefore might not be truly\n"); } else { fprintf(stderr, " %ld encroached subsegments, and therefore might not be truly\n" , m->badsubsegs.items); } fprintf(stderr, " Delaunay. If the Delaunay property is important to you,\n"); fprintf(stderr, " try increasing the number of Steiner points (controlled by\n"); fprintf(stderr, " the -S switch) slightly and try again.\n\n"); } } # 13646 "triangle.c" void highorder(m, b) struct mesh *m; struct behavior *b; { struct otri triangleloop, trisym; struct osub checkmark; vertex newvertex; vertex torg, tdest; int i; triangle ptr; subseg sptr; if (!b->quiet) { fprintf(stderr, "Adding vertices for second-order triangles.\n"); } m->vertices.deaditemstack = (int *) ((void *)0); traversalinit(&m->triangles); triangleloop.tri = triangletraverse(m); while (triangleloop.tri != (triangle *) ((void *)0)) { for (triangleloop.orient = 0; triangleloop.orient < 3; triangleloop.orient++) { ptr = (triangleloop).tri[(triangleloop).orient]; (trisym).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (trisym).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (trisym).orient);; if ((triangleloop.tri < trisym.tri) || (trisym.tri == m->dummytri)) { torg = (vertex) (triangleloop).tri[plus1mod3[(triangleloop).orient] + 3]; tdest = (vertex) (triangleloop).tri[minus1mod3[(triangleloop).orient] + 3]; newvertex = (vertex) poolalloc(&m->vertices); for (i = 0; i < 2 + m->nextras; i++) { newvertex[i] = 0.5 * (torg[i] + tdest[i]); } ((int *) (newvertex))[m->vertexmarkindex] = trisym.tri == m->dummytri; ((int *) (newvertex))[m->vertexmarkindex + 1] = trisym.tri == m->dummytri ? 2 : 1; if (b->usesegments) { sptr = (subseg) (triangleloop).tri[6 + (triangleloop).orient]; (checkmark).ssorient = (int) ((unsigned long) (sptr) & (unsigned long) 1l); (checkmark).ss = (subseg *) ((unsigned long) (sptr) & ~ (unsigned long) 3l); if (checkmark.ss != m->dummysub) { ((int *) (newvertex))[m->vertexmarkindex] = (* (int *) ((checkmark).ss + 6)); ((int *) (newvertex))[m->vertexmarkindex + 1] = 1; } } if (b->verbose > 1) { fprintf(stderr, " Creating (%.12g, %.12g).\n", newvertex[0], newvertex[1]); } triangleloop.tri[m->highorderindex + triangleloop.orient] = (triangle) newvertex; if (trisym.tri != m->dummytri) { trisym.tri[m->highorderindex + trisym.orient] = (triangle) newvertex; } } } triangleloop.tri = triangletraverse(m); } } # 14021 "triangle.c" void transfernodes(m, b, pointlist, pointattriblist, pointmarkerlist, numberofpoints, numberofpointattribs) struct mesh *m; struct behavior *b; double *pointlist; double *pointattriblist; int *pointmarkerlist; int numberofpoints; int numberofpointattribs; { vertex vertexloop; double x, y; int i, j; int coordindex; int attribindex; m->invertices = numberofpoints; m->mesh_dim = 2; m->nextras = numberofpointattribs; m->readnodefile = 0; if (m->invertices < 3) { fprintf(stderr, "Error: Input must have at least three input vertices.\n"); exit(1); } if (m->nextras == 0) { b->weighted = 0; } initializevertexpool(m, b); coordindex = 0; attribindex = 0; for (i = 0; i < m->invertices; i++) { vertexloop = (vertex) poolalloc(&m->vertices); x = vertexloop[0] = pointlist[coordindex++]; y = vertexloop[1] = pointlist[coordindex++]; for (j = 0; j < numberofpointattribs; j++) { vertexloop[2 + j] = pointattriblist[attribindex++]; } if (pointmarkerlist != (int *) ((void *)0)) { ((int *) (vertexloop))[m->vertexmarkindex] = pointmarkerlist[i]; } else { ((int *) (vertexloop))[m->vertexmarkindex] = 0; } ((int *) (vertexloop))[m->vertexmarkindex + 1] = 0; if (i == 0) { m->xmin = m->xmax = x; m->ymin = m->ymax = y; } else { m->xmin = (x < m->xmin) ? x : m->xmin; m->xmax = (x > m->xmax) ? x : m->xmax; m->ymin = (y < m->ymin) ? y : m->ymin; m->ymax = (y > m->ymax) ? y : m->ymax; } } m->xminextreme = 10 * m->xmin - 9 * m->xmax; } # 14258 "triangle.c" void writenodes(m, b, pointlist, pointattriblist, pointmarkerlist) struct mesh *m; struct behavior *b; double **pointlist; double **pointattriblist; int **pointmarkerlist; # 14282 "triangle.c" { double *plist; double *palist; int *pmlist; int coordindex; int attribindex; vertex vertexloop; long outvertices; int vertexnumber; int i; if (b->jettison) { outvertices = m->vertices.items - m->undeads; } else { outvertices = m->vertices.items; } if (!b->quiet) { fprintf(stderr, "Writing vertices.\n"); } if (*pointlist == (double *) ((void *)0)) { *pointlist = (double *) trimalloc(outvertices * 2 * sizeof(double)); } if ((m->nextras > 0) && (*pointattriblist == (double *) ((void *)0))) { *pointattriblist = (double *) trimalloc(outvertices * m->nextras * sizeof(double)); } if (!b->nobound && (*pointmarkerlist == (int *) ((void *)0))) { *pointmarkerlist = (int *) trimalloc(outvertices * sizeof(int)); } plist = *pointlist; palist = *pointattriblist; pmlist = *pointmarkerlist; coordindex = 0; attribindex = 0; # 14340 "triangle.c" traversalinit(&m->vertices); vertexnumber = b->firstnumber; vertexloop = vertextraverse(m); while (vertexloop != (vertex) ((void *)0)) { if (!b->jettison || (((int *) (vertexloop))[m->vertexmarkindex + 1] != -32767)) { plist[coordindex++] = vertexloop[0]; plist[coordindex++] = vertexloop[1]; for (i = 0; i < m->nextras; i++) { palist[attribindex++] = vertexloop[2 + i]; } if (!b->nobound) { pmlist[vertexnumber - b->firstnumber] = ((int *) (vertexloop))[m->vertexmarkindex]; } # 14373 "triangle.c" ((int *) (vertexloop))[m->vertexmarkindex] = vertexnumber; vertexnumber++; } vertexloop = vertextraverse(m); } } # 14397 "triangle.c" void numbernodes(m, b) struct mesh *m; struct behavior *b; { vertex vertexloop; int vertexnumber; traversalinit(&m->vertices); vertexnumber = b->firstnumber; vertexloop = vertextraverse(m); while (vertexloop != (vertex) ((void *)0)) { ((int *) (vertexloop))[m->vertexmarkindex] = vertexnumber; if (!b->jettison || (((int *) (vertexloop))[m->vertexmarkindex + 1] != -32767)) { vertexnumber++; } vertexloop = vertextraverse(m); } } # 14430 "triangle.c" void writeelements(m, b, trianglelist, triangleattriblist) struct mesh *m; struct behavior *b; int **trianglelist; double **triangleattriblist; # 14453 "triangle.c" { int *tlist; double *talist; int vertexindex; int attribindex; struct otri triangleloop; vertex p1, p2, p3; vertex mid1, mid2, mid3; long elementnumber; int i; if (!b->quiet) { fprintf(stderr, "Writing triangles.\n"); } if (*trianglelist == (int *) ((void *)0)) { *trianglelist = (int *) trimalloc(m->triangles.items * ((b->order + 1) * (b->order + 2) / 2) * sizeof(int)); } if ((m->eextras > 0) && (*triangleattriblist == (double *) ((void *)0))) { *triangleattriblist = (double *) trimalloc(m->triangles.items * m->eextras * sizeof(double)); } tlist = *trianglelist; talist = *triangleattriblist; vertexindex = 0; attribindex = 0; # 14501 "triangle.c" traversalinit(&m->triangles); triangleloop.tri = triangletraverse(m); triangleloop.orient = 0; elementnumber = b->firstnumber; while (triangleloop.tri != (triangle *) ((void *)0)) { p1 = (vertex) (triangleloop).tri[plus1mod3[(triangleloop).orient] + 3]; p2 = (vertex) (triangleloop).tri[minus1mod3[(triangleloop).orient] + 3]; p3 = (vertex) (triangleloop).tri[(triangleloop).orient + 3]; if (b->order == 1) { tlist[vertexindex++] = ((int *) (p1))[m->vertexmarkindex]; tlist[vertexindex++] = ((int *) (p2))[m->vertexmarkindex]; tlist[vertexindex++] = ((int *) (p3))[m->vertexmarkindex]; } else { mid1 = (vertex) triangleloop.tri[m->highorderindex + 1]; mid2 = (vertex) triangleloop.tri[m->highorderindex + 2]; mid3 = (vertex) triangleloop.tri[m->highorderindex]; tlist[vertexindex++] = ((int *) (p1))[m->vertexmarkindex]; tlist[vertexindex++] = ((int *) (p2))[m->vertexmarkindex]; tlist[vertexindex++] = ((int *) (p3))[m->vertexmarkindex]; tlist[vertexindex++] = ((int *) (mid1))[m->vertexmarkindex]; tlist[vertexindex++] = ((int *) (mid2))[m->vertexmarkindex]; tlist[vertexindex++] = ((int *) (mid3))[m->vertexmarkindex]; } for (i = 0; i < m->eextras; i++) { talist[attribindex++] = ((double *) (triangleloop).tri)[m->elemattribindex + (i)]; } triangleloop.tri = triangletraverse(m); elementnumber++; } } # 14570 "triangle.c" void writepoly(m, b, segmentlist, segmentmarkerlist) struct mesh *m; struct behavior *b; int **segmentlist; int **segmentmarkerlist; # 14599 "triangle.c" { int *slist; int *smlist; int index; struct osub subsegloop; vertex endpoint1, endpoint2; long subsegnumber; if (!b->quiet) { fprintf(stderr, "Writing segments.\n"); } if (*segmentlist == (int *) ((void *)0)) { *segmentlist = (int *) trimalloc(m->subsegs.items * 2 * sizeof(int)); } if (!b->nobound && (*segmentmarkerlist == (int *) ((void *)0))) { *segmentmarkerlist = (int *) trimalloc(m->subsegs.items * sizeof(int)); } slist = *segmentlist; smlist = *segmentmarkerlist; index = 0; # 14645 "triangle.c" traversalinit(&m->subsegs); subsegloop.ss = subsegtraverse(m); subsegloop.ssorient = 0; subsegnumber = b->firstnumber; while (subsegloop.ss != (subseg *) ((void *)0)) { endpoint1 = (vertex) (subsegloop).ss[2 + (subsegloop).ssorient]; endpoint2 = (vertex) (subsegloop).ss[3 - (subsegloop).ssorient]; slist[index++] = ((int *) (endpoint1))[m->vertexmarkindex]; slist[index++] = ((int *) (endpoint2))[m->vertexmarkindex]; if (!b->nobound) { smlist[subsegnumber - b->firstnumber] = (* (int *) ((subsegloop).ss + 6)); } # 14671 "triangle.c" subsegloop.ss = subsegtraverse(m); subsegnumber++; } # 14700 "triangle.c" } # 14714 "triangle.c" void writeedges(m, b, edgelist, edgemarkerlist) struct mesh *m; struct behavior *b; int **edgelist; int **edgemarkerlist; # 14737 "triangle.c" { int *elist; int *emlist; int index; struct otri triangleloop, trisym; struct osub checkmark; vertex p1, p2; long edgenumber; triangle ptr; subseg sptr; if (!b->quiet) { fprintf(stderr, "Writing edges.\n"); } if (*edgelist == (int *) ((void *)0)) { *edgelist = (int *) trimalloc(m->edges * 2 * sizeof(int)); } if (!b->nobound && (*edgemarkerlist == (int *) ((void *)0))) { *edgemarkerlist = (int *) trimalloc(m->edges * sizeof(int)); } elist = *edgelist; emlist = *edgemarkerlist; index = 0; # 14780 "triangle.c" traversalinit(&m->triangles); triangleloop.tri = triangletraverse(m); edgenumber = b->firstnumber; while (triangleloop.tri != (triangle *) ((void *)0)) { for (triangleloop.orient = 0; triangleloop.orient < 3; triangleloop.orient++) { ptr = (triangleloop).tri[(triangleloop).orient]; (trisym).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (trisym).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (trisym).orient);; if ((triangleloop.tri < trisym.tri) || (trisym.tri == m->dummytri)) { p1 = (vertex) (triangleloop).tri[plus1mod3[(triangleloop).orient] + 3]; p2 = (vertex) (triangleloop).tri[minus1mod3[(triangleloop).orient] + 3]; elist[index++] = ((int *) (p1))[m->vertexmarkindex]; elist[index++] = ((int *) (p2))[m->vertexmarkindex]; if (b->nobound) { } else { if (b->usesegments) { sptr = (subseg) (triangleloop).tri[6 + (triangleloop).orient]; (checkmark).ssorient = (int) ((unsigned long) (sptr) & (unsigned long) 1l); (checkmark).ss = (subseg *) ((unsigned long) (sptr) & ~ (unsigned long) 3l); if (checkmark.ss == m->dummysub) { emlist[edgenumber - b->firstnumber] = 0; } else { emlist[edgenumber - b->firstnumber] = (* (int *) ((checkmark).ss + 6)); } } else { emlist[edgenumber - b->firstnumber] = trisym.tri == m->dummytri; } } edgenumber++; } } triangleloop.tri = triangletraverse(m); } } # 14869 "triangle.c" void writevoronoi(m, b, vpointlist, vpointattriblist, vpointmarkerlist, vedgelist, vedgemarkerlist, vnormlist) struct mesh *m; struct behavior *b; double **vpointlist; double **vpointattriblist; int **vpointmarkerlist; int **vedgelist; int **vedgemarkerlist; double **vnormlist; # 14898 "triangle.c" { double *plist; double *palist; int *elist; double *normlist; int coordindex; int attribindex; struct otri triangleloop, trisym; vertex torg, tdest, tapex; double circumcenter[2]; double xi, eta; double dum; long vnodenumber, vedgenumber; int p1, p2; int i; triangle ptr; if (!b->quiet) { fprintf(stderr, "Writing Voronoi vertices.\n"); } if (*vpointlist == (double *) ((void *)0)) { *vpointlist = (double *) trimalloc(m->triangles.items * 2 * sizeof(double)); } if (*vpointattriblist == (double *) ((void *)0)) { *vpointattriblist = (double *) trimalloc(m->triangles.items * m->nextras * sizeof(double)); } *vpointmarkerlist = (int *) ((void *)0); plist = *vpointlist; palist = *vpointattriblist; coordindex = 0; attribindex = 0; # 14951 "triangle.c" traversalinit(&m->triangles); triangleloop.tri = triangletraverse(m); triangleloop.orient = 0; vnodenumber = b->firstnumber; while (triangleloop.tri != (triangle *) ((void *)0)) { torg = (vertex) (triangleloop).tri[plus1mod3[(triangleloop).orient] + 3]; tdest = (vertex) (triangleloop).tri[minus1mod3[(triangleloop).orient] + 3]; tapex = (vertex) (triangleloop).tri[(triangleloop).orient + 3]; findcircumcenter(m, b, torg, tdest, tapex, circumcenter, &xi, &eta, &dum); plist[coordindex++] = circumcenter[0]; plist[coordindex++] = circumcenter[1]; for (i = 2; i < 2 + m->nextras; i++) { palist[attribindex++] = torg[i] + xi * (tdest[i] - torg[i]) + eta * (tapex[i] - torg[i]); } # 14981 "triangle.c" * (int *) (triangleloop.tri + 6) = (int) vnodenumber; triangleloop.tri = triangletraverse(m); vnodenumber++; } if (!b->quiet) { fprintf(stderr, "Writing Voronoi edges.\n"); } if (*vedgelist == (int *) ((void *)0)) { *vedgelist = (int *) trimalloc(m->edges * 2 * sizeof(int)); } *vedgemarkerlist = (int *) ((void *)0); if (*vnormlist == (double *) ((void *)0)) { *vnormlist = (double *) trimalloc(m->edges * 2 * sizeof(double)); } elist = *vedgelist; normlist = *vnormlist; coordindex = 0; # 15019 "triangle.c" traversalinit(&m->triangles); triangleloop.tri = triangletraverse(m); vedgenumber = b->firstnumber; while (triangleloop.tri != (triangle *) ((void *)0)) { for (triangleloop.orient = 0; triangleloop.orient < 3; triangleloop.orient++) { ptr = (triangleloop).tri[(triangleloop).orient]; (trisym).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (trisym).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (trisym).orient);; if ((triangleloop.tri < trisym.tri) || (trisym.tri == m->dummytri)) { p1 = * (int *) (triangleloop.tri + 6); if (trisym.tri == m->dummytri) { torg = (vertex) (triangleloop).tri[plus1mod3[(triangleloop).orient] + 3]; tdest = (vertex) (triangleloop).tri[minus1mod3[(triangleloop).orient] + 3]; elist[coordindex] = p1; normlist[coordindex++] = tdest[1] - torg[1]; elist[coordindex] = -1; normlist[coordindex++] = torg[0] - tdest[0]; } else { p2 = * (int *) (trisym.tri + 6); elist[coordindex] = p1; normlist[coordindex++] = 0.0; elist[coordindex] = p2; normlist[coordindex++] = 0.0; } vedgenumber++; } } triangleloop.tri = triangletraverse(m); } } void writeneighbors(m, b, neighborlist) struct mesh *m; struct behavior *b; int **neighborlist; # 15102 "triangle.c" { int *nlist; int index; struct otri triangleloop, trisym; long elementnumber; int neighbor1, neighbor2, neighbor3; triangle ptr; if (!b->quiet) { fprintf(stderr, "Writing neighbors.\n"); } if (*neighborlist == (int *) ((void *)0)) { *neighborlist = (int *) trimalloc(m->triangles.items * 3 * sizeof(int)); } nlist = *neighborlist; index = 0; # 15137 "triangle.c" traversalinit(&m->triangles); triangleloop.tri = triangletraverse(m); triangleloop.orient = 0; elementnumber = b->firstnumber; while (triangleloop.tri != (triangle *) ((void *)0)) { * (int *) (triangleloop.tri + 6) = (int) elementnumber; triangleloop.tri = triangletraverse(m); elementnumber++; } * (int *) (m->dummytri + 6) = -1; traversalinit(&m->triangles); triangleloop.tri = triangletraverse(m); elementnumber = b->firstnumber; while (triangleloop.tri != (triangle *) ((void *)0)) { triangleloop.orient = 1; ptr = (triangleloop).tri[(triangleloop).orient]; (trisym).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (trisym).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (trisym).orient);; neighbor1 = * (int *) (trisym.tri + 6); triangleloop.orient = 2; ptr = (triangleloop).tri[(triangleloop).orient]; (trisym).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (trisym).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (trisym).orient);; neighbor2 = * (int *) (trisym.tri + 6); triangleloop.orient = 0; ptr = (triangleloop).tri[(triangleloop).orient]; (trisym).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); (trisym).tri = (triangle *) ((unsigned long) (ptr) ^ (unsigned long) (trisym).orient);; neighbor3 = * (int *) (trisym.tri + 6); nlist[index++] = neighbor1; nlist[index++] = neighbor2; nlist[index++] = neighbor3; triangleloop.tri = triangletraverse(m); elementnumber++; } } # 15272 "triangle.c" void quality_statistics(m, b) struct mesh *m; struct behavior *b; { struct otri triangleloop; vertex p[3]; double cossquaretable[8]; double ratiotable[16]; double dx[3], dy[3]; double edgelength[3]; double dotproduct; double cossquare; double triarea; double shortest, longest; double trilongest2; double smallestarea, biggestarea; double triminaltitude2; double minaltitude; double triaspect2; double worstaspect; double smallestangle, biggestangle; double radconst, degconst; int angletable[18]; int aspecttable[16]; int aspectindex; int tendegree; int acutebiggest; int i, ii, j, k; fprintf(stderr, "Mesh quality statistics:\n\n"); radconst = 3.141592653589793238462643383279502884197169399375105820974944592308 / 18.0; degconst = 180.0 / 3.141592653589793238462643383279502884197169399375105820974944592308; for (i = 0; i < 8; i++) { cossquaretable[i] = cos(radconst * (double) (i + 1)); cossquaretable[i] = cossquaretable[i] * cossquaretable[i]; } for (i = 0; i < 18; i++) { angletable[i] = 0; } ratiotable[0] = 1.5; ratiotable[1] = 2.0; ratiotable[2] = 2.5; ratiotable[3] = 3.0; ratiotable[4] = 4.0; ratiotable[5] = 6.0; ratiotable[6] = 10.0; ratiotable[7] = 15.0; ratiotable[8] = 25.0; ratiotable[9] = 50.0; ratiotable[10] = 100.0; ratiotable[11] = 300.0; ratiotable[12] = 1000.0; ratiotable[13] = 10000.0; ratiotable[14] = 100000.0; ratiotable[15] = 0.0; for (i = 0; i < 16; i++) { aspecttable[i] = 0; } worstaspect = 0.0; minaltitude = m->xmax - m->xmin + m->ymax - m->ymin; minaltitude = minaltitude * minaltitude; shortest = minaltitude; longest = 0.0; smallestarea = minaltitude; biggestarea = 0.0; worstaspect = 0.0; smallestangle = 0.0; biggestangle = 2.0; acutebiggest = 1; traversalinit(&m->triangles); triangleloop.tri = triangletraverse(m); triangleloop.orient = 0; while (triangleloop.tri != (triangle *) ((void *)0)) { p[0] = (vertex) (triangleloop).tri[plus1mod3[(triangleloop).orient] + 3]; p[1] = (vertex) (triangleloop).tri[minus1mod3[(triangleloop).orient] + 3]; p[2] = (vertex) (triangleloop).tri[(triangleloop).orient + 3]; trilongest2 = 0.0; for (i = 0; i < 3; i++) { j = plus1mod3[i]; k = minus1mod3[i]; dx[i] = p[j][0] - p[k][0]; dy[i] = p[j][1] - p[k][1]; edgelength[i] = dx[i] * dx[i] + dy[i] * dy[i]; if (edgelength[i] > trilongest2) { trilongest2 = edgelength[i]; } if (edgelength[i] > longest) { longest = edgelength[i]; } if (edgelength[i] < shortest) { shortest = edgelength[i]; } } triarea = counterclockwise(m, b, p[0], p[1], p[2]); if (triarea < smallestarea) { smallestarea = triarea; } if (triarea > biggestarea) { biggestarea = triarea; } triminaltitude2 = triarea * triarea / trilongest2; if (triminaltitude2 < minaltitude) { minaltitude = triminaltitude2; } triaspect2 = trilongest2 / triminaltitude2; if (triaspect2 > worstaspect) { worstaspect = triaspect2; } aspectindex = 0; while ((triaspect2 > ratiotable[aspectindex] * ratiotable[aspectindex]) && (aspectindex < 15)) { aspectindex++; } aspecttable[aspectindex]++; for (i = 0; i < 3; i++) { j = plus1mod3[i]; k = minus1mod3[i]; dotproduct = dx[j] * dx[k] + dy[j] * dy[k]; cossquare = dotproduct * dotproduct / (edgelength[j] * edgelength[k]); tendegree = 8; for (ii = 7; ii >= 0; ii--) { if (cossquare > cossquaretable[ii]) { tendegree = ii; } } if (dotproduct <= 0.0) { angletable[tendegree]++; if (cossquare > smallestangle) { smallestangle = cossquare; } if (acutebiggest && (cossquare < biggestangle)) { biggestangle = cossquare; } } else { angletable[17 - tendegree]++; if (acutebiggest || (cossquare > biggestangle)) { biggestangle = cossquare; acutebiggest = 0; } } } triangleloop.tri = triangletraverse(m); } shortest = sqrt(shortest); longest = sqrt(longest); minaltitude = sqrt(minaltitude); worstaspect = sqrt(worstaspect); smallestarea *= 0.5; biggestarea *= 0.5; if (smallestangle >= 1.0) { smallestangle = 0.0; } else { smallestangle = degconst * acos(sqrt(smallestangle)); } if (biggestangle >= 1.0) { biggestangle = 180.0; } else { if (acutebiggest) { biggestangle = degconst * acos(sqrt(biggestangle)); } else { biggestangle = 180.0 - degconst * acos(sqrt(biggestangle)); } } fprintf(stderr, " Smallest area: %16.5g | Largest area: %16.5g\n", smallestarea, biggestarea); fprintf(stderr, " Shortest edge: %16.5g | Longest edge: %16.5g\n", shortest, longest); fprintf(stderr, " Shortest altitude: %12.5g | Largest aspect ratio: %8.5g\n\n", minaltitude, worstaspect); fprintf(stderr, " Triangle aspect ratio histogram:\n"); fprintf(stderr, " 1.1547 - %-6.6g : %8d | %6.6g - %-6.6g : %8d\n", ratiotable[0], aspecttable[0], ratiotable[7], ratiotable[8], aspecttable[8]); for (i = 1; i < 7; i++) { fprintf(stderr, " %6.6g - %-6.6g : %8d | %6.6g - %-6.6g : %8d\n", ratiotable[i - 1], ratiotable[i], aspecttable[i], ratiotable[i + 7], ratiotable[i + 8], aspecttable[i + 8]); } fprintf(stderr, " %6.6g - %-6.6g : %8d | %6.6g - : %8d\n", ratiotable[6], ratiotable[7], aspecttable[7], ratiotable[14], aspecttable[15]); fprintf(stderr, " (Aspect ratio is longest edge divided by shortest altitude)\n\n"); fprintf(stderr, " Smallest angle: %15.5g | Largest angle: %15.5g\n\n", smallestangle, biggestangle); fprintf(stderr, " Angle histogram:\n"); for (i = 0; i < 9; i++) { fprintf(stderr, " %3d - %3d degrees: %8d | %3d - %3d degrees: %8d\n", i * 10, i * 10 + 10, angletable[i], i * 10 + 90, i * 10 + 100, angletable[i + 9]); } fprintf(stderr, "\n"); } # 15479 "triangle.c" void statistics(m, b) struct mesh *m; struct behavior *b; { fprintf(stderr, "\nStatistics:\n\n"); fprintf(stderr, " Input vertices: %d\n", m->invertices); if (b->refine) { fprintf(stderr, " Input triangles: %d\n", m->inelements); } if (b->poly) { fprintf(stderr, " Input segments: %d\n", m->insegments); if (!b->refine) { fprintf(stderr, " Input holes: %d\n", m->holes); } } fprintf(stderr, "\n Mesh vertices: %ld\n", m->vertices.items - m->undeads); fprintf(stderr, " Mesh triangles: %ld\n", m->triangles.items); fprintf(stderr, " Mesh edges: %ld\n", m->edges); fprintf(stderr, " Mesh exterior boundary edges: %ld\n", m->hullsize); if (b->poly || b->refine) { fprintf(stderr, " Mesh interior boundary edges: %ld\n", m->subsegs.items - m->hullsize); fprintf(stderr, " Mesh subsegments (constrained edges): %ld\n", m->subsegs.items); } fprintf(stderr, "\n"); if (b->verbose) { quality_statistics(m, b); fprintf(stderr, "Memory allocation statistics:\n\n"); fprintf(stderr, " Maximum number of vertices: %ld\n", m->vertices.maxitems); fprintf(stderr, " Maximum number of triangles: %ld\n", m->triangles.maxitems); if (m->subsegs.maxitems > 0) { fprintf(stderr, " Maximum number of subsegments: %ld\n", m->subsegs.maxitems); } if (m->viri.maxitems > 0) { fprintf(stderr, " Maximum number of viri: %ld\n", m->viri.maxitems); } if (m->badsubsegs.maxitems > 0) { fprintf(stderr, " Maximum number of encroached subsegments: %ld\n", m->badsubsegs.maxitems); } if (m->badtriangles.maxitems > 0) { fprintf(stderr, " Maximum number of bad triangles: %ld\n", m->badtriangles.maxitems); } if (m->flipstackers.maxitems > 0) { fprintf(stderr, " Maximum number of stacked triangle flips: %ld\n", m->flipstackers.maxitems); } if (m->splaynodes.maxitems > 0) { fprintf(stderr, " Maximum number of splay tree nodes: %ld\n", m->splaynodes.maxitems); } fprintf(stderr, " Approximate heap memory use (bytes): %ld\n\n", m->vertices.maxitems * m->vertices.itembytes + m->triangles.maxitems * m->triangles.itembytes + m->subsegs.maxitems * m->subsegs.itembytes + m->viri.maxitems * m->viri.itembytes + m->badsubsegs.maxitems * m->badsubsegs.itembytes + m->badtriangles.maxitems * m->badtriangles.itembytes + m->flipstackers.maxitems * m->flipstackers.itembytes + m->splaynodes.maxitems * m->splaynodes.itembytes); fprintf(stderr, "Algorithmic statistics:\n\n"); if (!b->weighted) { fprintf(stderr, " Number of incircle tests: %ld\n", m->incirclecount); } else { fprintf(stderr, " Number of 3D orientation tests: %ld\n", m->orient3dcount); } fprintf(stderr, " Number of 2D orientation tests: %ld\n", m->counterclockcount); if (m->hyperbolacount > 0) { fprintf(stderr, " Number of right-of-hyperbola tests: %ld\n", m->hyperbolacount); } if (m->circletopcount > 0) { fprintf(stderr, " Number of circle top computations: %ld\n", m->circletopcount); } if (m->circumcentercount > 0) { fprintf(stderr, " Number of triangle circumcenter computations: %ld\n", m->circumcentercount); } fprintf(stderr, "\n"); } } # 15600 "triangle.c" void triangulate(triswitches, in, out, vorout) char *triswitches; struct triangulateio *in; struct triangulateio *out; struct triangulateio *vorout; # 15619 "triangle.c" { struct mesh m; struct behavior b; double *holearray; double *regionarray; struct timeval tv0, tv1, tv2, tv3, tv4, tv5, tv6; struct timezone tz; gettimeofday(&tv0, &tz); triangleinit(&m); parsecommandline(1, &triswitches, &b); m.steinerleft = b.steiner; transfernodes(&m, &b, in->pointlist, in->pointattributelist, in->pointmarkerlist, in->numberofpoints, in->numberofpointattributes); if (!b.quiet) { gettimeofday(&tv1, &tz); } if (b.refine) { m.hullsize = reconstruct(&m, &b, in->trianglelist, in->triangleattributelist, in->trianglearealist, in->numberoftriangles, in->numberofcorners, in->numberoftriangleattributes, in->segmentlist, in->segmentmarkerlist, in->numberofsegments); } else { m.hullsize = delaunay(&m, &b); } if (!b.quiet) { gettimeofday(&tv2, &tz); if (b.refine) { fprintf(stderr, "Mesh reconstruction"); } else { fprintf(stderr, "Delaunay"); } fprintf(stderr, " milliseconds: %ld\n", 1000l * (tv2.tv_sec - tv1.tv_sec) + (tv2.tv_usec - tv1.tv_usec) / 1000l); } m.infvertex1 = (vertex) ((void *)0); m.infvertex2 = (vertex) ((void *)0); m.infvertex3 = (vertex) ((void *)0); if (b.usesegments) { m.checksegments = 1; if (!b.refine) { formskeleton(&m, &b, in->segmentlist, in->segmentmarkerlist, in->numberofsegments); } } if (!b.quiet) { gettimeofday(&tv3, &tz); if (b.usesegments && !b.refine) { fprintf(stderr, "Segment milliseconds: %ld\n", 1000l * (tv3.tv_sec - tv2.tv_sec) + (tv3.tv_usec - tv2.tv_usec) / 1000l); } } if (b.poly && (m.triangles.items > 0)) { holearray = in->holelist; m.holes = in->numberofholes; regionarray = in->regionlist; m.regions = in->numberofregions; if (!b.refine) { carveholes(&m, &b, holearray, m.holes, regionarray, m.regions); } } else { m.holes = 0; m.regions = 0; } if (!b.quiet) { gettimeofday(&tv4, &tz); if (b.poly && !b.refine) { fprintf(stderr, "Hole milliseconds: %ld\n", 1000l * (tv4.tv_sec - tv3.tv_sec) + (tv4.tv_usec - tv3.tv_usec) / 1000l); } } if (b.quality && (m.triangles.items > 0)) { enforcequality(&m, &b); } if (!b.quiet) { gettimeofday(&tv5, &tz); if (b.quality) { fprintf(stderr, "Quality milliseconds: %ld\n", 1000l * (tv5.tv_sec - tv4.tv_sec) + (tv5.tv_usec - tv4.tv_usec) / 1000l); } } m.edges = (3l * m.triangles.items + m.hullsize) / 2l; if (b.order > 1) { highorder(&m, &b); } if (!b.quiet) { fprintf(stderr, "\n"); } out->numberofpoints = m.vertices.items; out->numberofpointattributes = m.nextras; out->numberoftriangles = m.triangles.items; out->numberofcorners = (b.order + 1) * (b.order + 2) / 2; out->numberoftriangleattributes = m.eextras; out->numberofedges = m.edges; if (b.usesegments) { out->numberofsegments = m.subsegs.items; } else { out->numberofsegments = m.hullsize; } if (vorout != (struct triangulateio *) ((void *)0)) { vorout->numberofpoints = m.triangles.items; vorout->numberofpointattributes = m.nextras; vorout->numberofedges = m.edges; } if (b.nonodewritten || (b.noiterationnum && m.readnodefile)) { if (!b.quiet) { fprintf(stderr, "NOT writing vertices.\n"); } numbernodes(&m, &b); } else { writenodes(&m, &b, &out->pointlist, &out->pointattributelist, &out->pointmarkerlist); } if (b.noelewritten) { if (!b.quiet) { fprintf(stderr, "NOT writing triangles.\n"); } } else { writeelements(&m, &b, &out->trianglelist, &out->triangleattributelist); } if (b.poly || b.convex) { if (b.nopolywritten || b.noiterationnum) { if (!b.quiet) { fprintf(stderr, "NOT writing segments.\n"); } } else { writepoly(&m, &b, &out->segmentlist, &out->segmentmarkerlist); out->numberofholes = m.holes; out->numberofregions = m.regions; if (b.poly) { out->holelist = in->holelist; out->regionlist = in->regionlist; } else { out->holelist = (double *) ((void *)0); out->regionlist = (double *) ((void *)0); } } } # 15881 "triangle.c" if (b.edgesout) { writeedges(&m, &b, &out->edgelist, &out->edgemarkerlist); } if (b.voronoi) { writevoronoi(&m, &b, &vorout->pointlist, &vorout->pointattributelist, &vorout->pointmarkerlist, &vorout->edgelist, &vorout->edgemarkerlist, &vorout->normlist); } if (b.neighbors) { writeneighbors(&m, &b, &out->neighborlist); } if (!b.quiet) { gettimeofday(&tv6, &tz); fprintf(stderr, "\nOutput milliseconds: %ld\n", 1000l * (tv6.tv_sec - tv5.tv_sec) + (tv6.tv_usec - tv5.tv_usec) / 1000l); fprintf(stderr, "Total running milliseconds: %ld\n", 1000l * (tv6.tv_sec - tv0.tv_sec) + (tv6.tv_usec - tv0.tv_usec) / 1000l); statistics(&m, &b); } if (b.docheck) { checkmesh(&m, &b); checkdelaunay(&m, &b); } triangledeinit(&m, &b); }
kthyng/octant
octant/src/gridgen/delaunay.c
<reponame>kthyng/octant<filename>octant/src/gridgen/delaunay.c<gh_stars>10-100 /****************************************************************************** * * File: delaunay.c * * Created: 04/08/2000 * * Author: <NAME> * CSIRO Marine Research * * Purpose: Delaunay triangulation - a wrapper to triangulate() * * Description: None * * Revisions: 10/06/2003 PS: delaunay_build(); delaunay_destroy(); * struct delaunay: from now on, only shallow copy of the * input data is contained in struct delaunay. This saves * memory and is consistent with libcsa. * *****************************************************************************/ #include <stdlib.h> #include <stdio.h> #include <assert.h> #include <math.h> #include <string.h> #include <limits.h> #include <float.h> #include "triangle.h" #include "istack.h" #include "nan.h" #include "delaunay.h" #include "nn.h" #include "nn_internal.h" /* * This parameter is used in search of tricircles containing a given point: * if there are no more triangles than N_SEARCH_TURNON * do linear search * else * do more complicated stuff */ #define N_SEARCH_TURNON 20 static void tio_init(struct triangulateio* tio) { tio->pointlist = NULL; tio->pointattributelist = NULL; tio->pointmarkerlist = NULL; tio->numberofpoints = 0; tio->numberofpointattributes = 0; tio->trianglelist = NULL; tio->triangleattributelist = NULL; tio->trianglearealist = NULL; tio->neighborlist = NULL; tio->numberoftriangles = 0; tio->numberofcorners = 0; tio->numberoftriangleattributes = 0; tio->segmentlist = 0; tio->segmentmarkerlist = NULL; tio->numberofsegments = 0; tio->holelist = NULL; tio->numberofholes = 0; tio->regionlist = NULL; tio->numberofregions = 0; tio->edgelist = NULL; tio->edgemarkerlist = NULL; tio->normlist = NULL; tio->numberofedges = 0; } static void tio_destroy(struct triangulateio* tio) { if (tio->pointlist != NULL) free(tio->pointlist); if (tio->pointattributelist != NULL) free(tio->pointattributelist); if (tio->pointmarkerlist != NULL) free(tio->pointmarkerlist); if (tio->trianglelist != NULL) free(tio->trianglelist); if (tio->triangleattributelist != NULL) free(tio->triangleattributelist); if (tio->trianglearealist != NULL) free(tio->trianglearealist); if (tio->neighborlist != NULL) free(tio->neighborlist); if (tio->segmentlist != NULL) free(tio->segmentlist); if (tio->segmentmarkerlist != NULL) free(tio->segmentmarkerlist); if (tio->holelist != NULL) free(tio->holelist); if (tio->regionlist != NULL) free(tio->regionlist); if (tio->edgelist != NULL) free(tio->edgelist); if (tio->edgemarkerlist != NULL) free(tio->edgemarkerlist); if (tio->normlist != NULL) free(tio->normlist); } static delaunay* delaunay_create() { delaunay* d = malloc(sizeof(delaunay)); d->npoints = 0; d->points = NULL; d->xmin = DBL_MAX; d->xmax = -DBL_MAX; d->ymin = DBL_MAX; d->ymax = -DBL_MAX; d->ntriangles = 0; d->triangles = NULL; d->circles = NULL; d->neighbours = NULL; d->n_point_triangles = NULL; d->point_triangles = NULL; d->nedges = 0; d->edges = NULL; d->flags = NULL; d->first_id = -1; d->t_in = NULL; d->t_out = NULL; return d; } static void tio2delaunay(struct triangulateio* tio_out, delaunay* d) { int i, j; /* * I assume that all input points appear in tio_out in the same order as * they were written to tio_in. I have seen no exceptions so far, even * if duplicate points were presented. Just in case, let us make a couple * of checks. */ assert(tio_out->numberofpoints == d->npoints); assert(tio_out->pointlist[2 * d->npoints - 2] == d->points[d->npoints - 1].x && tio_out->pointlist[2 * d->npoints - 1] == d->points[d->npoints - 1].y); for (i = 0, j = 0; i < d->npoints; ++i) { point* p = &d->points[i]; if (p->x < d->xmin) d->xmin = p->x; if (p->x > d->xmax) d->xmax = p->x; if (p->y < d->ymin) d->ymin = p->y; if (p->y > d->ymax) d->ymax = p->y; } if (nn_verbose) { fprintf(stderr, "input:\n"); for (i = 0, j = 0; i < d->npoints; ++i) { point* p = &d->points[i]; fprintf(stderr, " %d: %15.7g %15.7g %15.7g\n", i, p->x, p->y, p->z); } } d->ntriangles = tio_out->numberoftriangles; if (d->ntriangles > 0) { d->triangles = malloc(d->ntriangles * sizeof(triangle)); d->neighbours = malloc(d->ntriangles * sizeof(triangle_neighbours)); d->circles = malloc(d->ntriangles * sizeof(circle)); d->n_point_triangles = calloc(d->npoints, sizeof(int)); d->point_triangles = malloc(d->npoints * sizeof(int*)); d->flags = calloc(d->ntriangles, sizeof(int)); } if (nn_verbose) fprintf(stderr, "triangles:\n"); for (i = 0; i < d->ntriangles; ++i) { int offset = i * 3; triangle* t = &d->triangles[i]; triangle_neighbours* n = &d->neighbours[i]; circle* c = &d->circles[i]; t->vids[0] = tio_out->trianglelist[offset]; t->vids[1] = tio_out->trianglelist[offset + 1]; t->vids[2] = tio_out->trianglelist[offset + 2]; n->tids[0] = tio_out->neighborlist[offset]; n->tids[1] = tio_out->neighborlist[offset + 1]; n->tids[2] = tio_out->neighborlist[offset + 2]; assert(circle_build1(c, &d->points[t->vids[0]], &d->points[t->vids[1]], &d->points[t->vids[2]])); if (nn_verbose) fprintf(stderr, " %d: (%d,%d,%d)\n", i, t->vids[0], t->vids[1], t->vids[2]); } for (i = 0; i < d->ntriangles; ++i) { triangle* t = &d->triangles[i]; for (j = 0; j < 3; ++j) d->n_point_triangles[t->vids[j]]++; } if (d->ntriangles > 0) { for (i = 0; i < d->npoints; ++i) { if (d->n_point_triangles[i] > 0) d->point_triangles[i] = malloc(d->n_point_triangles[i] * sizeof(int)); else d->point_triangles[i] = NULL; d->n_point_triangles[i] = 0; } } for (i = 0; i < d->ntriangles; ++i) { triangle* t = &d->triangles[i]; for (j = 0; j < 3; ++j) { int vid = t->vids[j]; d->point_triangles[vid][d->n_point_triangles[vid]] = i; d->n_point_triangles[vid]++; } } if (tio_out->edgelist != NULL) { d->nedges = tio_out->numberofedges; d->edges = malloc(d->nedges * 2 * sizeof(int)); memcpy(d->edges, tio_out->edgelist, d->nedges * 2 * sizeof(int)); } } /* Builds Delaunay triangulation of the given array of points. * * @param np Number of points * @param points Array of points [np] (input) * @param ns Number of forced segments * @param segments Array of (forced) segment endpoint indices [2*ns] * @param nh Number of holes * @param holes Array of hole (x,y) coordinates [2*nh] * @return Delaunay triangulation structure with triangulation results */ delaunay* delaunay_build(int np, point points[], int ns, int segments[], int nh, double holes[]) { delaunay* d = delaunay_create(); struct triangulateio tio_in; struct triangulateio tio_out; char cmd[64] = "eznC"; int i, j; assert(sizeof(REAL) == sizeof(double)); tio_init(&tio_in); if (np == 0) { free(d); return NULL; } tio_in.pointlist = malloc(np * 2 * sizeof(double)); tio_in.numberofpoints = np; for (i = 0, j = 0; i < np; ++i) { tio_in.pointlist[j++] = points[i].x; tio_in.pointlist[j++] = points[i].y; } if (ns > 0) { tio_in.segmentlist = malloc(ns * 2 * sizeof(int)); tio_in.numberofsegments = ns; memcpy(tio_in.segmentlist, segments, ns * 2 * sizeof(int)); } if (nh > 0) { tio_in.holelist = malloc(nh * 2 * sizeof(double)); tio_in.numberofholes = nh; memcpy(tio_in.holelist, holes, nh * 2 * sizeof(double)); } tio_init(&tio_out); if (!nn_verbose) strcat(cmd, "Q"); else if (nn_verbose > 1) strcat(cmd, "VV"); if (ns != 0) strcat(cmd, "p"); if (nn_verbose) fflush(stderr); /* * climax */ triangulate(cmd, &tio_in, &tio_out, NULL); if (nn_verbose) fflush(stderr); d->npoints = np; d->points = points; tio2delaunay(&tio_out, d); tio_destroy(&tio_in); tio_destroy(&tio_out); return d; } /* Destroys Delaunay triangulation. * * @param d Structure to be destroyed */ void delaunay_destroy(delaunay* d) { if (d == NULL) return; if (d->point_triangles != NULL) { int i; for (i = 0; i < d->npoints; ++i) if (d->point_triangles[i] != NULL) free(d->point_triangles[i]); free(d->point_triangles); } if (d->nedges > 0) free(d->edges); if (d->n_point_triangles != NULL) free(d->n_point_triangles); if (d->flags != NULL) free(d->flags); if (d->circles != NULL) free(d->circles); if (d->neighbours != NULL) free(d->neighbours); if (d->triangles != NULL) free(d->triangles); if (d->t_in != NULL) istack_destroy(d->t_in); if (d->t_out != NULL) istack_destroy(d->t_out); free(d); } /* Returns whether the point p is on the right side of the vector (p0, p1). */ static int onrightside(point* p, point* p0, point* p1) { return (p1->x - p->x) * (p0->y - p->y) > (p0->x - p->x) * (p1->y - p->y); } /* Finds triangle specified point belongs to (if any). * * @param d Delaunay triangulation * @param p Point to be mapped * @param seed Triangle index to start with * @return Triangle id if successful, -1 otherwhile */ int delaunay_xytoi(delaunay* d, point* p, int id) { triangle* t; int i; if (p->x < d->xmin || p->x > d->xmax || p->y < d->ymin || p->y > d->ymax) return -1; if (id < 0 || id > d->ntriangles) id = 0; t = &d->triangles[id]; do { for (i = 0; i < 3; ++i) { int i1 = (i + 1) % 3; if (onrightside(p, &d->points[t->vids[i]], &d->points[t->vids[i1]])) { id = d->neighbours[id].tids[(i + 2) % 3]; if (id < 0) return id; t = &d->triangles[id]; break; } } } while (i < 3); return id; } /* Finds all tricircles specified point belongs to. * * @param d Delaunay triangulation * @param p Point to be mapped * @param n Pointer to the number of tricircles within `d' containing `p' * (output) * @param out Pointer to an array of indices of the corresponding triangles * [n] (output) * * There is a standard search procedure involving search through triangle * neighbours (not through vertex neighbours). It must be a bit faster due to * the smaller number of triangle neighbours (3 per triangle) but may fail * for a point outside convex hall. * * We may wish to modify this procedure in future: first check if the point * is inside the convex hall, and depending on that use one of the two * search algorithms. It not 100% clear though whether this will lead to a * substantial speed gains because of the check on convex hall involved. */ void delaunay_circles_find(delaunay* d, point* p, int* n, int** out) { /* * This flag was introduced as a hack to handle some degenerate cases. It * is set to 1 only if the triangle associated with the first circle is * already known to contain the point. In this case the circle is assumed * to contain the point without a check. In my practice this turned * useful in some cases when point p coincided with one of the vertices * of a thin triangle. */ int contains = 0; int i; if (d->t_in == NULL) { d->t_in = istack_create(); d->t_out = istack_create(); } /* * if there are only a few data points, do linear search */ if (d->ntriangles <= N_SEARCH_TURNON) { istack_reset(d->t_out); for (i = 0; i < d->ntriangles; ++i) { if (circle_contains(&d->circles[i], p)) { istack_push(d->t_out, i); } } *n = d->t_out->n; *out = d->t_out->v; return; } /* * otherwise, do a more complicated stuff */ /* * It is important to have a reasonable seed here. If the last search * was successful -- start with the last found tricircle, otherwhile (i) * try to find a triangle containing p; if fails then (ii) check * tricircles from the last search; if fails then (iii) make linear * search through all tricircles */ if (d->first_id < 0 || !circle_contains(&d->circles[d->first_id], p)) { /* * if any triangle contains p -- start with this triangle */ d->first_id = delaunay_xytoi(d, p, d->first_id); contains = (d->first_id >= 0); /* * if no triangle contains p, there still is a chance that it is * inside some of circumcircles */ if (d->first_id < 0) { int nn = d->t_out->n; int tid = -1; /* * first check results of the last search */ for (i = 0; i < nn; ++i) { tid = d->t_out->v[i]; if (circle_contains(&d->circles[tid], p)) break; } /* * if unsuccessful, search through all circles */ if (tid < 0 || i == nn) { double nt = d->ntriangles; for (tid = 0; tid < nt; ++tid) { if (circle_contains(&d->circles[tid], p)) break; } if (tid == nt) { istack_reset(d->t_out); *n = 0; *out = NULL; return; /* failed */ } } d->first_id = tid; } } istack_reset(d->t_in); istack_reset(d->t_out); istack_push(d->t_in, d->first_id); d->flags[d->first_id] = 1; /* * main cycle */ while (d->t_in->n > 0) { int tid = istack_pop(d->t_in); triangle* t = &d->triangles[tid]; if (contains || circle_contains(&d->circles[tid], p)) { istack_push(d->t_out, tid); for (i = 0; i < 3; ++i) { int vid = t->vids[i]; int nt = d->n_point_triangles[vid]; int j; for (j = 0; j < nt; ++j) { int ntid = d->point_triangles[vid][j]; if (d->flags[ntid] == 0) { istack_push(d->t_in, ntid); d->flags[ntid] = 1; } } } } contains = 0; } *n = d->t_out->n; *out = d->t_out->v; }
kthyng/octant
octant/src/gridgen/version.h
/****************************************************************************** * * File: version.h * * Created: 18/10/2001 * * Author: <NAME> * CSIRO Marine Research * * Purpose: Contains version string * * Description: None * * Revisions: None * *****************************************************************************/ #if !defined(_VERSION_H) #define _VERSION_H static char* gridgen_version = "1.42"; char* nn_version = "1.71"; char* csa_version = "1.16"; char* gu_version = "0.43"; #endif
kthyng/octant
octant/src/gridgen/delaunay.h
<filename>octant/src/gridgen/delaunay.h /****************************************************************************** * * File: delaunay.h * * Created: 04/08/2000 * * Author: <NAME> * CSIRO Marine Research * * Purpose: Header for delaunay triangulation wrapper * * Description: None * * Revisions: None * *****************************************************************************/ #if !defined(_DELAUNAY_H) #define _DELAUNAY_H #include "nn.h" typedef struct { int vids[3]; } triangle; typedef struct { int tids[3]; } triangle_neighbours; typedef struct { double x; double y; double r; } circle; #if !defined(_ISTACK_STRUCT) #define _ISTACK_STRUCT struct istack; typedef struct istack istack; #endif #if !defined(_DELAUNAY_STRUCT) #define _DELAUNAY_STRUCT struct delaunay; typedef struct delaunay delaunay; #endif /** Structure to perform the Delaunay triangulation of a given array of points. * * Contains a deep copy of the input array of points. * Contains triangles, circles and edges resulted from the triangulation. * Contains neighbour triangles for each triangle. * Contains point to triangle map. */ struct delaunay { int npoints; point* points; double xmin; double xmax; double ymin; double ymax; int ntriangles; triangle* triangles; circle* circles; triangle_neighbours* neighbours; /* for delaunay_xytoi() */ int* n_point_triangles; /* n_point_triangles[i] is number of * triangles i-th point belongs to */ int** point_triangles; /* point_triangles[i][j] is index of j-th * triangle i-th point belongs to */ int nedges; int* edges; /* n-th edge is formed by points[edges[n*2]] * and points[edges[n*2+1]] */ /* * Work data for delaunay_circles_find(). Placed here for efficiency * reasons. Should be moved to the procedure if parallelizable code * needed. */ int* flags; int first_id; /* last search result, used in start up of a * new search */ istack* t_in; istack* t_out; }; /* * delaunay_build() and delaunay_destroy() belong to "nn.h" */ void delaunay_circles_find(delaunay* d, point* p, int* n, int** out); int delaunay_xytoi(delaunay* d, point* p, int seed); #endif
kthyng/octant
octant/src/gridgen/gucommon.h
<gh_stars>0 /****************************************************************************** * * File: gucommon.h * * Created 22/01/2002 * * Author: <NAME> * CSIRO Marine Research * * Purpose: Header file with some common stuff for grid utilities * Revisions: none * *****************************************************************************/ #if !defined(_GUCOMMON_H) #define _GUCOMMON_H extern int gu_verbose; /* set verbosity from your application */ void gu_quit(char* format, ...); FILE* gu_fopen(const char* path, const char* mode); void* gu_alloc2d(int n1, int n2, size_t size); void gu_free2d(void* dummy); int** gu_readmask(char* fname, int nx, int ny); #endif
kthyng/octant
octant/src/gridgen/gridgen.h
/****************************************************************************** * * File: gridgen.h * * Created: 2/11/2006 * * Author: <NAME> * CSIRO Marine Research * * Purpose: Top-level header file for the gridgen library. * For more information, see README and gridgen.c. * * Description: Contains prototypes of functions for running gridgen. * To use gridgen from your C code, #include this header * and link with libgridgen.a. * * Revisions: 15/02/2007 PS Introduced a new function gridgen_create2(). * *****************************************************************************/ #if !defined(_GRIDGEN_H) #define _GRIDGEN_H #include "config.h" #include "gridnodes.h" void gridgen_setverbose(int verbose); void gridgen_printversion(void); void gridgen_printhelpalg(void); void gridgen_printhelpprm(void); void gridgen_generategrid(char* prm); gridnodes* gridgen_generategrid2(int nbdry, double xbdry[], double ybdry[], double beta[], int ul, int nx, int ny, int ngrid, double xgrid[], double ygrid[], int nnodes, int newton, double precision, int checksimplepoly, int thin, int nppe, int verbose, int* nsigmas, double** sigmas, int* nrect, double** xrect, double** yrect); #endif /* _GRIDGEN_H */
kthyng/octant
octant/src/gridgen/gucommon.c
<reponame>kthyng/octant /****************************************************************************** * * File: gucommon.c * * Created 22/01/2002 * * Author: <NAME> * CSIRO Marine Research * * Purpose: Some common stuff for grid utilities * Revisions: none * *****************************************************************************/ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <stdarg.h> #include <limits.h> #include <assert.h> #include <errno.h> #define BUFSIZE 10240 int gu_verbose = 0; void gu_quit(char* format, ...) { va_list args; fflush(stdout); fprintf(stderr, "\nerror: gridutils: "); va_start(args, format); vfprintf(stderr, format, args); va_end(args); exit(1); } FILE* gu_fopen(const char* path, const char* mode) { FILE* f = NULL; f = fopen(path, mode); if (f == NULL) gu_quit("%s: could not open for \"%s\" : %s\n", path, mode, strerror(errno)); return f; } /* Allocates n1xn2 matrix of something. Note that it will be accessed as * [n2][n1]. * @param n1 Number of columns * @param n2 Number of rows * @param unitsize Size of one matrix element in bytes * @return Matrix */ void* gu_alloc2d(int n1, int n2, size_t unitsize) { size_t size; char* p; char** pp; int i; if (n1 <= 0 || n2 <= 0) gu_quit("alloc2d(): invalid size (n1 = %d, n2 = %d)\n", n1, n2); size = n1 * n2; if ((p = calloc(size, unitsize)) == NULL) gu_quit("gu_alloc2d(): %s\n", strerror(errno)); size = n2 * sizeof(void*); if ((pp = malloc(size)) == NULL) gu_quit("gu_alloc2d(): %s\n", strerror(errno)); for (i = 0; i < n2; i++) pp[i] = &p[i * n1 * unitsize]; return pp; } /* Destroys a matrix. * @param pp Matrix */ void gu_free2d(void* pp) { void* p; p = ((void**) pp)[0]; free(pp); free(p); } int** gu_readmask(char* fname, int nx, int ny) { int** v = NULL; FILE* f = NULL; char buf[BUFSIZE]; int count; int i, j; if (strcasecmp(fname, "stdin") == 0 || strcmp(fname, "-") == 0) f = stdin; else f = gu_fopen(fname, "r"); v = gu_alloc2d(nx, ny, sizeof(int)); for (j = 0, count = 0; j < ny; ++j) { for (i = 0; i < nx; ++i) { if (fgets(buf, BUFSIZE, f) == NULL) gu_quit("%s: could not read %d-th mask value (%d x %d values expected)\n", fname, j * nx + i + 1, nx, ny); buf[strlen(buf) - 1] = 0; if (strcmp(buf, "0") == 0) v[j][i] = 0; else if (strcmp(buf, "1") == 0) { v[j][i] = 1; count++; } else gu_quit("%s: could not interpret %d-th mask value = \"%s\" (expected \"0\" or \"1\"\n", fname, j * nx + i + 1, buf); } } if (f != stdin) fclose(f); if (gu_verbose) { int n = nx * ny; fprintf(stderr, "## mask: %d valid cells (%.1f%%), %d masked cells (%.1f%%)\n", count, 100.0 * count / n, n - count, 100.0 * (n - count) / n); fflush(stderr); } return v; }
pierriko/cpython
Modules/_codecsmodule.c
/* ------------------------------------------------------------------------ _codecs -- Provides access to the codec registry and the builtin codecs. This module should never be imported directly. The standard library module "codecs" wraps this builtin module for use within Python. The codec registry is accessible via: register(search_function) -> None lookup(encoding) -> CodecInfo object The builtin Unicode codecs use the following interface: <encoding>_encode(Unicode_object[,errors='strict']) -> (string object, bytes consumed) <encoding>_decode(char_buffer_obj[,errors='strict']) -> (Unicode object, bytes consumed) <encoding>_encode() interfaces also accept non-Unicode object as input. The objects are then converted to Unicode using PyUnicode_FromObject() prior to applying the conversion. These <encoding>s are available: utf_8, unicode_escape, raw_unicode_escape, unicode_internal, latin_1, ascii (7-bit), mbcs (on win32). Written by <NAME> (<EMAIL>). Copyright (c) Corporation for National Research Initiatives. ------------------------------------------------------------------------ */ #define PY_SSIZE_T_CLEAN #include "Python.h" #ifdef MS_WINDOWS #include <windows.h> #endif /*[clinic input] module _codecs [clinic start generated code]*/ /*[clinic end generated code: output=da39a3ee5e6b4b0d input=e1390e3da3cb9deb]*/ #include "clinic/_codecsmodule.c.h" /* --- Registry ----------------------------------------------------------- */ /*[clinic input] _codecs.register search_function: object / Register a codec search function. Search functions are expected to take one argument, the encoding name in all lower case letters, and either return None, or a tuple of functions (encoder, decoder, stream_reader, stream_writer) (or a CodecInfo object). [clinic start generated code]*/ static PyObject * _codecs_register(PyModuleDef *module, PyObject *search_function) /*[clinic end generated code: output=d17608b6ad380eb8 input=369578467955cae4]*/ { if (PyCodec_Register(search_function)) return NULL; Py_RETURN_NONE; } /*[clinic input] _codecs.lookup encoding: str / Looks up a codec tuple in the Python codec registry and returns a CodecInfo object. [clinic start generated code]*/ static PyObject * _codecs_lookup_impl(PyModuleDef *module, const char *encoding) /*[clinic end generated code: output=798e41aff0c04ef6 input=3c572c0db3febe9c]*/ { return _PyCodec_Lookup(encoding); } /*[clinic input] _codecs.encode obj: object encoding: str(c_default="NULL") = sys.getdefaultencoding() errors: str(c_default="NULL") = "strict" Encodes obj using the codec registered for encoding. encoding defaults to the default encoding. errors may be given to set a different error handling scheme. Default is 'strict' meaning that encoding errors raise a ValueError. Other possible values are 'ignore', 'replace' and 'backslashreplace' as well as any other name registered with codecs.register_error that can handle ValueErrors. [clinic start generated code]*/ static PyObject * _codecs_encode_impl(PyModuleDef *module, PyObject *obj, const char *encoding, const char *errors) /*[clinic end generated code: output=5c073f62249c8d7c input=2440d769df020a0e]*/ { if (encoding == NULL) encoding = PyUnicode_GetDefaultEncoding(); /* Encode via the codec registry */ return PyCodec_Encode(obj, encoding, errors); } /*[clinic input] _codecs.decode obj: object encoding: str(c_default="NULL") = sys.getdefaultencoding() errors: str(c_default="NULL") = "strict" Decodes obj using the codec registered for encoding. encoding defaults to the default encoding. errors may be given to set a different error handling scheme. Default is 'strict' meaning that encoding errors raise a ValueError. Other possible values are 'ignore', 'replace' and 'backslashreplace' as well as any other name registered with codecs.register_error that can handle ValueErrors. [clinic start generated code]*/ static PyObject * _codecs_decode_impl(PyModuleDef *module, PyObject *obj, const char *encoding, const char *errors) /*[clinic end generated code: output=c81cbf6189a7f878 input=a351e5f5baad1544]*/ { if (encoding == NULL) encoding = PyUnicode_GetDefaultEncoding(); /* Decode via the codec registry */ return PyCodec_Decode(obj, encoding, errors); } /* --- Helpers ------------------------------------------------------------ */ /*[clinic input] _codecs._forget_codec encoding: str / Purge the named codec from the internal codec lookup cache [clinic start generated code]*/ static PyObject * _codecs__forget_codec_impl(PyModuleDef *module, const char *encoding) /*[clinic end generated code: output=b56a9b99d2d28080 input=18d5d92d0e386c38]*/ { if (_PyCodec_Forget(encoding) < 0) { return NULL; }; Py_RETURN_NONE; } static PyObject *codec_tuple(PyObject *decoded, Py_ssize_t len) { if (decoded == NULL) return NULL; return Py_BuildValue("Nn", decoded, len); } /* --- String codecs ------------------------------------------------------ */ /*[clinic input] _codecs.escape_decode data: Py_buffer(accept={str, buffer}) errors: str(accept={str, NoneType}) = NULL / [clinic start generated code]*/ static PyObject * _codecs_escape_decode_impl(PyModuleDef *module, Py_buffer *data, const char *errors) /*[clinic end generated code: output=648fa3e78d03e658 input=0018edfd99db714d]*/ { PyObject *decoded = PyBytes_DecodeEscape(data->buf, data->len, errors, 0, NULL); return codec_tuple(decoded, data->len); } /*[clinic input] _codecs.escape_encode data: object(subclass_of='&PyBytes_Type') errors: str(accept={str, NoneType}) = NULL / [clinic start generated code]*/ static PyObject * _codecs_escape_encode_impl(PyModuleDef *module, PyObject *data, const char *errors) /*[clinic end generated code: output=fcd6f34fe4111c50 input=da9ded00992f32f2]*/ { Py_ssize_t size; Py_ssize_t newsize; PyObject *v; size = PyBytes_GET_SIZE(data); if (size > PY_SSIZE_T_MAX / 4) { PyErr_SetString(PyExc_OverflowError, "string is too large to encode"); return NULL; } newsize = 4*size; v = PyBytes_FromStringAndSize(NULL, newsize); if (v == NULL) { return NULL; } else { Py_ssize_t i; char c; char *p = PyBytes_AS_STRING(v); for (i = 0; i < size; i++) { /* There's at least enough room for a hex escape */ assert(newsize - (p - PyBytes_AS_STRING(v)) >= 4); c = PyBytes_AS_STRING(data)[i]; if (c == '\'' || c == '\\') *p++ = '\\', *p++ = c; else if (c == '\t') *p++ = '\\', *p++ = 't'; else if (c == '\n') *p++ = '\\', *p++ = 'n'; else if (c == '\r') *p++ = '\\', *p++ = 'r'; else if (c < ' ' || c >= 0x7f) { *p++ = '\\'; *p++ = 'x'; *p++ = Py_hexdigits[(c & 0xf0) >> 4]; *p++ = Py_hexdigits[c & 0xf]; } else *p++ = c; } *p = '\0'; if (_PyBytes_Resize(&v, (p - PyBytes_AS_STRING(v)))) { return NULL; } } return codec_tuple(v, size); } /* --- Decoder ------------------------------------------------------------ */ /*[clinic input] _codecs.unicode_internal_decode obj: object errors: str(accept={str, NoneType}) = NULL / [clinic start generated code]*/ static PyObject * _codecs_unicode_internal_decode_impl(PyModuleDef *module, PyObject *obj, const char *errors) /*[clinic end generated code: output=9fe47c2cd8807d92 input=8d57930aeda170c6]*/ { if (PyUnicode_Check(obj)) { if (PyUnicode_READY(obj) < 0) return NULL; Py_INCREF(obj); return codec_tuple(obj, PyUnicode_GET_LENGTH(obj)); } else { Py_buffer view; PyObject *result; if (PyObject_GetBuffer(obj, &view, PyBUF_SIMPLE) != 0) return NULL; result = codec_tuple( _PyUnicode_DecodeUnicodeInternal(view.buf, view.len, errors), view.len); PyBuffer_Release(&view); return result; } } /*[clinic input] _codecs.utf_7_decode data: Py_buffer errors: str(accept={str, NoneType}) = NULL final: int(c_default="0") = False / [clinic start generated code]*/ static PyObject * _codecs_utf_7_decode_impl(PyModuleDef *module, Py_buffer *data, const char *errors, int final) /*[clinic end generated code: output=ca945e907e72e827 input=bc4d6247ecdb01e6]*/ { Py_ssize_t consumed = data->len; PyObject *decoded = PyUnicode_DecodeUTF7Stateful(data->buf, data->len, errors, final ? NULL : &consumed); return codec_tuple(decoded, consumed); } /*[clinic input] _codecs.utf_8_decode data: Py_buffer errors: str(accept={str, NoneType}) = NULL final: int(c_default="0") = False / [clinic start generated code]*/ static PyObject * _codecs_utf_8_decode_impl(PyModuleDef *module, Py_buffer *data, const char *errors, int final) /*[clinic end generated code: output=7309f9ff4ef5c9b6 input=39161d71e7422ee2]*/ { Py_ssize_t consumed = data->len; PyObject *decoded = PyUnicode_DecodeUTF8Stateful(data->buf, data->len, errors, final ? NULL : &consumed); return codec_tuple(decoded, consumed); } /*[clinic input] _codecs.utf_16_decode data: Py_buffer errors: str(accept={str, NoneType}) = NULL final: int(c_default="0") = False / [clinic start generated code]*/ static PyObject * _codecs_utf_16_decode_impl(PyModuleDef *module, Py_buffer *data, const char *errors, int final) /*[clinic end generated code: output=8d2fa0507d9bef2c input=f3cf01d1461007ce]*/ { int byteorder = 0; /* This is overwritten unless final is true. */ Py_ssize_t consumed = data->len; PyObject *decoded = PyUnicode_DecodeUTF16Stateful(data->buf, data->len, errors, &byteorder, final ? NULL : &consumed); return codec_tuple(decoded, consumed); } /*[clinic input] _codecs.utf_16_le_decode data: Py_buffer errors: str(accept={str, NoneType}) = NULL final: int(c_default="0") = False / [clinic start generated code]*/ static PyObject * _codecs_utf_16_le_decode_impl(PyModuleDef *module, Py_buffer *data, const char *errors, int final) /*[clinic end generated code: output=4fd621515ef4ce18 input=a77e3bf97335d94e]*/ { int byteorder = -1; /* This is overwritten unless final is true. */ Py_ssize_t consumed = data->len; PyObject *decoded = PyUnicode_DecodeUTF16Stateful(data->buf, data->len, errors, &byteorder, final ? NULL : &consumed); return codec_tuple(decoded, consumed); } /*[clinic input] _codecs.utf_16_be_decode data: Py_buffer errors: str(accept={str, NoneType}) = NULL final: int(c_default="0") = False / [clinic start generated code]*/ static PyObject * _codecs_utf_16_be_decode_impl(PyModuleDef *module, Py_buffer *data, const char *errors, int final) /*[clinic end generated code: output=792f4eacb3e1fa05 input=606f69fae91b5563]*/ { int byteorder = 1; /* This is overwritten unless final is true. */ Py_ssize_t consumed = data->len; PyObject *decoded = PyUnicode_DecodeUTF16Stateful(data->buf, data->len, errors, &byteorder, final ? NULL : &consumed); return codec_tuple(decoded, consumed); } /* This non-standard version also provides access to the byteorder parameter of the builtin UTF-16 codec. It returns a tuple (unicode, bytesread, byteorder) with byteorder being the value in effect at the end of data. */ /*[clinic input] _codecs.utf_16_ex_decode data: Py_buffer errors: str(accept={str, NoneType}) = NULL byteorder: int = 0 final: int(c_default="0") = False / [clinic start generated code]*/ static PyObject * _codecs_utf_16_ex_decode_impl(PyModuleDef *module, Py_buffer *data, const char *errors, int byteorder, int final) /*[clinic end generated code: output=f136a186dc2defa0 input=f6e7f697658c013e]*/ { /* This is overwritten unless final is true. */ Py_ssize_t consumed = data->len; PyObject *decoded = PyUnicode_DecodeUTF16Stateful(data->buf, data->len, errors, &byteorder, final ? NULL : &consumed); if (decoded == NULL) return NULL; return Py_BuildValue("Nni", decoded, consumed, byteorder); } /*[clinic input] _codecs.utf_32_decode data: Py_buffer errors: str(accept={str, NoneType}) = NULL final: int(c_default="0") = False / [clinic start generated code]*/ static PyObject * _codecs_utf_32_decode_impl(PyModuleDef *module, Py_buffer *data, const char *errors, int final) /*[clinic end generated code: output=b7635e55857e8efb input=86d4f41c6c2e763d]*/ { int byteorder = 0; /* This is overwritten unless final is true. */ Py_ssize_t consumed = data->len; PyObject *decoded = PyUnicode_DecodeUTF32Stateful(data->buf, data->len, errors, &byteorder, final ? NULL : &consumed); return codec_tuple(decoded, consumed); } /*[clinic input] _codecs.utf_32_le_decode data: Py_buffer errors: str(accept={str, NoneType}) = NULL final: int(c_default="0") = False / [clinic start generated code]*/ static PyObject * _codecs_utf_32_le_decode_impl(PyModuleDef *module, Py_buffer *data, const char *errors, int final) /*[clinic end generated code: output=a79d1787d8ddf988 input=d18b650772d188ba]*/ { int byteorder = -1; /* This is overwritten unless final is true. */ Py_ssize_t consumed = data->len; PyObject *decoded = PyUnicode_DecodeUTF32Stateful(data->buf, data->len, errors, &byteorder, final ? NULL : &consumed); return codec_tuple(decoded, consumed); } /*[clinic input] _codecs.utf_32_be_decode data: Py_buffer errors: str(accept={str, NoneType}) = NULL final: int(c_default="0") = False / [clinic start generated code]*/ static PyObject * _codecs_utf_32_be_decode_impl(PyModuleDef *module, Py_buffer *data, const char *errors, int final) /*[clinic end generated code: output=a8356b0f36779981 input=19c271b5d34926d8]*/ { int byteorder = 1; /* This is overwritten unless final is true. */ Py_ssize_t consumed = data->len; PyObject *decoded = PyUnicode_DecodeUTF32Stateful(data->buf, data->len, errors, &byteorder, final ? NULL : &consumed); return codec_tuple(decoded, consumed); } /* This non-standard version also provides access to the byteorder parameter of the builtin UTF-32 codec. It returns a tuple (unicode, bytesread, byteorder) with byteorder being the value in effect at the end of data. */ /*[clinic input] _codecs.utf_32_ex_decode data: Py_buffer errors: str(accept={str, NoneType}) = NULL byteorder: int = 0 final: int(c_default="0") = False / [clinic start generated code]*/ static PyObject * _codecs_utf_32_ex_decode_impl(PyModuleDef *module, Py_buffer *data, const char *errors, int byteorder, int final) /*[clinic end generated code: output=ab8c70977c1992f5 input=4af3e6ccfe34a076]*/ { Py_ssize_t consumed = data->len; PyObject *decoded = PyUnicode_DecodeUTF32Stateful(data->buf, data->len, errors, &byteorder, final ? NULL : &consumed); if (decoded == NULL) return NULL; return Py_BuildValue("Nni", decoded, consumed, byteorder); } /*[clinic input] _codecs.unicode_escape_decode data: Py_buffer(accept={str, buffer}) errors: str(accept={str, NoneType}) = NULL / [clinic start generated code]*/ static PyObject * _codecs_unicode_escape_decode_impl(PyModuleDef *module, Py_buffer *data, const char *errors) /*[clinic end generated code: output=d1aa63f2620c4999 input=49fd27d06813a7f5]*/ { PyObject *decoded = PyUnicode_DecodeUnicodeEscape(data->buf, data->len, errors); return codec_tuple(decoded, data->len); } /*[clinic input] _codecs.raw_unicode_escape_decode data: Py_buffer(accept={str, buffer}) errors: str(accept={str, NoneType}) = NULL / [clinic start generated code]*/ static PyObject * _codecs_raw_unicode_escape_decode_impl(PyModuleDef *module, Py_buffer *data, const char *errors) /*[clinic end generated code: output=0bf96cc182d81379 input=770903a211434ebc]*/ { PyObject *decoded = PyUnicode_DecodeRawUnicodeEscape(data->buf, data->len, errors); return codec_tuple(decoded, data->len); } /*[clinic input] _codecs.latin_1_decode data: Py_buffer errors: str(accept={str, NoneType}) = NULL / [clinic start generated code]*/ static PyObject * _codecs_latin_1_decode_impl(PyModuleDef *module, Py_buffer *data, const char *errors) /*[clinic end generated code: output=66b916f5055aaf13 input=5cad0f1759c618ec]*/ { PyObject *decoded = PyUnicode_DecodeLatin1(data->buf, data->len, errors); return codec_tuple(decoded, data->len); } /*[clinic input] _codecs.ascii_decode data: Py_buffer errors: str(accept={str, NoneType}) = NULL / [clinic start generated code]*/ static PyObject * _codecs_ascii_decode_impl(PyModuleDef *module, Py_buffer *data, const char *errors) /*[clinic end generated code: output=7f213a1b5cdafc65 input=ad1106f64037bd16]*/ { PyObject *decoded = PyUnicode_DecodeASCII(data->buf, data->len, errors); return codec_tuple(decoded, data->len); } /*[clinic input] _codecs.charmap_decode data: Py_buffer errors: str(accept={str, NoneType}) = NULL mapping: object = NULL / [clinic start generated code]*/ static PyObject * _codecs_charmap_decode_impl(PyModuleDef *module, Py_buffer *data, const char *errors, PyObject *mapping) /*[clinic end generated code: output=87d27f365098bbae input=19712ca35c5a80e2]*/ { PyObject *decoded; if (mapping == Py_None) mapping = NULL; decoded = PyUnicode_DecodeCharmap(data->buf, data->len, mapping, errors); return codec_tuple(decoded, data->len); } #ifdef HAVE_MBCS /*[clinic input] _codecs.mbcs_decode data: Py_buffer errors: str(accept={str, NoneType}) = NULL final: int(c_default="0") = False / [clinic start generated code]*/ static PyObject * _codecs_mbcs_decode_impl(PyModuleDef *module, Py_buffer *data, const char *errors, int final) /*[clinic end generated code: output=0ebaf3a5b20e53fa input=d492c1ca64f4fa8a]*/ { Py_ssize_t consumed = data->len; PyObject *decoded = PyUnicode_DecodeMBCSStateful(data->buf, data->len, errors, final ? NULL : &consumed); return codec_tuple(decoded, consumed); } /*[clinic input] _codecs.code_page_decode codepage: int data: Py_buffer errors: str(accept={str, NoneType}) = NULL final: int(c_default="0") = False / [clinic start generated code]*/ static PyObject * _codecs_code_page_decode_impl(PyModuleDef *module, int codepage, Py_buffer *data, const char *errors, int final) /*[clinic end generated code: output=4318e3d9971e31ba input=4f3152a304e21d51]*/ { Py_ssize_t consumed = data->len; PyObject *decoded = PyUnicode_DecodeCodePageStateful(codepage, data->buf, data->len, errors, final ? NULL : &consumed); return codec_tuple(decoded, consumed); } #endif /* HAVE_MBCS */ /* --- Encoder ------------------------------------------------------------ */ /*[clinic input] _codecs.readbuffer_encode data: Py_buffer(accept={str, buffer}) errors: str(accept={str, NoneType}) = NULL / [clinic start generated code]*/ static PyObject * _codecs_readbuffer_encode_impl(PyModuleDef *module, Py_buffer *data, const char *errors) /*[clinic end generated code: output=319cc24083299859 input=b7c322b89d4ab923]*/ { PyObject *result = PyBytes_FromStringAndSize(data->buf, data->len); return codec_tuple(result, data->len); } /*[clinic input] _codecs.unicode_internal_encode obj: object errors: str(accept={str, NoneType}) = NULL / [clinic start generated code]*/ static PyObject * _codecs_unicode_internal_encode_impl(PyModuleDef *module, PyObject *obj, const char *errors) /*[clinic end generated code: output=be08457068ad503b input=8628f0280cf5ba61]*/ { if (PyErr_WarnEx(PyExc_DeprecationWarning, "unicode_internal codec has been deprecated", 1)) return NULL; if (PyUnicode_Check(obj)) { Py_UNICODE *u; Py_ssize_t len, size; if (PyUnicode_READY(obj) < 0) return NULL; u = PyUnicode_AsUnicodeAndSize(obj, &len); if (u == NULL) return NULL; if ((size_t)len > (size_t)PY_SSIZE_T_MAX / sizeof(Py_UNICODE)) return PyErr_NoMemory(); size = len * sizeof(Py_UNICODE); return codec_tuple(PyBytes_FromStringAndSize((const char*)u, size), PyUnicode_GET_LENGTH(obj)); } else { Py_buffer view; PyObject *result; if (PyObject_GetBuffer(obj, &view, PyBUF_SIMPLE) != 0) return NULL; result = codec_tuple(PyBytes_FromStringAndSize(view.buf, view.len), view.len); PyBuffer_Release(&view); return result; } } /*[clinic input] _codecs.utf_7_encode str: object errors: str(accept={str, NoneType}) = NULL / [clinic start generated code]*/ static PyObject * _codecs_utf_7_encode_impl(PyModuleDef *module, PyObject *str, const char *errors) /*[clinic end generated code: output=a7accc496a32b759 input=fd91a78f103b0421]*/ { PyObject *v; str = PyUnicode_FromObject(str); if (str == NULL || PyUnicode_READY(str) < 0) { Py_XDECREF(str); return NULL; } v = codec_tuple(_PyUnicode_EncodeUTF7(str, 0, 0, errors), PyUnicode_GET_LENGTH(str)); Py_DECREF(str); return v; } /*[clinic input] _codecs.utf_8_encode str: object errors: str(accept={str, NoneType}) = NULL / [clinic start generated code]*/ static PyObject * _codecs_utf_8_encode_impl(PyModuleDef *module, PyObject *str, const char *errors) /*[clinic end generated code: output=ec831d80e7aedede input=2c22d40532f071f3]*/ { PyObject *v; str = PyUnicode_FromObject(str); if (str == NULL || PyUnicode_READY(str) < 0) { Py_XDECREF(str); return NULL; } v = codec_tuple(PyUnicode_AsEncodedString(str, "utf-8", errors), PyUnicode_GET_LENGTH(str)); Py_DECREF(str); return v; } /* This version provides access to the byteorder parameter of the builtin UTF-16 codecs as optional third argument. It defaults to 0 which means: use the native byte order and prepend the data with a BOM mark. */ /*[clinic input] _codecs.utf_16_encode str: object errors: str(accept={str, NoneType}) = NULL byteorder: int = 0 / [clinic start generated code]*/ static PyObject * _codecs_utf_16_encode_impl(PyModuleDef *module, PyObject *str, const char *errors, int byteorder) /*[clinic end generated code: output=93ac58e960a9ee4d input=3935a489b2d5385e]*/ { PyObject *v; str = PyUnicode_FromObject(str); if (str == NULL || PyUnicode_READY(str) < 0) { Py_XDECREF(str); return NULL; } v = codec_tuple(_PyUnicode_EncodeUTF16(str, errors, byteorder), PyUnicode_GET_LENGTH(str)); Py_DECREF(str); return v; } /*[clinic input] _codecs.utf_16_le_encode str: object errors: str(accept={str, NoneType}) = NULL / [clinic start generated code]*/ static PyObject * _codecs_utf_16_le_encode_impl(PyModuleDef *module, PyObject *str, const char *errors) /*[clinic end generated code: output=422bedb8da34fb66 input=bc27df05d1d20dfe]*/ { PyObject *v; str = PyUnicode_FromObject(str); if (str == NULL || PyUnicode_READY(str) < 0) { Py_XDECREF(str); return NULL; } v = codec_tuple(_PyUnicode_EncodeUTF16(str, errors, -1), PyUnicode_GET_LENGTH(str)); Py_DECREF(str); return v; } /*[clinic input] _codecs.utf_16_be_encode str: object errors: str(accept={str, NoneType}) = NULL / [clinic start generated code]*/ static PyObject * _codecs_utf_16_be_encode_impl(PyModuleDef *module, PyObject *str, const char *errors) /*[clinic end generated code: output=3aa7ee9502acdd77 input=5a69d4112763462b]*/ { PyObject *v; str = PyUnicode_FromObject(str); if (str == NULL || PyUnicode_READY(str) < 0) { Py_XDECREF(str); return NULL; } v = codec_tuple(_PyUnicode_EncodeUTF16(str, errors, +1), PyUnicode_GET_LENGTH(str)); Py_DECREF(str); return v; } /* This version provides access to the byteorder parameter of the builtin UTF-32 codecs as optional third argument. It defaults to 0 which means: use the native byte order and prepend the data with a BOM mark. */ /*[clinic input] _codecs.utf_32_encode str: object errors: str(accept={str, NoneType}) = NULL byteorder: int = 0 / [clinic start generated code]*/ static PyObject * _codecs_utf_32_encode_impl(PyModuleDef *module, PyObject *str, const char *errors, int byteorder) /*[clinic end generated code: output=3e7d5a003b02baed input=434a1efa492b8d58]*/ { PyObject *v; str = PyUnicode_FromObject(str); if (str == NULL || PyUnicode_READY(str) < 0) { Py_XDECREF(str); return NULL; } v = codec_tuple(_PyUnicode_EncodeUTF32(str, errors, byteorder), PyUnicode_GET_LENGTH(str)); Py_DECREF(str); return v; } /*[clinic input] _codecs.utf_32_le_encode str: object errors: str(accept={str, NoneType}) = NULL / [clinic start generated code]*/ static PyObject * _codecs_utf_32_le_encode_impl(PyModuleDef *module, PyObject *str, const char *errors) /*[clinic end generated code: output=5dda641cd33dbfc2 input=dfa2d7dc78b99422]*/ { PyObject *v; str = PyUnicode_FromObject(str); if (str == NULL || PyUnicode_READY(str) < 0) { Py_XDECREF(str); return NULL; } v = codec_tuple(_PyUnicode_EncodeUTF32(str, errors, -1), PyUnicode_GET_LENGTH(str)); Py_DECREF(str); return v; } /*[clinic input] _codecs.utf_32_be_encode str: object errors: str(accept={str, NoneType}) = NULL / [clinic start generated code]*/ static PyObject * _codecs_utf_32_be_encode_impl(PyModuleDef *module, PyObject *str, const char *errors) /*[clinic end generated code: output=ccca8b44d91a7c7a input=4595617b18169002]*/ { PyObject *v; str = PyUnicode_FromObject(str); if (str == NULL || PyUnicode_READY(str) < 0) { Py_XDECREF(str); return NULL; } v = codec_tuple(_PyUnicode_EncodeUTF32(str, errors, +1), PyUnicode_GET_LENGTH(str)); Py_DECREF(str); return v; } /*[clinic input] _codecs.unicode_escape_encode str: object errors: str(accept={str, NoneType}) = NULL / [clinic start generated code]*/ static PyObject * _codecs_unicode_escape_encode_impl(PyModuleDef *module, PyObject *str, const char *errors) /*[clinic end generated code: output=389f23d2b8f8d80b input=8273506f14076912]*/ { PyObject *v; str = PyUnicode_FromObject(str); if (str == NULL || PyUnicode_READY(str) < 0) { Py_XDECREF(str); return NULL; } v = codec_tuple(PyUnicode_AsUnicodeEscapeString(str), PyUnicode_GET_LENGTH(str)); Py_DECREF(str); return v; } /*[clinic input] _codecs.raw_unicode_escape_encode str: object errors: str(accept={str, NoneType}) = NULL / [clinic start generated code]*/ static PyObject * _codecs_raw_unicode_escape_encode_impl(PyModuleDef *module, PyObject *str, const char *errors) /*[clinic end generated code: output=fec4e39d6ec37a62 input=181755d5dfacef3c]*/ { PyObject *v; str = PyUnicode_FromObject(str); if (str == NULL || PyUnicode_READY(str) < 0) { Py_XDECREF(str); return NULL; } v = codec_tuple(PyUnicode_AsRawUnicodeEscapeString(str), PyUnicode_GET_LENGTH(str)); Py_DECREF(str); return v; } /*[clinic input] _codecs.latin_1_encode str: object errors: str(accept={str, NoneType}) = NULL / [clinic start generated code]*/ static PyObject * _codecs_latin_1_encode_impl(PyModuleDef *module, PyObject *str, const char *errors) /*[clinic end generated code: output=ecf00eb8e48c889c input=f03f6dcf1d84bee4]*/ { PyObject *v; str = PyUnicode_FromObject(str); if (str == NULL || PyUnicode_READY(str) < 0) { Py_XDECREF(str); return NULL; } v = codec_tuple(_PyUnicode_AsLatin1String(str, errors), PyUnicode_GET_LENGTH(str)); Py_DECREF(str); return v; } /*[clinic input] _codecs.ascii_encode str: object errors: str(accept={str, NoneType}) = NULL / [clinic start generated code]*/ static PyObject * _codecs_ascii_encode_impl(PyModuleDef *module, PyObject *str, const char *errors) /*[clinic end generated code: output=a9d18fc6b6b91cfb input=d87e25a10a593fee]*/ { PyObject *v; str = PyUnicode_FromObject(str); if (str == NULL || PyUnicode_READY(str) < 0) { Py_XDECREF(str); return NULL; } v = codec_tuple(_PyUnicode_AsASCIIString(str, errors), PyUnicode_GET_LENGTH(str)); Py_DECREF(str); return v; } /*[clinic input] _codecs.charmap_encode str: object errors: str(accept={str, NoneType}) = NULL mapping: object = NULL / [clinic start generated code]*/ static PyObject * _codecs_charmap_encode_impl(PyModuleDef *module, PyObject *str, const char *errors, PyObject *mapping) /*[clinic end generated code: output=14ca42b83853c643 input=85f4172661e8dad9]*/ { PyObject *v; if (mapping == Py_None) mapping = NULL; str = PyUnicode_FromObject(str); if (str == NULL || PyUnicode_READY(str) < 0) { Py_XDECREF(str); return NULL; } v = codec_tuple(_PyUnicode_EncodeCharmap(str, mapping, errors), PyUnicode_GET_LENGTH(str)); Py_DECREF(str); return v; } /*[clinic input] _codecs.charmap_build map: unicode / [clinic start generated code]*/ static PyObject * _codecs_charmap_build_impl(PyModuleDef *module, PyObject *map) /*[clinic end generated code: output=9485b58fa44afa6a input=d91a91d1717dbc6d]*/ { return PyUnicode_BuildEncodingMap(map); } #ifdef HAVE_MBCS /*[clinic input] _codecs.mbcs_encode str: object errors: str(accept={str, NoneType}) = NULL / [clinic start generated code]*/ static PyObject * _codecs_mbcs_encode_impl(PyModuleDef *module, PyObject *str, const char *errors) /*[clinic end generated code: output=d1a013bc68798bd7 input=65c09ee1e4203263]*/ { PyObject *v; str = PyUnicode_FromObject(str); if (str == NULL || PyUnicode_READY(str) < 0) { Py_XDECREF(str); return NULL; } v = codec_tuple(PyUnicode_EncodeCodePage(CP_ACP, str, errors), PyUnicode_GET_LENGTH(str)); Py_DECREF(str); return v; } /*[clinic input] _codecs.code_page_encode code_page: int str: object errors: str(accept={str, NoneType}) = NULL / [clinic start generated code]*/ static PyObject * _codecs_code_page_encode_impl(PyModuleDef *module, int code_page, PyObject *str, const char *errors) /*[clinic end generated code: output=3b406618dbfbce25 input=c8562ec460c2e309]*/ { PyObject *v; str = PyUnicode_FromObject(str); if (str == NULL || PyUnicode_READY(str) < 0) { Py_XDECREF(str); return NULL; } v = codec_tuple(PyUnicode_EncodeCodePage(code_page, str, errors), PyUnicode_GET_LENGTH(str)); Py_DECREF(str); return v; } #endif /* HAVE_MBCS */ /* --- Error handler registry --------------------------------------------- */ /*[clinic input] _codecs.register_error errors: str handler: object / Register the specified error handler under the name errors. handler must be a callable object, that will be called with an exception instance containing information about the location of the encoding/decoding error and must return a (replacement, new position) tuple. [clinic start generated code]*/ static PyObject * _codecs_register_error_impl(PyModuleDef *module, const char *errors, PyObject *handler) /*[clinic end generated code: output=be00d3b1849ce68a input=5e6709203c2e33fe]*/ { if (PyCodec_RegisterError(errors, handler)) return NULL; Py_RETURN_NONE; } /*[clinic input] _codecs.lookup_error name: str / lookup_error(errors) -> handler Return the error handler for the specified error handling name or raise a LookupError, if no handler exists under this name. [clinic start generated code]*/ static PyObject * _codecs_lookup_error_impl(PyModuleDef *module, const char *name) /*[clinic end generated code: output=731e6df8c83c6158 input=4775dd65e6235aba]*/ { return PyCodec_LookupError(name); } /* --- Module API --------------------------------------------------------- */ static PyMethodDef _codecs_functions[] = { _CODECS_REGISTER_METHODDEF _CODECS_LOOKUP_METHODDEF _CODECS_ENCODE_METHODDEF _CODECS_DECODE_METHODDEF _CODECS_ESCAPE_ENCODE_METHODDEF _CODECS_ESCAPE_DECODE_METHODDEF _CODECS_UTF_8_ENCODE_METHODDEF _CODECS_UTF_8_DECODE_METHODDEF _CODECS_UTF_7_ENCODE_METHODDEF _CODECS_UTF_7_DECODE_METHODDEF _CODECS_UTF_16_ENCODE_METHODDEF _CODECS_UTF_16_LE_ENCODE_METHODDEF _CODECS_UTF_16_BE_ENCODE_METHODDEF _CODECS_UTF_16_DECODE_METHODDEF _CODECS_UTF_16_LE_DECODE_METHODDEF _CODECS_UTF_16_BE_DECODE_METHODDEF _CODECS_UTF_16_EX_DECODE_METHODDEF _CODECS_UTF_32_ENCODE_METHODDEF _CODECS_UTF_32_LE_ENCODE_METHODDEF _CODECS_UTF_32_BE_ENCODE_METHODDEF _CODECS_UTF_32_DECODE_METHODDEF _CODECS_UTF_32_LE_DECODE_METHODDEF _CODECS_UTF_32_BE_DECODE_METHODDEF _CODECS_UTF_32_EX_DECODE_METHODDEF _CODECS_UNICODE_ESCAPE_ENCODE_METHODDEF _CODECS_UNICODE_ESCAPE_DECODE_METHODDEF _CODECS_UNICODE_INTERNAL_ENCODE_METHODDEF _CODECS_UNICODE_INTERNAL_DECODE_METHODDEF _CODECS_RAW_UNICODE_ESCAPE_ENCODE_METHODDEF _CODECS_RAW_UNICODE_ESCAPE_DECODE_METHODDEF _CODECS_LATIN_1_ENCODE_METHODDEF _CODECS_LATIN_1_DECODE_METHODDEF _CODECS_ASCII_ENCODE_METHODDEF _CODECS_ASCII_DECODE_METHODDEF _CODECS_CHARMAP_ENCODE_METHODDEF _CODECS_CHARMAP_DECODE_METHODDEF _CODECS_CHARMAP_BUILD_METHODDEF _CODECS_READBUFFER_ENCODE_METHODDEF _CODECS_MBCS_ENCODE_METHODDEF _CODECS_MBCS_DECODE_METHODDEF _CODECS_CODE_PAGE_ENCODE_METHODDEF _CODECS_CODE_PAGE_DECODE_METHODDEF _CODECS_REGISTER_ERROR_METHODDEF _CODECS_LOOKUP_ERROR_METHODDEF _CODECS__FORGET_CODEC_METHODDEF {NULL, NULL} /* sentinel */ }; static struct PyModuleDef codecsmodule = { PyModuleDef_HEAD_INIT, "_codecs", NULL, -1, _codecs_functions, NULL, NULL, NULL, NULL }; PyMODINIT_FUNC PyInit__codecs(void) { return PyModule_Create(&codecsmodule); }
eavelie/oversimplifiedparse
functions.h
#ifndef FUNCTIONS_H #define FUNCTIONS_H #include <string> #include <iostream> std::string classNameInput(); std::string nameInput(std::string className); std::string gradeInput(std::string className); bool boolCheck(std::string input); std::string namesData(std::string studentsNames[100], int namesArrayTrueSize, std::string className); std::string datagrade(std::string studentsGrades[], int namesArrayTrueSize, int gradesArrayTrueSize, std::string className); std::string classNameFunc(std::string className, int classNameChoice); int highestValue(std::string studentsGrades[], int namesArrayTrueSize, int namesArrayTrueSize1); int lowestValue(std::string studentsGrades[], int namesArrayTrueSize, int namesArrayTrueSize1); double avrgValue(std::string studentsGrades[], int namesArrayTrueSize, int namesArrayTrueSize1); void parser(std::string arrayString[], std::string input, bool breaker); int arraySize(std::string input, bool breaker); void highestValueOverall(std::string grade[], std::string name[], std::string grade1[], std::string name1[], int namesArrayTrueSize, int gradesArrayTrueSize, int namesArrayTrueSize1, int gradesArrayTrueSize1, std::string className); void lowestValueOverall(std::string grade[], std::string name[], std::string grade1[], std::string name1[], int namesArrayTrueSize, int gradesArrayTrueSize, int namesArrayTrueSize1, int gradesArrayTrueSize1, std::string className); void warningMessage(int namesArrayTrueSize, int namesArrayTrueSize1, int namesArrayTrueSize2, int namesArrayTrueSize3); std::string outputHighestValue(std::string studentsGrades[], std::string studentsNames[], int namesArrayTrueSize, int namesArrayTrueSize1, std::string className); std::string outputLowestValue(std::string studentsGrades[], std::string studentsNames[], int namesArrayTrueSize, int namesArrayTrueSize1, std::string className); void outputAvrgValue(std::string studentsGrades[], std::string className, int namesArrayTrueSize, int namesArrayTrueSize1); void allResult(int namesArrayTrueSize, int namesArrayTrueSize1, int gradesArrayTrueSize, int gradesArrayTrueSize1, std::string name[], std::string name1[], std::string grade[], std::string grade1[], std::string classNameInput); #endif
mdjarv/dcs-bios-arduino-library
Buttons.h
<reponame>mdjarv/dcs-bios-arduino-library #ifndef __DCSBIOS_BUTTONS_H #define __DCSBIOS_BUTTONS_H #include "Arduino.h" #include "PollingInput.h" namespace DcsBios { class ActionButton : PollingInput { private: void pollInput(); char* msg_; char* arg_; char pin_; char lastState_; public: ActionButton(char* msg, char* arg, char pin); }; } #endif
mdjarv/dcs-bios-arduino-library
Leds.h
#ifndef __DCSBIOS_LEDS_H #define __DCSBIOS_LEDS_H #include "Arduino.h" #include "ExportStreamListener.h" namespace DcsBios { class LED : IntegerBuffer { private: void onDcsBiosFrameSync(); unsigned char pin_; public: LED(unsigned int address, unsigned int mask, char pin); }; } #endif
mdjarv/dcs-bios-arduino-library
DcsBios.h
#ifndef __DCSBIOS_H #define __DCSBIOS_H #include "Protocol.h" #include "Buttons.h" #include "Switches.h" #include "Encoders.h" #include "Potentiometers.h" #include "Leds.h" #include "Servos.h" #endif
mdjarv/dcs-bios-arduino-library
ExportStreamListener.h
#ifndef __DCSBIOS_EXPORTSTREAMLISTENER_H #define __DCSBIOS_EXPORTSTREAMLISTENER_H #include "Arduino.h" namespace DcsBios { class ExportStreamListener { private: virtual void onDcsBiosWrite(unsigned int address, unsigned int value) {} virtual void onDcsBiosFrameSync() {} ExportStreamListener* nextExportStreamListener; public: static ExportStreamListener* firstExportStreamListener; ExportStreamListener() { this->nextExportStreamListener = firstExportStreamListener; firstExportStreamListener = this; } static void handleDcsBiosWrite(unsigned int address, unsigned int value) { ExportStreamListener* el = firstExportStreamListener; while (el) { el->onDcsBiosWrite(address, value); el = el->nextExportStreamListener; } } static void handleDcsBiosFrameSync() { ExportStreamListener* el = firstExportStreamListener; while (el) { el->onDcsBiosFrameSync(); el = el->nextExportStreamListener; } } }; template < unsigned int LENGTH > class StringBuffer : ExportStreamListener { private: void onDcsBiosWrite(unsigned int address, unsigned int value) { if ((address >= address_) && (endAddress_ > address)) { unsigned int index = address - address_; buffer[index] = ((char*)&value)[0]; index++; if (LENGTH > index) { buffer[index] = ((char*)&value)[1]; } // No need to compare existing buffer with current value. We never get to this // point unless the sim has sent a change. dirty_ = true; } } unsigned int address_; unsigned int endAddress_; bool dirty_; public: char buffer[LENGTH+1]; StringBuffer(unsigned int address) { dirty_ = false; address_ = address; // Move calculating end address into startup. Timing for // parsing loop is more critical than the extra 2 bytes of ram. endAddress_ = address+LENGTH; memset(buffer, '\0', LENGTH+1); } // Replace callback with external dirty flag. Callbacks are // not safe inside protcol parsing due to timing criticallity. bool isDirty() { return dirty_; } void clearDirty() { dirty_ = false; } }; class IntegerBuffer : ExportStreamListener { private: void onDcsBiosWrite(unsigned int address, unsigned int value) { if (address == address_) { data = (value & mask_) >> shift_; } } unsigned int address_; unsigned int mask_; unsigned char shift_; bool dirty_; public: int data; IntegerBuffer(unsigned int address, unsigned int mask, unsigned char shift) { dirty_ = false; address_ = address; mask_ = mask; shift_ = shift; } bool isDirty() { return dirty_; } void clearDirty() { dirty_ = false; } }; } #endif
mdjarv/dcs-bios-arduino-library
Switches.h
#ifndef __DCSBIOS_SWITCHES_H #define __DCSBIOS_SWITCHES_H #include "Arduino.h" #include "PollingInput.h" namespace DcsBios { class Switch2Pos : PollingInput { private: void pollInput(); char* msg_; char pin_; char lastState_; public: Switch2Pos(char* msg, char pin); }; class Switch3Pos : PollingInput { private: void pollInput(); char* msg_; char pinA_; char pinB_; char lastState_; char readState(); public: Switch3Pos(char* msg, char pinA, char pinB); }; class SwitchMultiPos : PollingInput { private: void pollInput(); char* msg_; const byte* pins_; char numberOfPins_; char lastState_; char readState(); public: SwitchMultiPos(char* msg_, const byte* pins, char numberOfPins); }; } #endif
mdjarv/dcs-bios-arduino-library
Potentiometers.h
#ifndef __DCSBIOS_POTS_H #define __DCSBIOS_POTS_H #include "Arduino.h" #include "PollingInput.h" namespace DcsBios { class Potentiometer : PollingInput { private: void pollInput(); char* msg_; char pin_; unsigned int lastState_; public: Potentiometer(char* msg, char pin); }; } #endif
mdjarv/dcs-bios-arduino-library
Encoders.h
#ifndef __DCSBIOS_ENCODERS_H #define __DCSBIOS_ENCODERS_H #include "Arduino.h" #include "PollingInput.h" namespace DcsBios { class RotaryEncoder : PollingInput { private: void pollInput(); char readState(); const char* msg_; const char* decArg_; const char* incArg_; char pinA_; char pinB_; char lastState_; signed char delta_; public: RotaryEncoder(const char* msg, const char* decArg, const char* incArg, char pinA, char pinB); }; } #endif
mdjarv/dcs-bios-arduino-library
Servos.h
#ifndef __DCSBIOS_SERVOS_H #define __DCSBIOS_SERVOS_H #include "Arduino.h" #include "ExportStreamListener.h" #include <Servo.h> namespace DcsBios { class ServoOutput : IntegerBuffer { private: void onDcsBiosFrameSync(); Servo servo_; char pin_; int minPulseWidth_; int maxPulseWidth_; public: ServoOutput(unsigned int address, char pin, int minPulseWidth, int maxPulseWidth); ServoOutput(unsigned int address, char pin); }; } #endif
mdjarv/dcs-bios-arduino-library
PollingInput.h
#ifndef __DCSBIOS_POLLINGINPUT_H #define __DCSBIOS_POLLINGINPUT_H #include "Arduino.h" void sendDcsBiosMessage(const char* msg, const char* args); namespace DcsBios { class PollingInput { private: virtual void pollInput(); PollingInput* nextPollingInput; public: static PollingInput* firstPollingInput; PollingInput() { this->nextPollingInput = firstPollingInput; firstPollingInput = this; } static void pollInputs() { PollingInput* pi = firstPollingInput; while (pi) { pi->pollInput(); pi = pi->nextPollingInput; } } }; } #endif
mdjarv/dcs-bios-arduino-library
Protocol.h
#ifndef __DCSBIOS_PROTOCOL_H #define __DCSBIOS_PROTOCOL_H void onDcsBiosWrite(unsigned int address, unsigned int value); void onDcsBiosFrameSync(); #define DCSBIOS_STATE_WAIT_FOR_SYNC 0 #define DCSBIOS_STATE_ADDRESS_LOW 1 #define DCSBIOS_STATE_ADDRESS_HIGH 2 #define DCSBIOS_STATE_COUNT_LOW 3 #define DCSBIOS_STATE_COUNT_HIGH 4 #define DCSBIOS_STATE_DATA_LOW 5 #define DCSBIOS_STATE_DATA_HIGH 6 namespace DcsBios { class ProtocolParser { private: unsigned char state; unsigned int address; unsigned int count; unsigned int data; unsigned char sync_byte_count; public: void processChar(unsigned char c); ProtocolParser(); }; } #endif
alexandergr/INFView
INFView/INFLayoutStrategy.h
<gh_stars>1-10 // // INFLayoutStrategy.h // INFView // // Created by Alexander on 2/9/18. // Copyright © 2018 Alexander. All rights reserved. // #import <Foundation/Foundation.h> #import <UIKit/UIKit.h> #import "INFViewLayout.h" #import "INFOrientation.h" typedef enum : NSUInteger { INFLayoutStrategyTypeSimple, } INFLayoutStrategyType; @protocol INFViewsSizeStorage - (NSInteger)countOfViews; - (CGSize)sizeOfViewAtIndex:(NSInteger)index; - (CGSize)accurateSizeOfViewAtIndex:(NSInteger)index; @end @protocol INFLayoutStrategy @property (nonatomic) INFOrientation orientation; @property (nonatomic) CGSize scrollViewSize; @property (weak, nonatomic) id<INFViewsSizeStorage> sizesStorage; - (INFViewLayout*)layoutArrangedViewsForContentOffset:(CGPoint)contentOffset; @end
alexandergr/INFView
INFView/INFOrientation.h
// // INFOrientation.h // INFView // // Created by <NAME> on 2/1/18. // Copyright © 2018 Alexander. All rights reserved. // typedef enum : NSUInteger { INFOrientationHorizontal, INFOrientationVertical } INFOrientation;
alexandergr/INFView
INFView/INFLayoutViewInfo.h
<filename>INFView/INFLayoutViewInfo.h // // INFViewLayoutInfo.h // INFView // // Created by <NAME> on 2/1/18. // Copyright © 2018 Alexander. All rights reserved. // #import <Foundation/Foundation.h> #import <CoreGraphics/CoreGraphics.h> #import "INFOrientation.h" @interface INFLayoutViewInfo : NSObject @property (nonatomic) NSInteger index; @property (nonatomic) CGPoint center; @property (nonatomic) CGSize size; - (instancetype)initWithIndex:(NSInteger)index size:(CGSize)size; - (CGFloat)getPositionForOrientation:(INFOrientation)orientation; - (void)setPosition:(CGFloat)position forOrientation:(INFOrientation)orientation; - (void)shiftPosition:(CGFloat)shift forOrientation:(INFOrientation)orientation; - (CGFloat)getLengthForOrientation:(INFOrientation)orientation; @end
alexandergr/INFView
INFView/INFViewLayout.h
// // INFViewLayout.h // INFView // // Created by Alexander on 2/9/18. // Copyright © 2018 Alexander. All rights reserved. // #import <Foundation/Foundation.h> #import "INFLayoutViewInfo.h" #import "INFOrientation.h" @interface INFViewLayout : NSObject @property (nonatomic) INFOrientation orientation; @property (nonatomic) CGSize scrollViewSize; @property (nonatomic) CGPoint contentOffset; @property (nonatomic) CGSize contentSize; @property (strong, nonatomic) NSArray<INFLayoutViewInfo*>* viewsLayoutInfo; @property (nonatomic) NSRange leadingViewsRange; @property (nonatomic) NSRange trailingViewsRange; @property (nonatomic) BOOL canHaveInfiniteScrolling; - (CGFloat)getContentOffsetPosition; - (void)setContentOffsetPosition:(CGFloat)position; - (void)setContentLength:(CGFloat)contentLength; - (CGFloat)lengthOfViewsInRange:(NSRange)range; - (CGFloat)lengthOfAllViews; - (CGFloat)lengthOfLeadingViews; - (CGFloat)lengthOfTrailingViews; - (void)moveViewsInRange:(NSRange)range position:(CGFloat)position; - (void)shiftViewsWithOffset:(CGFloat)offset; - (void)setAccurateSize:(CGSize)size forViewAtIndex:(NSInteger)index; - (NSArray<INFLayoutViewInfo*>*)getViewsInAreaFrom:(CGFloat)startPosition to:(CGFloat)endPosition; - (NSArray<INFLayoutViewInfo*>*)getViewsInVisibleArea; @end
alexandergr/INFView
INFViewTests/Fakes/FakeViewsSizeStorage.h
<gh_stars>1-10 // // FakeViewsSizeStorage.h // INFViewTests // // Created by <NAME> on 3/7/18. // Copyright © 2018 Alexander. All rights reserved. // #import <Foundation/Foundation.h> #import "INFLayoutStrategy.h" @interface FakeViewsSizeStorage : NSObject <INFViewsSizeStorage> @property (nonatomic) NSInteger countOfViews; @property (nonatomic) CGSize estimatedSize; @property (nonatomic) CGSize accurateSize; - (instancetype)initWithCountOfViews:(NSInteger)countOfViews estimatedSize:(CGSize)estimatedSize accurateSize:(CGSize)accurateSize; @end
alexandergr/INFView
INFView/INFSimpleLayoutStrategy.h
// // INFSimpleLayoutStrategy.h // INFView // // Created by Alexander on 2/9/18. // Copyright © 2018 Alexander. All rights reserved. // #import <Foundation/Foundation.h> #import "INFLayoutStrategy.h" #import "INFOrientation.h" @interface INFSimpleLayoutStrategy : NSObject<INFLayoutStrategy> @property (nonatomic) INFOrientation orientation; @property (nonatomic) CGSize scrollViewSize; @property (weak, nonatomic) id<INFViewsSizeStorage> sizesStorage; - (INFViewLayout*)layoutArrangedViewsForContentOffset:(CGPoint)contentOffset; @end
alexandergr/INFView
INFView/INFScrollView.h
<filename>INFView/INFScrollView.h // // INFScrollView.h // INFView // // Created by Alexander on 2/1/18. // Copyright © 2018 Alexander. All rights reserved. // #import <UIKit/UIKit.h> #import "INFOrientation.h" @protocol INFScrollViewDataSource; @protocol INFScrollViewDelegate; @interface INFScrollView : UIScrollView @property (weak, nonatomic, nullable) id<INFScrollViewDataSource> dataSource; @property (weak, nonatomic, nullable) id<INFScrollViewDelegate, UIScrollViewDelegate> delegate; @property (nonatomic) INFOrientation orientation; -(void)reloadData; @end @protocol INFScrollViewDataSource <NSObject> @required - (NSInteger)numberOfArrangedViewsInINFScrollView:(nonnull INFScrollView*)scrollView; - (nonnull UIView*)infScrollView:(nonnull INFScrollView*)infView arrangedViewForIndex:(NSInteger)index; @optional - (CGSize)infScrollView:(nonnull INFScrollView*)scrollView estimatedSizeForViewAtIndex:(NSInteger)index; - (CGSize)infScrollView:(nonnull INFScrollView*)scrollView sizeForViewAtIndex:(NSInteger)index; @end @protocol INFScrollViewDelegate <NSObject> @optional - (void)infScrollView:(nonnull INFScrollView*)scrollView willShowViewAtIndex:(NSInteger)index; - (void)infScrollView:(nonnull INFScrollView*)scrollView didShowViewAtIndex:(NSInteger)index; - (void)infScrollView:(nonnull INFScrollView*)scrollView willHideViewAtIndex:(NSInteger)index; - (void)infScrollView:(nonnull INFScrollView*)scrollView didHideViewAtIndex:(NSInteger)index; @end
alexandergr/INFView
INFView/INFView.h
// // INFView.h // INFView // // Created by Alexander on 2/1/18. // Copyright © 2018 Alexander. All rights reserved. // #import <UIKit/UIKit.h> //! Project version number for INFView. FOUNDATION_EXPORT double INFViewVersionNumber; //! Project version string for INFView. FOUNDATION_EXPORT const unsigned char INFViewVersionString[]; // In this header, you should import all the public headers of your framework using statements like #import <INFView/PublicHeader.h> #import <INFView/INFScrollView.h>
alexandergr/INFView
INFViewTests/Fakes/FakeLayoutDataSource.h
<reponame>alexandergr/INFView // // FaceLayoutDataSource.h // INFViewTests // // Created by <NAME> on 3/14/18. // Copyright © 2018 Alexander. All rights reserved. // #import <Foundation/Foundation.h> #import "INFLayoutManager.h" @interface FakeLayoutDataSource : NSObject <INFLayoutDataSource> @property (strong, nonatomic) NSArray<NSNumber*>* viewsWidth; @property (nonatomic) CGFloat viewsHeight; - (instancetype)initWithViewsWidth:(NSArray<NSNumber*>*)viewsWidth viewsHeight:(CGFloat)viewsHeight; @end
alexandergr/INFView
INFView/INFLayoutManager.h
// // INFLayoutManager.h // INFView // // Created by <NAME> on 2/1/18. // Copyright © 2018 Alexander. All rights reserved. // #import <Foundation/Foundation.h> #import <CoreGraphics/CoreGraphics.h> #import "INFLayoutStrategy.h" @protocol INFLayoutTarget; @protocol INFLayoutDataSource; @protocol INFLayoutDelegate; @interface INFLayoutManager: NSObject @property (nonatomic) CGSize scrollViewSize; @property (nullable, weak, nonatomic) id<INFLayoutTarget> target; @property (nullable, weak, nonatomic) id<INFLayoutDataSource> dataSource; @property (nullable, weak, nonatomic) id<INFLayoutDelegate> delegate; @property (nonnull, strong, nonatomic) id<INFLayoutStrategy> strategy; @property (nonatomic) INFOrientation orientation; - (nonnull instancetype)initWithLayoutStrategyType:(INFLayoutStrategyType)layoutStrategyType NS_DESIGNATED_INITIALIZER; - (void)arrangeViews; - (void)updateArrangedViewsForNewContentOffset:(CGPoint)contentOffset; @end @protocol INFLayoutDataSource - (NSInteger)numberOfArrangedViews; - (CGSize)sizeForViewAtIndex:(NSInteger)index; - (CGSize)estimatedSizeForViewAtIndex:(NSInteger)index; @end @protocol INFLayoutTarget - (void)updateContentSize:(CGSize)contentSize; - (void)updateContentOffset:(CGPoint)contentOffset; - (void)updateArrangedViewWithLayoutInfo:(nonnull INFLayoutViewInfo*)viewInfo; @end @protocol INFLayoutDelegate - (void)willShowViewAtIndex:(NSInteger)index; - (void)didShowViewAtIndex:(NSInteger)index; - (void)willHideViewAtIndex:(NSInteger)index; - (void)didHideViewAtIndex:(NSInteger)index; @end