void test_no_rows(void) { size_t expected[1][1] = { {0} }; size_t **r = create_triangle(0); TEST_ASSERT_TRUE(check(1, expected, r)); free_triangle(r, 1); }
void ShZshapeManager::create_shape(const char* content) { if (content == "cube") { create_cube(); } if (content == "cylinder") { create_cylinder(); } if (content == "pipe") { create_pipe(); } if (content == "cone") { create_cone(); } if (content == "circle") { create_circle(); } if (content == "ring") { create_ring(); } if (content == "pyramid") { create_pyramid(); } if (content == "triangle") { create_triangle(); } if (content == "rectangle") { create_rectangle(); } if (content == "polygon") { create_polygon(); } if (content == "multigonalStar") { create_multigonalStar(); } }
/******************************************************************************************* * NAME : int main(argc, argv) * * DESCRIPTION : Parses arguments to construct a set of points representing a triangle. * Prints to the console the classification of the triangle or an error. * * INPUTS : * PARAMETERS : * int argc number of arguments in argv * char * argv[] strings containing program name, (x,y) pairs */ int main (int argc, char *argv[]) { if (check_arg_count(argc)) { ERROR(); } if (create_triangle(argv)) { ERROR(); } if (check_colinearity()) { NAT(); } compute_triangle_sides(); print_classification(); return 0; }
void test_single_row(void) { TEST_IGNORE(); // delete this line to run test size_t expected[1][1] = { {1} }; size_t **r = create_triangle(1); TEST_ASSERT_TRUE(check(1, expected, r)); free_triangle(r, 1); }
void test_two_rows(void) { TEST_IGNORE(); size_t expected[2][2] = { {1, 0}, {1, 1} }; size_t **r = create_triangle(2); TEST_ASSERT_TRUE(check(2, expected, r)); free_triangle(r, 2); }
void test_three_rows(void) { TEST_IGNORE(); size_t expected[3][3] = { {1, 0, 0}, {1, 1, 0}, {1, 2, 1} }; size_t **r = create_triangle(3); TEST_ASSERT_TRUE(check(3, expected, r)); free_triangle(r, 3); }
void test_four_rows(void) { TEST_IGNORE(); size_t expected[4][4] = { {1, 0, 0, 0}, {1, 1, 0, 0}, {1, 2, 1, 0}, {1, 3, 3, 1} }; size_t **r = create_triangle(4); TEST_ASSERT_TRUE(check(4, expected, r)); free_triangle(r, 4); }
half_edge tetraedron(gl_vertex *v1, gl_vertex *v2, gl_vertex *v3, gl_vertex *v4) { half_edge e12 = create_triangle(v1, v2, v3); half_edge e21 = e12 -> opp; half_edge e13 = e12 -> next; half_edge e31 = e13 -> opp; half_edge e32 = e31 -> next; add_vertex_to_edge(e21,v4); half_edge e24 = e21 -> next; half_edge e42 = e24 -> opp; half_edge e41 = e42 -> next; close_triangle(e32,e24); half_edge e34 = e32 -> next; fill_triangle(e13,e34,e41); return e12; }
void ShZshapeManager::create_shape(const char* content, GLdouble positionX, GLdouble positionY, GLdouble positionZ, GLdouble r) { if (content == "circle") { create_circle(positionX, positionY, positionZ, r); } if (content == "ring") { create_ring(positionX, positionY, positionZ, r); } if (content == "triangle") { create_triangle(positionX, positionY, positionZ, r); } if (content == "rectangle") { create_rectangle(positionX, positionY, positionZ, r); } }
/* * Version: 12.08.12 * Test (e18_triangle.c): * init() * destruct() * create_triangle() * sum_of_data() * * Test (e18.c): * solution() * * Modes: * \0 - normal * v - verbose * */ void test_sweep(char mode) { int input; int output; int answer; int i; struct node *tmp; struct node *data; //struct node *stack; // Test for init() answer = 16; init(&tmp, 16); output = tmp->data; TEST(init(&tmp, 16), output, answer, mode == 'v', , 0x0); answer = 0; output = (int)(tmp->right); TEST(init(&tmp, 16), output, answer, mode == 'v', , 0x1); output = (int)(tmp->left); TEST(init(&tmp, 16), output, answer, mode == 'v', , 0x2); // Test for destruct() answer = 0; destruct(&tmp); output = tmp->data; TEST(destruct(&tmp), output, answer, mode == 'v', , 0x10); output = (int)(tmp->right); TEST(destruct(&tmp), output, answer, mode == 'v', , 0x11); output = (int)(tmp->left); TEST(destruct(&tmp), output, answer, mode == 'v', , 0x12); // Test for create_triangle() data = calloc(10, sizeof(struct node)); printf("%i\n", sizeof(struct node)); for(i = 0; i < 10; i++) { tmp = data + i; tmp->data = i; } for(i = 0; i < 10; i++) { tmp = data + i; print_node(&tmp); } create_triangle(&tmp, &data, 10); printf("\ncreate_triangle()\n"); for(i = 0; i < 10; i++) { tmp = data + i; print_node(&tmp); } free(data); }
bool H2DReader::load_stream(std::istream &is, Mesh *mesh, const char *filename) { int i, j, k, n; Node* en; bool debug = false; mesh->free(); std::string mesh_str = read_file(is); Python p; initpython_reader(); p.exec("from python_reader import read_hermes_format_str"); p.push_str("s", mesh_str); p.exec("vertices, elements, boundaries, curves, refinements" " = read_hermes_format_str(s)"); //// vertices //////////////////////////////////////////////////////////////// p.exec("n = len(vertices)"); n = p.pull_int("n"); if (n < 0) error("File %s: 'vertices' must be a list.", filename); if (n < 2) error("File %s: invalid number of vertices.", filename); // create a hash table large enough int size = HashTable::H2D_DEFAULT_HASH_SIZE; while (size < 8*n) size *= 2; mesh->init(size); // create top-level vertex nodes for (i = 0; i < n; i++) { Node* node = mesh->nodes.add(); assert(node->id == i); node->ref = TOP_LEVEL_REF; node->type = HERMES_TYPE_VERTEX; node->bnd = 0; node->p1 = node->p2 = -1; node->next_hash = NULL; p.push_int("i", i); p.exec("x, y = vertices[i]"); node->x = p.pull_double("x"); node->y = p.pull_double("y"); } mesh->ntopvert = n; //// elements //////////////////////////////////////////////////////////////// p.exec("n = len(elements)"); n = p.pull_int("n"); if (n < 0) error("File %s: 'elements' must be a list.", filename); if (n < 1) error("File %s: no elements defined.", filename); // create elements mesh->nactive = 0; for (i = 0; i < n; i++) { // read and check vertex indices p.push_int("i", i); p.exec("nv = len(elements[i])"); int nv = p.pull_int("nv"); int idx[5]; std::string el_marker; if (!nv) { mesh->elements.skip_slot(); continue; } if (nv < 4 || nv > 5) error("File %s: element #%d: wrong number of vertex indices.", filename, i); if (nv == 4) { p.exec("n1, n2, n3, marker = elements[i]"); idx[0] = p.pull_int("n1"); idx[1] = p.pull_int("n2"); idx[2] = p.pull_int("n3"); p.exec("marker_str = 1 if isinstance(marker, str) else 0"); if (p.pull_int("marker_str")) el_marker = p.pull_str("marker"); else { std::ostringstream string_stream; string_stream << p.pull_int("marker"); el_marker = string_stream.str(); } } else { p.exec("n1, n2, n3, n4, marker = elements[i]"); idx[0] = p.pull_int("n1"); idx[1] = p.pull_int("n2"); idx[2] = p.pull_int("n3"); idx[3] = p.pull_int("n4"); p.exec("marker_str = 1 if isinstance(marker, str) else 0"); if (p.pull_int("marker_str")) el_marker = p.pull_str("marker"); else { std::ostringstream string_stream; string_stream << p.pull_int("marker"); el_marker = string_stream.str(); } } for (j = 0; j < nv-1; j++) if (idx[j] < 0 || idx[j] >= mesh->ntopvert) error("File %s: error creating element #%d: vertex #%d does not exist.", filename, i, idx[j]); Node *v0 = &mesh->nodes[idx[0]], *v1 = &mesh->nodes[idx[1]], *v2 = &mesh->nodes[idx[2]]; int marker; // This functions check if the user-supplied marker on this element has been // already used, and if not, inserts it in the appropriate structure. mesh->element_markers_conversion.insert_marker(mesh->element_markers_conversion.min_marker_unused, el_marker); marker = mesh->element_markers_conversion.get_internal_marker(el_marker); if(nv == 4) { check_triangle(i, v0, v1, v2); create_triangle(mesh, marker, v0, v1, v2, NULL); } else { Node *v3 = &mesh->nodes[idx[3]]; check_quad(i, v0, v1, v2, v3); create_quad(mesh, marker, v0, v1, v2, v3, NULL); } mesh->nactive++; } mesh->nbase = n; //// boundaries ////////////////////////////////////////////////////////////// p.exec("have_boundaries = 1 if boundaries else 0"); if (p.pull_int("have_boundaries")) { p.exec("n = len(boundaries)"); n = p.pull_int("n"); // read boundary data for (i = 0; i < n; i++) { int v1, v2, marker; p.push_int("i", i); p.exec("v1, v2, marker = boundaries[i]"); v1 = p.pull_int("v1"); v2 = p.pull_int("v2"); en = mesh->peek_edge_node(v1, v2); if (en == NULL) error("File %s: boundary data #%d: edge %d-%d does not exist", filename, i, v1, v2); std::string bnd_marker; p.exec("marker_str = 1 if isinstance(marker, str) else 0"); if (p.pull_int("marker_str")) bnd_marker = p.pull_str("marker"); else { std::ostringstream string_stream; string_stream << p.pull_int("marker"); bnd_marker = string_stream.str(); } // This functions check if the user-supplied marker on this element has been // already used, and if not, inserts it in the appropriate structure. mesh->boundary_markers_conversion.insert_marker(mesh->boundary_markers_conversion.min_marker_unused, bnd_marker); marker = mesh->boundary_markers_conversion.get_internal_marker(bnd_marker); en->marker = marker; // This is extremely important, as in DG, it is assumed that negative boundary markers are reserved // for the inner edges. if (marker > 0) { mesh->nodes[v1].bnd = 1; mesh->nodes[v2].bnd = 1; en->bnd = 1; } } } #ifdef HERMES_COMMON_CHECK_BOUNDARY_CONDITIONS // check that all boundary edges have a marker assigned for_all_edge_nodes(en, mesh) if (en->ref < 2 && en->marker == 0) { warn("Boundary edge node does not have a boundary marker"); } #endif //// curves ////////////////////////////////////////////////////////////////// p.exec("have_curves = 1 if curves else 0"); if (p.pull_int("have_curves")) { p.exec("n = len(curves)"); n = p.pull_int("n"); if (n < 0) error("File %s: 'curves' must be a list.", filename); // load curved edges for (i = 0; i < n; i++) { // load the control points, knot vector, etc. Node* en; int p1, p2; p.push_int("i", i); p.exec("curve = curves[i]"); Nurbs* nurbs = load_nurbs(mesh, p, i, &en, p1, p2); // assign the nurbs to the elements sharing the edge node for (k = 0; k < 2; k++) { Element* e = en->elem[k]; if (e == NULL) continue; if (e->cm == NULL) { e->cm = new CurvMap; memset(e->cm, 0, sizeof(CurvMap)); e->cm->toplevel = 1; e->cm->order = 4; } int idx = -1; for (unsigned j = 0; j < e->nvert; j++) if (e->en[j] == en) { idx = j; break; } assert(idx >= 0); if (e->vn[idx]->id == p1) { e->cm->nurbs[idx] = nurbs; nurbs->ref++; } else { Nurbs* nurbs_rev = mesh->reverse_nurbs(nurbs); e->cm->nurbs[idx] = nurbs_rev; nurbs_rev->ref++; } } if (!nurbs->ref) delete nurbs; } } // update refmap coeffs of curvilinear elements Element* e; for_all_elements(e, mesh) if (e->cm != NULL) e->cm->update_refmap_coeffs(e); //// refinements ///////////////////////////////////////////////////////////// p.exec("have_refinements = 1 if refinements else 0"); if (p.pull_int("have_refinements")) { p.exec("n = len(refinements)"); n = p.pull_int("n"); if (n < 0) error("File %s: 'refinements' must be a list.", filename); // perform initial refinements for (i = 0; i < n; i++) { int id, ref; p.push_int("i", i); p.exec("id, ref = refinements[i]"); id = p.pull_int("id"); ref = p.pull_int("ref"); mesh->refine_element_id(id, ref); } } mesh->ninitial = mesh->elements.get_num_items(); mesh->seq = g_mesh_seq++; return true; }
void test_negative_rows(void) { TEST_IGNORE(); TEST_ASSERT_TRUE((create_triangle(-1) == NULL)); }