public PlateCombine GetMinPlateCombine(PlateModel source, float T, string type, float limit = -1) { RectHelper rect = new RectHelper(); CopyOper co = new CopyOper(); PlateModel pm = co.CopyPlate(source); PlateModel pmnew = co.CopyPlate(source); //旋转180后的图形 pmnew = Rotate(pmnew, 180); List <PointF> pnew = pmnew.OutModel.ExpandPoint; List <PointF> chnew = rect.GetConvexHull(pmnew.OutModel.ExpandPoint); List <PointF> p = pm.OutModel.ExpandPoint; List <PointF> ch = rect.GetConvexHull(pm.OutModel.ExpandPoint); Dictionary <string, object> diccombine = rect.Combine(p, ch, pnew, chnew, T, limit, type); List <PointF> chcombine = (List <PointF>)diccombine["convexhull"]; Move(pmnew, Convert.ToSingle(diccombine["movex"]), Convert.ToSingle(diccombine["movey"])); RotateAndMove(pm, pmnew, Convert.ToSingle(diccombine["angle"])); PlateCombine pc = new PlateCombine(pm, pmnew); pc.Rect = pm.Rect = pmnew.Rect = GetRect(pm.OutModel.ExpandPoint, pmnew.OutModel.ExpandPoint); return(pc); }
/// <summary> /// 组合图形旋转归位 /// </summary> /// <param name="pm"></param> /// <param name="angle"></param> /// <returns></returns> public PlateCombine RotateAndMove(PlateCombine pc, float angle) { CopyOper co = new CopyOper(); PlateModel pm1 = co.CopyPlate(pc.Plate1); PlateModel pm2 = co.CopyPlate(pc.Plate2); RotateOper ro = new RotateOper(); pm1 = ro.RotatePlate(pm1, new PointF(0, 0), angle); pm2 = ro.RotatePlate(pm2, new PointF(0, 0), angle); float maxX = pm1.OutModel.ExpandPoint[0].X; float maxY = pm1.OutModel.ExpandPoint[0].Y; float minX = pm1.OutModel.ExpandPoint[0].X; float minY = pm1.OutModel.ExpandPoint[0].Y; for (int i = 0; i < pm1.OutModel.ExpandPoint.Count; i++) { if (maxX < pm1.OutModel.ExpandPoint[i].X) { maxX = pm1.OutModel.ExpandPoint[i].X; } if (maxY < pm1.OutModel.ExpandPoint[i].Y) { maxY = pm1.OutModel.ExpandPoint[i].Y; } if (minX > pm1.OutModel.ExpandPoint[i].X) { minX = pm1.OutModel.ExpandPoint[i].X; } if (minY > pm1.OutModel.ExpandPoint[i].Y) { minY = pm1.OutModel.ExpandPoint[i].Y; } } for (int i = 0; i < pm2.OutModel.ExpandPoint.Count; i++) { if (maxX < pm2.OutModel.ExpandPoint[i].X) { maxX = pm2.OutModel.ExpandPoint[i].X; } if (maxY < pm2.OutModel.ExpandPoint[i].Y) { maxY = pm2.OutModel.ExpandPoint[i].Y; } if (minX > pm2.OutModel.ExpandPoint[i].X) { minX = pm2.OutModel.ExpandPoint[i].X; } if (minY > pm2.OutModel.ExpandPoint[i].Y) { minY = pm2.OutModel.ExpandPoint[i].Y; } } MoveOper mo = new MoveOper(); mo.MovePlate(pm1, -minX, -minY); mo.MovePlate(pm2, -minX, -minY); PlateCombine pcnew = new PlateCombine(pm1, pm2); pcnew.Rect = pc.Rect; //if (angle == 90) //{ // pcnew .Rect = new RectangleF(0, 0, pc .Rect .Height, pc .Rect .Width); //} pcnew.Rect = GetRect(pm1.OutModel.ExpandPoint, pm2.OutModel.ExpandPoint); return(pcnew); }