static void analog_clock_update_arrow_tips(Analog_Clock *analog_clock) { time_t now; struct tm *local; now = time(NULL); local = localtime(&now); analog_clock->hour_tip.directions = DIR_ALL; analog_clock->min_tip.directions = DIR_ALL; analog_clock->sec_tip.directions = DIR_ALL; if (local) { make_hours(&analog_clock->centre,local->tm_hour,local->tm_min, 0.50 * analog_clock->radius, &analog_clock->hour_tip.pos); make_minutes(&analog_clock->centre,local->tm_min, 0.80 * analog_clock->radius, &analog_clock->min_tip.pos); make_minutes(&analog_clock->centre,local->tm_sec, 0.85 * analog_clock->radius, &analog_clock->sec_tip.pos); } else { /* Highly unlikely */ point_copy(&analog_clock->hour_tip.pos,&analog_clock->centre); point_copy(&analog_clock->min_tip.pos,&analog_clock->centre); point_copy(&analog_clock->sec_tip.pos,&analog_clock->centre); } }
//sets up the view void view2D_set(View2D *view, Point *vrp, double dx, Vector *x, double screenx, double screeny){ point_copy(&(view->vrp), vrp); view->dx = dx; vector_copy(&(view->x), x); view->screenx = screenx; view->screeny = screeny; }
/** updates point to the point on the arc at angle angle degrees */ void arc_get_point_at_angle(Arc *arc, Point* point, real angle) { Point vec; vec.x = cos(angle/180.0*M_PI); vec.y = -sin(angle/180.0*M_PI); point_copy(point,&arc->center); point_add_scaled(point,&vec,arc->radius); }
/* Return a point described by NAME and the context EC. */ gcry_mpi_point_t _gcry_ecc_get_point (const char *name, mpi_ec_t ec) { if (!strcmp (name, "g") && ec->G) return point_copy (ec->G); if (!strcmp (name, "q")) { /* If only the private key is given, compute the public key. */ if (!ec->Q) ec->Q = _gcry_ecc_compute_public (NULL, ec, NULL, NULL); if (ec->Q) return point_copy (ec->Q); } return NULL; }
/* Store the point NEWVALUE into the context EC under NAME. */ gpg_err_code_t _gcry_ecc_set_point (const char *name, gcry_mpi_point_t newvalue, mpi_ec_t ec) { if (!strcmp (name, "g")) { _gcry_mpi_point_release (ec->G); ec->G = point_copy (newvalue); } else if (!strcmp (name, "q")) { _gcry_mpi_point_release (ec->Q); ec->Q = point_copy (newvalue); } else return GPG_ERR_UNKNOWN_NAME; return 0; }
void point_convex(Point *dst, const Point *src1, const Point *src2, real alpha) { /* Make convex combination of src1 and src2: dst = alpha * src1 + (1-alpha) * src2; */ point_copy(dst,src1); point_scale(dst,alpha); point_add_scaled(dst,src2,1.0 - alpha); }
Piece * piece_copy(Piece * old_piece) { Point ** blocks = (Point **) malloc(sizeof(Point)*4); for (int i=0; i<4; i++) { blocks[i] = point_copy(old_piece->blocks[i]); } Point * center = point_create(old_piece->center->x, old_piece->center->y); Piece * p = malloc (sizeof(Piece)); p->center = center; p->blocks = blocks; return p; }
gpg_err_code_t _gcry_mpi_ec_set_point (const char *name, gcry_mpi_point_t newvalue, gcry_ctx_t ctx) { mpi_ec_t ec = _gcry_ctx_get_pointer (ctx, CONTEXT_TYPE_EC); if (!strcmp (name, "g")) { gcry_mpi_point_release (ec->G); ec->G = point_copy (newvalue); } else if (!strcmp (name, "q")) { gcry_mpi_point_release (ec->Q); ec->Q = point_copy (newvalue); } else return GPG_ERR_UNKNOWN_NAME; return 0; }
/*Modifica los datos de un elemento*/ EleStack * elestack_setInfo(EleStack *ppoint, void *pvoid){ if(!ppoint || !pvoid){ return NULL; } if(ppoint->point){ point_free(ppoint->point); } ppoint->point = point_copy((Point *)pvoid); if(!ppoint->point){ return NULL; } return ppoint; }
/* initializes the vertex list to the points in vlist. De-allocates/allocates the vertex list for p, as necessary */ void polyline_set(Polyline *p, int numV, Point *vlist){ if (p->vertex!=NULL) { free(p->vertex); } p->vertex=malloc(sizeof(Point)*numV); for (int i = 0; i < numV; i++) { point_copy(&(p->vertex[i]),&vlist[i]); } p->numVertex = numV; p->zBuffer = 1; }
/*Modifica los datos de un elemento*/ EleQueue * elequeue_setInfo(EleQueue *pele, void *pvoid){ if(!pele || !pvoid){ return NULL; } if(pele->point){ point_free(pele->point); } pele->point = point_copy((Point *)pvoid); if(!pele->point){ return NULL; } return pele; }
polygon_t* polygon_giftwrap(point_t* points, int num_points) { ASSERT(num_points > 2); ASSERT(all_points_are_coplanar(points, num_points)); // Find the plane of the polygon. vector_t normal; compute_normal(points, num_points, &normal); point_t x0; compute_centroid(points, num_points, &x0); sp_func_t* plane = plane_new(&normal, &x0); // Do the gift-wrapping in 2D. point2_t pts[num_points]; for (int i = 0; i < num_points; ++i) plane_project(plane, &points[i], &pts[i]); polygon2_t* poly2 = polygon2_giftwrap(pts, num_points); #if 0 // Re-embed the resulting vertices in 3D. int num_vertices = polygon2_num_vertices(poly2); point_t vertices[num_vertices]; int pos = 0, offset = 0; point2_t* vtx; while (polygon2_next_vertex(poly2, &pos, &vtx)) plane_embed(plane, vtx, &vertices[offset++]); #endif // Read off the vertex ordering from the planar polygon. Note that // not all of the vertices will be used in general. int num_p2_points = polygon2_num_vertices(poly2); int* ordering = polygon2_ordering(poly2); // Create our polygon with the given ordering. polygon_t* poly = NULL; if (num_p2_points < num_points) { point_t p2_points[num_p2_points]; for (int i = 0; i < num_p2_points; ++i) point_copy(&p2_points[i], &points[ordering[i]]); poly = polygon_new(p2_points, num_p2_points); } else poly = polygon_new_with_ordering(points, ordering, num_points); // Clean up. poly2 = NULL; plane = NULL; return poly; }
/* * Allocate an Element and store a duplicate of the data pointed to by * obj in the Element. Modules do not get duplicated. The function needs * to handle each type of object separately in a case statement. */ Element *element_init(ObjectType type, void *obj){ Element *e = malloc(sizeof(Element)); if(!e){ printf("malloc failed in element_init\n"); return NULL; } e->type = type; e->next = NULL; switch (e->type) { case ObjNone: printf("ObjNone not implemented in element_init\n"); break; case ObjLine: line_copy(&(e->obj.line), (Line*)obj); break; case ObjPoint: point_copy(&(e->obj.point), (Point*)obj); break; case ObjPolyline: polyline_init(&(e->obj.polyline)); polyline_copy(&(e->obj.polyline), (Polyline*)obj); break; case ObjPolygon: polygon_init(&(e->obj.polygon)); polygon_copy(&(e->obj.polygon), (Polygon*)obj); break; case ObjIdentity: break; case ObjMatrix: matrix_copy(&(e->obj.matrix), (Matrix*)obj); break; case ObjColor: case ObjBodyColor: case ObjSurfaceColor: color_copy(&(e->obj.color), (Color*)obj); break; case ObjSurfaceCoeff: e->obj.coeff = *(float*)obj; break; case ObjLight: printf("ObjLight not implemented in element_init\n"); break; case ObjModule: e->obj.module = obj; break; default: printf("ObjectType %d is not handled in element_init\n",type); } return e; }
void point_list_copy(point_list_t *copyer, point_list_t *copee) { dlink_t *a, *b; assert(copyer); assert(copee); assert(point_list_get_count(copyer) == point_list_get_count(copee)); a = copyer->tail->next; for (b = copee->tail->next; b != copee->head; b = b->next) { point_copy((point_t *)a->object, (point_t *)b->object); a = a->next; } }
static real_t distance_from_point_to_line(point_t *p, line_t *line) { real_t len, dist; //point_t *q, *r; point_t a, b; assert(p); assert(line); switch (line->form_type) { case LINE_BY_ENDPOINTS: point_copy(&a, line_get_a(line)); point_copy(&b, line_get_b(line)); break; case LINE_BY_ENDPOINT_DIRECTION: point_copy(&a, line_get_a(line)); point_add(&b, line_get_a(line), line_get_b(line)); break; case LINE_BY_POSITION_DIRECTION: point_copy(&a, line_get_a(line)); point_add(&b, line_get_a(line), line_get_b(line)); break; default: abort(); break; } len = sqrt(sqr(point_get_x(&b) - point_get_x(&a)) + sqr(point_get_y(&b) - point_get_y(&a))); dist = abs((point_get_x(&b) - point_get_x(&a)) * (point_get_y(&a) - point_get_y(p)) - (point_get_x(&a) - point_get_x(p)) * (point_get_y(&b) - point_get_y(&a))); return dist / len; }
DiaObject *aadlbox_copy(DiaObject *obj) { int i; Handle *handle1,*handle2; Aadlport *port; ConnectionPoint *connection; Aadlbox *aadlbox = (Aadlbox *) obj; void *user_data = ((Aadlbox *) obj)->specific; DiaObject *newobj = obj->type->ops->create(&obj->position, user_data, &handle1,&handle2); object_copy_props(newobj,obj,FALSE); /* copy ports */ for (i=0; i<aadlbox->num_ports; i++) { Point p; point_copy(&p, &aadlbox->ports[i]->handle->pos); port = new_port(aadlbox->ports[i]->type, aadlbox->ports[i]->declaration); aadlbox_add_port((Aadlbox *)newobj, &p, port); } /* copy connection points */ for (i=0; i<aadlbox->num_connections; i++) { Point p; point_copy(&p, &aadlbox->connections[i]->pos); connection= g_new0(ConnectionPoint, 1); aadlbox_add_connection((Aadlbox *)newobj, &p, connection); } return newobj; }
gcry_mpi_point_t _gcry_mpi_ec_get_point (const char *name, gcry_ctx_t ctx, int copy) { mpi_ec_t ec = _gcry_ctx_get_pointer (ctx, CONTEXT_TYPE_EC); (void)copy; /* Not used. */ if (!strcmp (name, "g") && ec->G) return point_copy (ec->G); if (!strcmp (name, "q")) { /* If only the private key is given, compute the public key. */ if (!ec->Q && ec->d && ec->G && ec->p && ec->a) { ec->Q = gcry_mpi_point_new (0); _gcry_mpi_ec_mul_point (ec->Q, ec->d, ec->G, ec); } if (ec->Q) return point_copy (ec->Q); } return NULL; }
/*Copia un elemento en otro, reservando memoria*/ EleStack * elestack_copy(const EleStack *ppoint1){ EleStack *ppoint2 = NULL; if(!ppoint1 || !ppoint1->point){ return NULL; } ppoint2 = elestack_ini(); if(!ppoint2){ return NULL; } ppoint2->point = point_copy (ppoint1->point); if(!ppoint2->point){ elestack_free(ppoint2); return NULL; } return ppoint2; }
/* returns an allocated Polyline pointer with the vertex list initialized to the points in vlist */ Polyline *polyline_createp(int numV, Point *vlist){ Polyline *p=malloc(sizeof(Polyline)); if(NULL == p){ printf("ERROR: polyline_createp >> malloc failed!\n"); exit(-1); } p->vertex=malloc(sizeof(Point)*numV); for (int i = 0; i < numV; i++) { point_copy(&(p->vertex[i]),&vlist[i]); } // p=vlist; p->numVertex=numV; p->zBuffer = 1; return p; }
static bool midpt_next_volume_point(void* context, int* pos, point_t* point, real_t* weight) { midpt_t* midpt = context; if (*pos == 0) { point_copy(point, &midpt->cell_center); *weight = midpt->cell_volume; ++(*pos); return true; } else return false; }
static real approx_bez_length(BezierConn *bez) { /* Approximates the length of the bezier curve * by the length of the polyline joining its points */ Point *current, *last, vec; real length = .0; int i; current = &bez->bezier.points[0].p1; for (i=1; i < bez->bezier.num_points ; i++){ last = current; current = &bez->bezier.points[i].p3; point_copy(&vec,last); point_sub(&vec,current); length += point_len(&vec); } return length; }
/* Añade un punto a un laberinto dado*/ Maze *maze_addPoint(Maze *pmaze, const Point *ppoint){ Point *aux; if(!pmaze){ return NULL; } if(!ppoint){ return NULL; } if(point_getSymbol(ppoint) == ERRORCHAR||(point_getCoordinateX(ppoint)) > pmaze->ncol||(point_getCoordinateX(ppoint)) < 0||(point_getCoordinateY(ppoint)) < 0||(point_getCoordinateY(ppoint)) > pmaze->nrow){ return NULL; } aux = point_copy(ppoint); if(!aux){ return NULL; } pmaze->ppoint[point_getCoordinateY(ppoint)][point_getCoordinateX(ppoint)] = aux; return pmaze; }
static bool midpt_next_surface_point(void* context, int face, int* pos, point_t* point, vector_t* normal_vector, real_t* weight) { midpt_t* midpt = context; if (*pos == 0) { point_copy(point, &midpt->face_centers[face]); vector_copy(normal_vector, &midpt->face_normals[face]); *weight = midpt->face_areas[face]; ++(*pos); return true; } else return false; }
void connpointline_putonaline(ConnPointLine *cpl,Point *start,Point *end, gint dirs) { Point se_vector; real se_len,pseudopoints; int i; GSList *elem; point_copy(&se_vector, end); point_sub(&se_vector, start); se_len = point_len(&se_vector); if (se_len > 0) point_normalize(&se_vector); cpl->start = *start; cpl->end = *end; if (dirs != DIR_NONE) /* use the oone givne by the caller */; else if (fabs(se_vector.x) > fabs(se_vector.y)) dirs = DIR_NORTH|DIR_SOUTH; else dirs = DIR_EAST|DIR_WEST; pseudopoints = cpl->num_connections + 1; /* here, we count the start and end points as eating real positions. */ for (i=0, elem=cpl->connections; i<cpl->num_connections; i++,elem=g_slist_next(elem)) { ConnectionPoint *cp = (ConnectionPoint *)(elem->data); cp->pos = se_vector; cp->directions = dirs; point_scale(&cp->pos,se_len * (i+1.0)/pseudopoints); point_add(&cp->pos,start); } }
void gui_widget_screen_visible_position(gui_widget_t* widget, point_t* point, rect_t* rect) { if(point == NULL && rect == NULL) return; point_t widget_point; gui_widget_position(widget, &widget_point); rect_t widget_rect; gui_widget_rect(widget, &widget_rect); rect_t parent_rect; gui_object_t* parent = gui_object_parent(GUI_OBJECT(widget)); while(parent){ gui_widget_rect(GUI_WIDGET(parent), &parent_rect); widget_point.x += rect_x(&parent_rect); widget_point.y += rect_y(&parent_rect); widget_rect.left += parent_rect.left; widget_rect.top += parent_rect.top; widget_rect.right += parent_rect.left; widget_rect.bottom += parent_rect.top; widget_rect.left = MAX(widget_rect.left, parent_rect.left); widget_rect.top = MAX(widget_rect.top, parent_rect.top); widget_rect.right = MIN(widget_rect.right, parent_rect.right); widget_rect.bottom = MIN(widget_rect.bottom, parent_rect.bottom); parent = gui_object_parent(parent); } if(point) point_copy(point, &widget_point); if(rect) rect_copy(rect, &widget_rect); }
sp_func_t* cylinder_new(point_t* x, real_t r, normal_orient_t normal_orientation) { // Set up a cylinder signed distance function. cyl_t* c = polymec_malloc(sizeof(cyl_t)); point_copy(&c->x, x); c->r = r; c->orient = normal_orientation; char cyl_str[1024]; sprintf(cyl_str, "Cylinder (x = (%g %g %g), r = %g)", x->x, x->y, x->z, r); sp_func_vtable vtable = {.eval = cyl_eval, .dtor = polymec_free}; sp_func_t* cyl = sp_func_new(cyl_str, c, vtable, SP_FUNC_INHOMOGENEOUS, 1); // Register the gradient function. char cyl_grad_str[1024]; sprintf(cyl_grad_str, "Cylinder gradient (x = (%g %g %g), r = %g)", x->x, x->y, x->z, r); sp_func_vtable vtable_g = {.eval = cyl_eval_gradient}; // Notice no dtor. sp_func_t* cyl_grad = sp_func_new(cyl_grad_str, c, vtable_g, SP_FUNC_INHOMOGENEOUS, 3); sp_func_register_deriv(cyl, 1, cyl_grad); return cyl; }
/** Draw a TextLine object. * @param object The renderer object to use for transform and output * @param text_line The TextLine to render, including font and height. * @param pos The position to render it at. * @param color The color to render it with. */ static void draw_text_line (DiaRenderer *object, TextLine *text_line, Point *pos, Alignment alignment, Color *color) { DiaGdkRenderer *renderer = DIA_GDK_RENDERER (object); GdkColor gdkcolor; int x,y; Point start_pos; PangoLayout* layout = NULL; const gchar *text = text_line_get_string(text_line); int height_pixels; real font_height = text_line_get_height(text_line); real scale = dia_transform_length(renderer->transform, 1.0); if (text == NULL || *text == '\0') return; /* Don't render empty strings. */ point_copy(&start_pos,pos); renderer_color_convert(renderer, color, &gdkcolor); height_pixels = dia_transform_length(renderer->transform, font_height); if (height_pixels < 2) { /* "Greeking" instead of making tiny font */ int width_pixels = dia_transform_length(renderer->transform, text_line_get_width(text_line)); gdk_gc_set_foreground(renderer->gc, &gdkcolor); gdk_gc_set_dashes(renderer->gc, 0, (gint8*)"\1\2", 2); dia_transform_coords(renderer->transform, start_pos.x, start_pos.y, &x, &y); gdk_draw_line(renderer->pixmap, renderer->gc, x, y, x + width_pixels, y); return; } else { start_pos.y -= text_line_get_ascent(text_line); start_pos.x -= text_line_get_alignment_adjustment (text_line, alignment); dia_transform_coords(renderer->transform, start_pos.x, start_pos.y, &x, &y); layout = dia_font_build_layout(text, text_line->font, dia_transform_length(renderer->transform, text_line->height)/20.0); #if defined(PANGO_VERSION_ENCODE) # if (PANGO_VERSION >= PANGO_VERSION_ENCODE(1,16,0)) /* I'd say the former Pango API was broken, i.e. leaky */ # define HAVE_pango_layout_get_line_readonly # endif #endif text_line_adjust_layout_line (text_line, #if defined(HAVE_pango_layout_get_line_readonly) pango_layout_get_line_readonly(layout, 0), #else pango_layout_get_line(layout, 0), #endif scale/20.0); if (renderer->highlight_color != NULL) { draw_highlighted_string(renderer, layout, x, y, &gdkcolor); } else { #if defined HAVE_FREETYPE { FT_Bitmap ftbitmap; int width, height; GdkPixbuf *rgba = NULL; width = dia_transform_length(renderer->transform, text_line_get_width(text_line)); height = dia_transform_length(renderer->transform, text_line_get_height(text_line)); if (width > 0) { int stride; guchar* pixels; int i,j; guint8 *graybitmap; initialize_ft_bitmap(&ftbitmap, width, height); pango_ft2_render_layout(&ftbitmap, layout, 0, 0); graybitmap = ftbitmap.buffer; rgba = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, width, height); stride = gdk_pixbuf_get_rowstride(rgba); pixels = gdk_pixbuf_get_pixels(rgba); for (i = 0; i < height; i++) { for (j = 0; j < width; j++) { pixels[i*stride+j*4] = gdkcolor.red>>8; pixels[i*stride+j*4+1] = gdkcolor.green>>8; pixels[i*stride+j*4+2] = gdkcolor.blue>>8; pixels[i*stride+j*4+3] = graybitmap[i*ftbitmap.pitch+j]; } } g_free(graybitmap); gdk_draw_pixbuf(renderer->pixmap, renderer->gc, rgba, 0, 0, x, y, width, height, GDK_RGB_DITHER_NONE, 0, 0); g_object_unref(G_OBJECT(rgba)); } } #else gdk_gc_set_foreground(renderer->gc, &gdkcolor); gdk_draw_layout(renderer->pixmap, renderer->gc, x, y, layout); #endif } /* !higlight_color */ g_object_unref(G_OBJECT(layout)); } /* !greeking */
static void chronoref_update_data(Chronoref *chronoref) { Element *elem = &chronoref->element; DiaObject *obj = &elem->object; real time_span,t; Point p1,p2; Point ur_corner; int shouldbe,i; real labelwidth; char biglabel[10]; ElementBBExtras *extra = &elem->extra_spacing; chronoref->majgrad_height = elem->height; chronoref->mingrad_height = elem->height / 3.0; /* build i = -log_{10}(time_step), then make a %.if format out of it. */ t = 1; i = 0; while (t > chronoref->time_step) { t /= 10; i++; } chronoref->spec = i; /* update precision */ g_snprintf(biglabel,sizeof(biglabel),"%.*f", chronoref->spec, MIN(-ABS(chronoref->start_time),-ABS(chronoref->end_time))); labelwidth = dia_font_string_width(biglabel,chronoref->font, chronoref->font_size); /* Now, update the drawing helper counters */ time_span = chronoref->end_time - chronoref->start_time; if (time_span == 0) { chronoref->end_time = chronoref->start_time + .1; time_span = .1; } else if (time_span < 0) { chronoref->start_time = chronoref->end_time; time_span = -time_span; chronoref->end_time = chronoref->start_time + time_span; } chronoref->firstmaj = chronoref->time_step * ceil(chronoref->start_time / chronoref->time_step); if (chronoref->firstmaj < chronoref->start_time) chronoref->firstmaj += chronoref->time_step; chronoref->firstmin = chronoref->time_lstep * ceil(chronoref->start_time / chronoref->time_lstep); if (chronoref->firstmin < chronoref->start_time) chronoref->firstmin += chronoref->time_lstep; chronoref->firstmaj_x = elem->corner.x + elem->width*((chronoref->firstmaj-chronoref->start_time)/time_span); chronoref->firstmin_x = elem->corner.x + elem->width*((chronoref->firstmin-chronoref->start_time)/time_span); chronoref->majgrad = (chronoref->time_step * elem->width) / time_span; chronoref->mingrad = (chronoref->time_lstep * elem->width) / time_span; extra->border_trans = chronoref->main_lwidth/2; element_update_boundingbox(elem); /* fix boundingbox for special extras: */ obj->bounding_box.left -= (chronoref->font_size + labelwidth)/2; obj->bounding_box.bottom += chronoref->font_size; obj->bounding_box.right += (chronoref->font_size + labelwidth)/2; obj->position = elem->corner; element_update_handles(elem); /* Update connections: */ ur_corner.x = elem->corner.x + elem->width; ur_corner.y = elem->corner.y; shouldbe = (int)(ceil((chronoref->end_time-chronoref->firstmin)/ chronoref->time_lstep)); if (shouldbe == 0) shouldbe++; if (shouldbe < 0) shouldbe = 0; shouldbe++; /* off by one.. */ connpointline_adjust_count(chronoref->scale,shouldbe,&ur_corner); connpointline_update(chronoref->scale); point_copy(&p1,&elem->corner); point_copy(&p2,&ur_corner); p1.x -= chronoref->mingrad; p2.x += chronoref->mingrad; connpointline_putonaline(chronoref->scale,&p1,&p2, DIR_SOUTH); }
ObjectChange* aadlbox_move_handle(Aadlbox *aadlbox, Handle *handle, Point *to, ConnectionPoint *cp, HandleMoveReason reason, ModifierKeys modifiers) { assert(aadlbox!=NULL); assert(handle!=NULL); assert(to!=NULL); if (handle->id < 8) { /* box resizing */ Element *element = &aadlbox->element; Point oldcorner, newcorner; real oldw, neww, oldh, newh; real w_factor, h_factor; Aadlport *p; ConnectionPoint *c; int i; point_copy(&oldcorner, &element->corner); oldw = element->width; oldh = element->height; element_move_handle( &aadlbox->element, handle->id, to, cp, reason, modifiers); point_copy(&newcorner, &element->corner); neww = element->width; newh = element->height; /* update ports positions proportionally */ for (i=0; i < aadlbox->num_ports; i++) { p = aadlbox->ports[i]; w_factor = (p->handle->pos.x - oldcorner.x) / oldw; h_factor = (p->handle->pos.y - oldcorner.y) / oldh; p->handle->pos.x = newcorner.x + w_factor * neww; p->handle->pos.y = newcorner.y + h_factor * newh; } /* update connection points proportionally */ for (i=0; i < aadlbox->num_connections; i++) { c = aadlbox->connections[i]; w_factor = (c->pos.x - oldcorner.x) / oldw; h_factor = (c->pos.y - oldcorner.y) / oldh; c->pos.x = newcorner.x + w_factor * neww; c->pos.y = newcorner.y + h_factor * newh; } } else { /* port handles */ handle->pos.x = to->x; handle->pos.y = to->y; } aadlbox_update_data(aadlbox); /* FIXME !! Should I free the given structures (to, ...) ? */ return NULL; }
int main(int argc, char *argv[]) { const int rows = 1000; const int cols = 1000; View3D view; Matrix vtm; Polygon side[4]; Polygon tpoly; Point tv[3]; Point v[4]; Color color[4]; Image *src; char filename[100]; double x; int i; // set some colors Color_set( &color[0], 0, 0, 1 ); Color_set( &color[1], 0, 1, 0 ); Color_set( &color[2], 1, 0, 0 ); Color_set( &color[3], 1, 0, 1 ); // initialize polygons for(i=0;i<4;i++) { polygon_init( &side[i] ); } // corners of a cube, centered at (0, 0, 0) point_set3D( &v[0], 0, 1, 0 ); point_set3D( &v[1], 1, -1, 0); point_set3D( &v[2], -1, -1, 0 ); point_set3D( &v[3], 0, 0, 1 ); //base of the pyramid polygon_set(&side[3], 3, &(v[0])); //side1 point_copy(&tv[0], &v[0]); point_copy(&tv[1], &v[2]); point_copy(&tv[2], &v[3]); polygon_set(&side[0], 3, tv); //side2 point_copy(&tv[0], &v[0]); point_copy(&tv[1], &v[1]); point_copy(&tv[2], &v[3]); polygon_set(&side[1], 3, tv); //side3 point_copy(&tv[0], &v[1]); point_copy(&tv[1], &v[2]); point_copy(&tv[2], &v[3]); polygon_set(&side[2], 3, tv); point_set3D( &(view.vrp), 1, 0, 0); vector_set( &(view.vpn), -view.vrp.val[0], -view.vrp.val[1], -view.vrp.val[2] ); vector_set( &(view.vup), 0, 0, 1 ); view.d = 1; // focal length view.du = 2; view.dv = view.du * (float)rows / cols; view.f = 0; // front clip plane view.b = 4; // back clip plane view.screenx = cols; view.screeny = rows; matrix_setView3D( &vtm, &view ); // use a temprary polygon to transform stuff polygon_init( &tpoly ); printf("Drawing pyramid\n"); x = -2; int j; for (j=0; j<50; j++){ // create image src = image_create( rows, cols ); point_set3D(&(view.vrp), x , 2, 0.5); vector_set( &(view.vpn), -x, -2, -0.5); matrix_setView3D(&vtm, &view); i=0; for(i=0;i<4;i++) { polygon_copy( &tpoly, &side[i] ); matrix_xformPolygon( &vtm, &tpoly ); // normalize by homogeneous coordinate before drawing polygon_normalize( &tpoly ); polygon_draw( &tpoly, src, color[i] ); //polygon_print( &tpoly, stdout ); } printf("Writing image\n"); sprintf(filename, "pyramid_%04d.ppm", j); image_write( src, filename); free(src); if(j<25){ x += 0.08; }else{ x -= 0.08; } } printf("Making the .gif file...\n"); system("convert -delay 10 pyramid_*.ppm ../images/ext1.gif"); system("rm -f pyramid*"); return(0); }