void hex_init(t_hex *self, int size) { int i, x, y, ry, pos; int id = 0; t_node *node; for (i = 0; i < MAX_CODE; ++i) { self->nodes_by_pos[i] = NULL; } self->size = size; self->count = 3 * size * (size - 1) + 1; for (y = 0; y < size; ++y) { for (x = 0; x < size + y; ++x) { pos = make_point(x, y); node = &self->nodes_by_id[id]; node_init(node, pos, id, 0, NULL); self->nodes_by_pos[pos] = node; id += 1; } } for (y = 1; y < size; ++y) { ry = size - 1 + y; for (x = y; x < 2 * size - 1; ++x) { pos = make_point(x, ry); node = &self->nodes_by_id[id]; node_init(node, pos, id, 0, NULL); self->nodes_by_pos[pos] = node; id += 1; } } }
int main(){ struct rectangle rect1 = make_rectangle(make_point(2,1), make_point(4,6)); struct rectangle rect2 = make_rectangle(make_point(3,3), make_point(9,9)); printf("Intersection: %d\n", is_intersect(rect1, rect2)); return 0; }
void HeeksDxfRead::OnReadLine(const double* s, const double* e, bool hidden) { HLine* new_object = new HLine(make_point(s), make_point(e), hidden ? (&hidden_color) : ActiveColorPtr(m_aci)); if (m_thickness != 0.0) { new_object->m_thickness = m_thickness; for (int i = 0; i < 3; i++)new_object->m_extrusion_vector[i] = m_extrusion_vector[i]; } AddObject(new_object); }
TEST( rod_nullable , function_return ) { rod::nullable< point > valid = make_point(1,2,true); ASSERT_TRUE(valid); ASSERT_EQ( valid->x , 1 ); ASSERT_EQ( valid->y , 2 ); rod::nullable< point > invalid = make_point(1,2,false); ASSERT_FALSE(invalid); //bool is not allowed //rod::nullable<bool> ttt; }
bool HImage::Stretch(const double *p, const double* shift, void* data){ gp_Pnt vp = make_point(p); gp_Vec vshift = make_vector(shift); for(int i = 0; i<4; i++){ gp_Pnt vt = make_point(m_x[i]); if(vt.IsEqual(vp, wxGetApp().m_geom_tol)){ vt = vt.XYZ() + vshift.XYZ(); extract(vt, m_x[i]); break; } } return false; }
void mesh_bounds( const Mesh& m, Point& pmin, Point& pmax ) { if(m.positions.size() < 1) return; pmin= make_point(m.positions[0].x, m.positions[0].y, m.positions[0].z); pmax= pmin; for(unsigned int i= 1; i < (unsigned int) m.positions.size(); i++) { vec3 p= m.positions[i]; pmin= make_point( std::min(pmin.x, p.x), std::min(pmin.y, p.y), std::min(pmin.z, p.z) ); pmax= make_point( std::max(pmax.x, p.x), std::max(pmax.y, p.y), std::max(pmax.z, p.z) ); } }
bool HeeksObj::StretchTemporaryTransformed(const double *p, const double* shift, void* data) { #ifdef HEEKSCAD gp_Trsf mat; #ifdef MULTIPLE_OWNERS HeeksObj* owner = Owner(); #else HeeksObj* owner = m_owner; #endif CSketch *sketch = dynamic_cast<CSketch*>(owner); if(sketch && sketch->m_coordinate_system) mat = sketch->m_coordinate_system->GetMatrix(); //mat.Invert(); gp_Pnt vp = make_point(p); gp_Vec vshift = make_vector(shift); //vp.Transform(mat); //vshift.Transform(mat); double np[3]; double nshift[3]; extract(vp,np); extract(vshift,nshift); return StretchTemporary(np,nshift,data); #else return StretchTemporary(p,shift,data); #endif }
void CCuboid::SetFromXMLElement(TiXmlElement* pElem) { double l[3] = {0, 0, 0}; double d[3] = {0, 0, 1}; double x[3] = {1, 0, 0}; for(TiXmlAttribute* a = pElem->FirstAttribute(); a; a = a->Next()) { std::string name(a->Name()); if(name == "lx") {l[0] = a->DoubleValue();} else if(name == "ly"){l[1] = a->DoubleValue();} else if(name == "lz"){l[2] = a->DoubleValue();} else if(name == "dx"){d[0] = a->DoubleValue();} else if(name == "dy"){d[1] = a->DoubleValue();} else if(name == "dz"){d[2] = a->DoubleValue();} else if(name == "xx"){x[0] = a->DoubleValue();} else if(name == "xy"){x[1] = a->DoubleValue();} else if(name == "xz"){x[2] = a->DoubleValue();} else if(name == "wx"){m_x = a->DoubleValue();} else if(name == "wy"){m_y = a->DoubleValue();} else if(name == "wz"){m_z = a->DoubleValue();} } m_pos = gp_Ax2(make_point(l), make_vector(d), make_vector(x)); CSolid::SetFromXMLElement(pElem); }
void HeeksDxfRead::OnReadCircle(const double* s, const double* c, bool dir, bool hidden) { gp_Pnt p0 = make_point(s); //gp_Pnt p1 = make_point(e); gp_Dir up(0, 0, 1); if(!dir)up = -up; gp_Pnt pc = make_point(c); gp_Circ circle(gp_Ax2(pc, up), p0.Distance(pc)); HCircle* new_object = new HCircle(circle, hidden ? (&hidden_color) : ActiveColorPtr(m_aci)); if (m_thickness != 0.0) { new_object->m_thickness = m_thickness; for (int i = 0; i < 3; i++)new_object->m_extrusion_vector[i] = m_extrusion_vector[i]; } AddObject(new_object); }
void CCylinder::SetFromXMLElement(TiXmlElement* pElem) { // get the attributes double l[3] = {0, 0, 0}; double d[3] = {0, 0, 1}; double x[3] = {1, 0, 0}; for(TiXmlAttribute* a = pElem->FirstAttribute(); a; a = a->Next()) { std::string name(a->Name()); if(name == "lx") {l[0] = a->DoubleValue();} else if(name == "ly"){l[1] = a->DoubleValue();} else if(name == "lz"){l[2] = a->DoubleValue();} else if(name == "dx"){d[0] = a->DoubleValue();} else if(name == "dy"){d[1] = a->DoubleValue();} else if(name == "dz"){d[2] = a->DoubleValue();} else if(name == "xx"){x[0] = a->DoubleValue();} else if(name == "xy"){x[1] = a->DoubleValue();} else if(name == "xz"){x[2] = a->DoubleValue();} else if(name == "r"){m_radius = a->DoubleValue();} else if(name == "h"){m_height = a->DoubleValue();} } m_pos = gp_Ax2(make_point(l), make_vector(d), make_vector(x)); CSolid::SetFromXMLElement(pElem); }
bool CSketchRelinker::TryAdd(HeeksObj* object) { // if the object is not already added if(m_added_from_old_set.find(object) == m_added_from_old_set.end()) { double old_point[3]; double new_point[3]; m_new_back->GetEndPoint(old_point); // try the object, the right way round object->GetStartPoint(new_point); if(make_point(old_point).IsEqual(make_point(new_point), wxGetApp().m_sketch_reorder_tol)) { m_new_lists.back().push_back(object); m_new_back = object; m_added_from_old_set.insert(object); return true; } // try the object, the wrong way round object->GetEndPoint(new_point); if(make_point(old_point).IsEqual(make_point(new_point), wxGetApp().m_sketch_reorder_tol)) { CSketch::ReverseObject(object); m_new_lists.back().push_back(object); m_new_back = object; m_added_from_old_set.insert(object); return true; } // try at the start m_new_front->GetStartPoint(old_point); // try the object, the right way round object->GetEndPoint(new_point); if(make_point(old_point).IsEqual(make_point(new_point), wxGetApp().m_sketch_reorder_tol)) { m_new_lists.back().push_front(object); m_new_front = object; m_added_from_old_set.insert(object); return true; } // try the object, the wrong way round object->GetStartPoint(new_point); if(make_point(old_point).IsEqual(make_point(new_point), wxGetApp().m_sketch_reorder_tol)) { CSketch::ReverseObject(object); m_new_lists.back().push_front(object); m_new_front = object; m_added_from_old_set.insert(object); return true; } } return false; }
Point* compute_mid(Point* a, Point* b) { double mid_x = (a->x + b->x) / 2, mid_y = (a->y + b->y) / 2; Point* mid = make_point(mid_x, mid_y); return mid; }
void HeeksDxfRead::OnReadPoint(const double* s) { if(m_read_points) { HPoint* new_object = new HPoint(make_point(s), ActiveColorPtr(m_aci)); AddObject(new_object); } }
void HImage::ModifyByMatrix(const double *m) { gp_Trsf mat = make_matrix(m); for(int i = 0; i<4; i++){ gp_Pnt vt = make_point(m_x[i]); extract(vt.Transformed(mat), m_x[i]); } }
void HeeksDxfRead::OnReadEllipse(const double* c, double major_radius, double minor_radius, double rotation, double start_angle, double end_angle, bool dir) { gp_Dir up(0, 0, 1); if(!dir)up = -up; gp_Pnt pc = make_point(c); gp_Elips ellipse(gp_Ax2(pc, up), major_radius, minor_radius); ellipse.Rotate(gp_Ax1(pc,up),rotation); HEllipse* new_object = new HEllipse(ellipse, start_angle, end_angle, ActiveColorPtr(m_aci)); AddObject(new_object); }
void print_pos(t_pos *pos) { int i, x, y, ry, pos2, id; t_hex *hex = &pos->hex; t_done *done = &pos->done; int size = hex->size; for (y = 0; y < size; ++y) { for (i = 0; i < size - y - 1; ++i) { putchar(' '); } for (x = 0; x < size + y; ++x) { pos2 = make_point(x, y); id = get_by_pos(hex, pos2)->id; if (already_done(done, id) && (done->cells[id] < 7)) { putchar('0' + done->cells[id]); } else { putchar('.'); } putchar(' '); } putchar('\n'); } for (y = 1; y < size; ++y) { ry = size - 1 + y; for (i = 0; i < y; ++i) { putchar(' '); } for (x = y; x < 2 * size - 1; ++x) { pos2 = make_point(x, ry); id = get_by_pos(hex, pos2)->id; if (already_done(done, id) && (done->cells[id] < 7)) { putchar('0' + done->cells[id]); } else { putchar('.'); } putchar(' '); } putchar('\n'); } //print_tiles(&pos->tiles); //printf("Sum tiles: %d\n", pos->sum_tiles); }
void HeeksDxfRead::OnReadDimension(int dimension_type, double angle, double angle2, double angle3, double radius_leader_length, const double *def_point, const double *mid, const double *p1, const double *p2, const double *p3, const double *p4, const double *p5) { int type = (dimension_type & 0x07); gp_Pnt d = make_point(def_point); gp_Pnt m = make_point(mid); gp_Vec d_to_m = make_vector(d, m); gp_Pnt e = gp_Pnt(m.XYZ() + d_to_m.XYZ()); gp_Dir forward(1,0,0); HeeksColor c(0, 0, 0); if(type == 0) { forward.Rotate(gp_Ax1(gp_Pnt(0, 0, 0), gp_Dir(0, 0, 1)), (angle/* + angle2 + angle3*/) * -0.01745329251); } else { forward = gp_Dir(-d_to_m); c = HeeksColor(255, 0, 0); } gp_Dir left(-forward.Y(), forward.X(), 0.0); double arrow_size = 5.0; gp_Pnt da1 = d.XYZ() + forward.XYZ() * (-arrow_size) + left.XYZ() * (arrow_size * 0.25); gp_Pnt da2 = d.XYZ() + forward.XYZ() * (-arrow_size) + left.XYZ() * (arrow_size * -0.25); gp_Pnt ea1 = e.XYZ() + forward.XYZ() * (arrow_size) + left.XYZ() * (arrow_size * 0.25); gp_Pnt ea2 = e.XYZ() + forward.XYZ() * (arrow_size) + left.XYZ() * (arrow_size * -0.25); AddObject(new HLine(d, da1, &c)); AddObject(new HLine(da1, da2, &c)); AddObject(new HLine(da2, d, &c)); AddObject(new HLine(e, ea1, &c)); AddObject(new HLine(ea1, ea2, &c)); AddObject(new HLine(ea2, e, &c)); }
int main() { double x, y; printf("Enter coordinates of point A: "); scanf("%lf %lf", &x, &y); Point* a = make_point(x, y); printf("Enter coordinates of point B: "); scanf("%lf %lf", &x, &y); Point* b = make_point(x, y); Point* c = compute_mid(a, b); print_point(c); destroy_point(a); destroy_point(b); destroy_point(c); return 0; }
bool HDimension::Stretch(const double *p, const double* shift, void* data) { EndedObject::Stretch(p,shift,data); gp_Pnt vp = make_point(p); gp_Vec vshift = make_vector(shift); if(data == &m_p2){ m_p2->m_p = vp.XYZ() + vshift.XYZ(); } return false; }
CheapPointType pad_or_pin_center(PadOrPinType* pp) { if (pp->pad) { return pad_center(pp->pad); } else if (pp->pin) { return pin_center(pp->pin); } else { base_log("Error: pad_or_pin_center() got an empty PadOrPinType.\n"); return make_point(0, 0); } }
static void lineAddFunction(const double *p) { gp_Pnt pnt = make_point(p); if(lines_started) { HLine* new_object = new HLine(prev_point, pnt, &wxGetApp().current_color); sketch_for_make->Add(new_object, NULL); } lines_started = true; prev_point = pnt; }
int main(int argc, char *argv[]) { void *myso = dlopen("./libpoints.dylib", RTLD_NOW); _make_point *make_point = dlsym(myso, "make_point"); _free_point *free_point = dlsym(myso, "free_point"); _get_distance *get_distance = dlsym(myso, "get_distance"); struct Point* a = make_point(10,10); struct Point* b = make_point(20,20); double d = get_distance(a,b); printf("distance: %f\n", d); free_point(a); free_point(b); dlclose(myso); return 0; }
main() { #define SIZE 5 struct point point_1 = { 5, 10 }; struct point *p = &point_1; struct point points[SIZE]; struct point* pps = points; int i; struct { int len; char *str; } *a; struct string s = { 6, "hello" }; struct { int len; char *str; } ss; ss.len = 6; ss.str = "hello"; /* causes a misaligned address error, because a points to nothing */ /* a->len = 6; a->str = "hello"; */ a = &ss; //warning incompatible pointer type printf("Point1: (x, y) --> (%d, %d)\n", point_1.x, point_1.y); printf("Point1: (x, y) --> (%d, %d)\n", p->x, p->y); printf("playing around with pointers and structs\n"); for (i = 0; i < SIZE; i++) { points[i] = make_point(i, i + 10); } printf("(%d, %d)\n", (*pps).x, (*pps).y); printf("(%d, %d)\n", (*++pps).x, (*++pps).y); printf("(%d, %d)\n", ++(*pps).x, ++(*pps).y); printf("a points to \nstruct {\n\t int len;\n\tchar *str;\n\t} *a;\n"); printf("a->len: %d, a->str: %s\n", (*a).len, (*a).str); }//end main
bool CCuboid::Stretch(const double *p, const double* shift, void* data) { gp_Pnt vp = make_point(p); gp_Vec vshift = make_vector(shift); gp_Pnt o = m_pos.Location(); gp_Dir z_dir = m_pos.XDirection() ^ m_pos.YDirection(); gp_Pnt m2(o.XYZ() + m_pos.XDirection().XYZ() * m_x + m_pos.YDirection().XYZ() * m_y/2); gp_Pnt m3(o.XYZ() + m_pos.XDirection().XYZ() * m_x/2 + m_pos.YDirection().XYZ() * m_y); gp_Pnt m8(o.XYZ() + m_pos.YDirection().XYZ() * m_y/2 + z_dir.XYZ() * m_z); bool make_a_new_cuboid = false; if(m2.IsEqual(vp, wxGetApp().m_geom_tol)){ m2 = m2.XYZ() + vshift.XYZ(); double new_x = gp_Vec(m2.XYZ()) * gp_Vec(m_pos.XDirection()) - gp_Vec(o.XYZ()) * gp_Vec(m_pos.XDirection()); if(new_x > 0){ make_a_new_cuboid = true; m_x = new_x; } } else if(m3.IsEqual(vp, wxGetApp().m_geom_tol)){ m3 = m3.XYZ() + vshift.XYZ(); double new_y = gp_Vec(m3.XYZ()) * gp_Vec(m_pos.YDirection()) - gp_Vec(o.XYZ()) * gp_Vec(m_pos.YDirection()); if(new_y > 0){ make_a_new_cuboid = true; m_y = new_y; } } else if(m8.IsEqual(vp, wxGetApp().m_geom_tol)){ m8 = m8.XYZ() + vshift.XYZ(); double new_z = gp_Vec(m8.XYZ()) * gp_Vec(z_dir) - gp_Vec(o.XYZ()) * gp_Vec(z_dir); if(new_z > 0){ make_a_new_cuboid = true; m_z = new_z; } } if(make_a_new_cuboid) { CCuboid* new_object = new CCuboid(m_pos, m_x, m_y, m_z, m_title.c_str(), m_color, m_opacity); new_object->CopyIDsFrom(this); HEEKSOBJ_OWNER->Add(new_object, NULL); HEEKSOBJ_OWNER->Remove(this); wxGetApp().m_marked_list->Clear(false); wxGetApp().m_marked_list->Add(new_object, true); } return true; }
instance_t make(const description_t& description) { BOOST_LOG_TRIVIAL(debug) << "Make camera"; const instance_t instance { make_point(description.origin), make_direction(description.direction), make_direction(description.up), normalize(cross(description.direction, description.up)) }; return std::move(instance); }
void GameState::updateTL(){ bool pullerFound = false; bool pusherFound = false; field pullerField = this->at(puller); field pusherField = this->at(pusher); for(dimension i = 0 ; i< dims.first;i++){ for(dimension j =0; j<dims.second;j++){ if(!pullerFound && this->at(i,j) == pullerField){ pullerTL = make_point(i,j); pullerFound = true; } if(!pusherFound && this->at(i,j) == pusherField){ pusherTL = make_point(i,j); pusherFound = true; } if(pusherFound && pullerFound) break; } } }
static BYTE calculate_rotation_steps(CheapPointType new1_pt, CheapPointType new2_pt, CheapPointType old1_pt, CheapPointType old2_pt) { /* Translation of new1_pt to origin. */ LocationType new1_to_origin_dx = -new1_pt.X; LocationType new1_to_origin_dy = -new1_pt.Y; /* Use translation for new2_pt. */ CheapPointType new2_translated_pt = make_point(new2_pt.X + new1_to_origin_dx, new2_pt.Y + new1_to_origin_dy); double new2_angle = (new2_translated_pt.Y || new2_translated_pt.X ? atan2(new2_translated_pt.Y, new2_translated_pt.X) : 0); /* Translation of old1_pt to origin. */ LocationType old1_to_origin_dx = -old1_pt.X; LocationType old1_to_origin_dy = -old1_pt.Y; /* Use translation for old2_pt. */ CheapPointType old2_translated_pt = make_point(old2_pt.X + old1_to_origin_dx, old2_pt.Y + old1_to_origin_dy); double old2_angle = (old2_translated_pt.X || old2_translated_pt.Y ? atan2(old2_translated_pt.Y, old2_translated_pt.X) : 0); /* Compute rotation, adjust to match atan2 range. */ double angle = old2_angle - new2_angle; if (angle > M_PI) { angle -= 2 * M_PI; } else if (angle < -M_PI) { angle += 2 * M_PI; } debug_log("Rotation: %lf\n", RAD_TO_DEG * angle); /* Return a PCB rotation steps count. */ return angle_to_rotation_steps(angle); }
static YAP_Bool make_point_to_term (geometry_t geometry, const char * functor_name, YAP_Term *term) { double x, y; sequence_t sequence; assert (term != NULL); sequence = (sequence_t) GEOSGeom_getCoordSeq (geometry); if ((sequence == NULL) || (GEOSCoordSeq_getX (sequence, 0, &x) == 0) || (GEOSCoordSeq_getY (sequence, 0, &y) == 0)) return (FALSE); if (make_point (x, y, functor_name, term) == FALSE) return (FALSE); return (TRUE); }
void link_nodes(t_hex *self) { int i, p, d, nx, ny, ncode; t_node *node; for (i = 0; i < self->count; ++i) { node = &self->nodes_by_id[i]; p = node->pos; for (d = 0; d < NB_DIRS; ++d) { nx = point_x(p) + DIRS[d][0]; ny = point_y(p) + DIRS[d][1]; ncode = make_point(nx, ny); if (contains_pos(self, ncode)) { append_link(node, self->nodes_by_pos[ncode]->id); } } } }
int main(void) { //struct point pt; struct point pt = make_point(400,600); printf("%d , %d\n", pt.x, pt.y); struct point maxpt = { 800, 600 }; printf("%d , %d\n", maxpt.x, maxpt.y); printf("the day %d\n", day_of_year(2011, 3, 1)); printf("int size %d\n",sizeof(int)); //32 λ windows int a = 66000; printf("int size %d\n",a); char *p = NULL; if(p==NULL){ printf("NULL\n"); } return EXIT_SUCCESS; }