int main () { time_t now; int i; int errors = 0, count = 0; time (&now); srandom ((unsigned int) now + getpid ()); grow_layer_list (0); for (i = 0; i < 16; i++) { int j; char *p; if (i != 1 && i != 4 && i != 5 && i != 9) set_layer_list (i, 1); else set_layer_list (i, 0); p = print_layer_list (); printf ("%2d : %20s =", i, p); parse_layer_list (p + 1, 0); for (j = 0; j < num_layers; j++) printf (" %d", layers[j]); printf ("\n"); } while (count < 1000000) { FlagHolder fh; char *str; FlagType new_flags; int i; int otype; otype = ALL_TYPES; fh.Flags = empty_flags; for (i = 0; i < ENTRIES (object_flagbits); i++) { if (TEST_FLAG (object_flagbits[i].mask, &fh)) continue; if ((otype & object_flagbits[i].object_types) == 0) continue; if ((random () & 4) == 0) continue; otype &= object_flagbits[i].object_types; SET_FLAG (object_flagbits[i].mask, &fh); } if (otype & PIN_TYPES) for (i = 0; i < MAX_LAYER; i++) if (random () & 4) ASSIGN_THERM (i, 3, &fh); str = flags_to_string (fh.Flags, otype); new_flags = string_to_flags (str, 0); count++; if (FLAGS_EQUAL (fh.Flags, new_flags)) continue; dump_flag (&fh.Flags); printf (" "); dump_flag (&new_flags); printf ("\n"); if (++errors == 5) exit (1); } while (count < 1000000) { FlagHolder fh; char *str; FlagType new_flags; int i; int otype; otype = ALL_TYPES; fh.Flags = empty_flags; for (i = 0; i < ENTRIES (pcb_flagbits); i++) { if (TEST_FLAG (pcb_flagbits[i].mask, &fh)) continue; if ((random () & 4) == 0) continue; otype &= pcb_flagbits[i].object_types; SET_FLAG (pcb_flagbits[i].mask, &fh); } str = pcbflags_to_string (fh.Flags); new_flags = string_to_pcbflags (str, 0); count++; if (FLAGS_EQUAL (fh.Flags, new_flags)) continue; dump_flag (&fh.Flags); printf (" "); dump_flag (&new_flags); printf ("\n"); if (++errors == 5) exit (1); } printf ("%d out of %d failed\n", errors, count); return errors; }
static int polycombine (int argc, char **argv, Coord x, Coord y) { POLYAREA *res; bool forward; // bool outer; POLYAREA *np; // POLYAREA *pa; // PLINE *pline; // VNODE *node; // PolygonType *Polygon; LayerType *Layer = NULL; poly_tree *root = NULL; poly_tree *this_node; /* First pass to combine the forward and backward contours */ VISIBLEPOLYGON_LOOP (PCB->Data); { if (!TEST_FLAG (SELECTEDFLAG, polygon)) continue; /* Pick the layer of the first polygon we find selected */ if (Layer == NULL) Layer = layer; /* Only combine polygons on the same layer */ if (Layer != layer) continue; np = original_poly (polygon, &forward); /* Build a poly_tree record */ this_node = calloc (1, sizeof (poly_tree)); this_node->polygon = polygon; this_node->forward = forward; this_node->polyarea = np; /* Check where we should place the node in the tree */ root = insert_node_recursive (root, this_node); //RemovePolygon (layer, polygon); } ENDALL_LOOP; /* Now perform a traversal of the tree, computing a polygon */ res = compute_polygon_recursive (root, NULL); SaveUndoSerialNumber (); /* Second pass to remove the input polygons */ VISIBLEPOLYGON_LOOP (PCB->Data); { if (!TEST_FLAG (SELECTEDFLAG, polygon)) continue; /* Only combine polygons on the same layer */ if (Layer != layer) continue; RemovePolygon (layer, polygon); } ENDALL_LOOP; /* Now de-construct the resulting polygon into raw PCB polygons */ PolyToPolygonsOnLayer (PCB->Data, Layer, res, string_to_pcbflags ("clearpoly", NULL)); RestoreUndoSerialNumber (); IncrementUndoSerialNumber (); Draw (); return 0; }