private Point[] GetRectancleCoor(RectancleInfo info) { double Xdelta = Math.Abs(info.leftUp.X - info.rightUp.X); double Ydelta = Math.Abs(info.leftUp.Y - info.rightUp.Y); Point[] rectanclePoints = null; if (info.leftUp.Y <= info.rightUp.Y) { rectanclePoints = new Point[] { info.leftUp, info.rightUp, new Point(info.rightUp.X + Ydelta, info.rightUp.Y - Xdelta), new Point(info.leftUp.X + Ydelta, info.leftUp.Y - Xdelta), }; } else { rectanclePoints = new Point[] { info.leftUp, info.rightUp, new Point(info.rightUp.X - Ydelta, info.rightUp.Y - Xdelta), new Point(info.leftUp.X - Ydelta, info.leftUp.Y - Xdelta), }; } return(rectanclePoints); }
private void SetNewRectancle(IList <Point> points) { Random random = new Random(); byte[] colors = new byte[4]; random.NextBytes(colors); Color randomColor = new Color() { A = colors[0], B = colors[1], R = colors[2], G = colors[3] }; Point left, right; if (points[0].Y <= points[1].Y) { left = new Point() { X = (points[3].X + points[0].X) / 2, Y = (points[3].Y + points[0].Y) / 2 }; right = new Point() { X = (points[0].X + points[1].X) / 2, Y = (points[0].Y + points[1].Y) / 2 }; } else { left = new Point() { X = (points[0].X + points[1].X) / 2, Y = (points[0].Y + points[1].Y) / 2 }; right = new Point() { X = (points[1].X + points[2].X) / 2, Y = (points[1].Y + points[2].Y) / 2 }; } newRectancle = new RectancleInfo() { leftUp = left, rightUp = right, brush = new SolidColorBrush(randomColor) }; }