Index: trunk/src/obj_common.c =================================================================== --- trunk/src/obj_common.c (revision 10845) +++ trunk/src/obj_common.c (revision 10846) @@ -133,3 +133,16 @@ return; pcb_attribute_copy_all(&o->Attributes, src); } + +void pcb_obj_center(pcb_any_obj_t *obj, pcb_coord_t *x, pcb_coord_t *y) +{ + switch (obj->type) { + case PCB_OBJ_PIN: + *x = ((pcb_pin_t *)(obj))->X; + *y = ((pcb_pin_t *)(obj))->Y; + break; + default: + *x = (obj->BoundingBox.X1 + obj->BoundingBox.X2) / 2; + *y = (obj->BoundingBox.Y1 + obj->BoundingBox.Y2) / 2; + } +} Index: trunk/src/obj_common.h =================================================================== --- trunk/src/obj_common.h (revision 10845) +++ trunk/src/obj_common.h (revision 10846) @@ -155,6 +155,8 @@ return murmurhash(&(c), sizeof(pcb_coord_t)); } +/* Return the geometric center of an object (center of bbox usually) */ +void pcb_obj_center(pcb_any_obj_t *obj, pcb_coord_t *x, pcb_coord_t *y); /* compare two fields and return 0 if they are equal */ #define pcb_field_neq(s1, s2, f) ((s1)->f != (s2)->f)