コード例 #1
0
        public void CenterTest()
        {
            var quadrilateral = new Quadrilateral
            {
                Points = new List <Point> {
                    new Point(0, 0), new Point(10, 0), new Point(0, 4), new Point(10, 4)
                }
            };
            var center = quadrilateral.Center();

            Assert.Equal(5, center.X);
            Assert.Equal(2, center.Y);
        }
コード例 #2
0
        public static Quadrilateral MoveToPoint(Quadrilateral quadrilateral, Point newCenter)
        {
            Point previouseCenter = quadrilateral.Center();
            int   xShifting       = previouseCenter.X - newCenter.X;
            int   yShifting       = previouseCenter.Y - newCenter.Y;

            var points = quadrilateral.ToArray();

            for (int i = 0; i < points.Count(); i++)
            {
                points[i].X -= xShifting;
                points[i].Y -= yShifting;
            }
            quadrilateral.Points = points.ToList();

            return(quadrilateral);
        }