/* --------------------------------------------------------------------------- * creates a new polygon from the old formats rectangle data */ PolygonTypePtr CreateNewPolygonFromRectangle (LayerTypePtr Layer, LocationType X1, LocationType Y1, LocationType X2, LocationType Y2, FlagType Flags) { PolygonTypePtr polygon = CreateNewPolygon (Layer, Flags); if (!polygon) return (polygon); CreateNewPointInPolygon (polygon, X1, Y1); CreateNewPointInPolygon (polygon, X2, Y1); CreateNewPointInPolygon (polygon, X2, Y2); CreateNewPointInPolygon (polygon, X1, Y2); SetPolygonBoundingBox (polygon); if (!Layer->polygon_tree) Layer->polygon_tree = r_create_tree (NULL, 0, 0); r_insert_entry (Layer->polygon_tree, (BoxTypePtr) polygon, 0); return (polygon); }
/*! * \brief Creates a new polygon from the old formats rectangle data. */ PolygonType * CreateNewPolygonFromRectangle (LayerType *Layer, Coord X1, Coord Y1, Coord X2, Coord Y2, FlagType Flags) { PolygonType *polygon = CreateNewPolygon (Layer, Flags); if (!polygon) return (polygon); CreateNewPointInPolygon (polygon, X1, Y1); CreateNewPointInPolygon (polygon, X2, Y1); CreateNewPointInPolygon (polygon, X2, Y2); CreateNewPointInPolygon (polygon, X1, Y2); SetPolygonBoundingBox (polygon); if (!Layer->polygon_tree) Layer->polygon_tree = r_create_tree (NULL, 0, 0); r_insert_entry (Layer->polygon_tree, (BoxType *) polygon, 0); return (polygon); }
/* --------------------------------------------------------------------------- * inserts a point into a polygon */ static void * InsertPointIntoPolygon (LayerTypePtr Layer, PolygonTypePtr Polygon) { PointType save; Cardinal n; LineType line; if (!Forcible) { /* * first make sure adding the point is sensible */ line.Thickness = 0; line.Point1 = Polygon->Points[prev_contour_point (Polygon, InsertAt)]; line.Point2 = Polygon->Points[InsertAt]; if (IsPointOnLine ((float) InsertX, (float) InsertY, 0.0, &line)) return (NULL); } /* * second, shift the points up to make room for the new point */ ErasePolygon (Polygon); r_delete_entry (Layer->polygon_tree, (BoxTypePtr) Polygon); save = *CreateNewPointInPolygon (Polygon, InsertX, InsertY); for (n = Polygon->PointN - 1; n > InsertAt; n--) Polygon->Points[n] = Polygon->Points[n - 1]; /* Shift up indices of any holes */ for (n = 0; n < Polygon->HoleIndexN; n++) if (Polygon->HoleIndex[n] > InsertAt || (InsertLast && Polygon->HoleIndex[n] == InsertAt)) Polygon->HoleIndex[n]++; Polygon->Points[InsertAt] = save; SetChangedFlag (true); AddObjectToInsertPointUndoList (POLYGONPOINT_TYPE, Layer, Polygon, &Polygon->Points[InsertAt]); SetPolygonBoundingBox (Polygon); r_insert_entry (Layer->polygon_tree, (BoxType *) Polygon, 0); InitClip (PCB->Data, Layer, Polygon); if (Forcible || !RemoveExcessPolygonPoints (Layer, Polygon)) { DrawPolygon (Layer, Polygon, 0); Draw (); } return (&Polygon->Points[InsertAt]); }
/* --------------------------------------------------------------------------- * copies data from one polygon to another * 'Dest' has to exist */ PolygonType * CopyPolygonLowLevel (PolygonType *Dest, PolygonType *Src) { Cardinal hole = 0; Cardinal n; for (n = 0; n < Src->PointN; n++) { if (hole < Src->HoleIndexN && n == Src->HoleIndex[hole]) { CreateNewHoleInPolygon (Dest); hole++; } CreateNewPointInPolygon (Dest, Src->Points[n].X, Src->Points[n].Y); } SetPolygonBoundingBox (Dest); Dest->Flags = Src->Flags; CLEAR_FLAG (NOCOPY_FLAGS, Dest); return (Dest); }