public static VisualRectangle Create(Rectangle2 rect, Pen pen = null, Brush brush = null)
 {
     return new VisualRectangle(rect)
     {
         Pen = pen,
         FillBrush = brush
     };
 }
        public void LocationRotation(string locationStr, string sizeStr, string rotationStr)
        {
            var location = Vector2.Parse(locationStr);
            var size = SizeD.Parse(sizeStr);
            var rotation = Angle.Parse(rotationStr);

            var rect = new Rectangle2(location, size, rotation);

            Assert.AreEqual(location, rect.Location);
            Assert.AreEqual(size.Width, rect.Width, GeometrySettings.DEFAULT_TOLERANCE);
            Assert.AreEqual(size.Height, rect.Height, GeometrySettings.DEFAULT_TOLERANCE);
            Assert.AreEqual(rotation, rect.Rotation);
        }
        //[TestCase("(0, 0), (100, 0), (100, 200), (0, 200)", "-100, 50", "90°")]
        // TODO add more tests with rotation
        public void FromVertices(string verticesStr, string expectedMiddleStr, string expectedRotationStr)
        {
            var vertices = Vector2.ParseAll(verticesStr);
            var expectedMiddle = Vector2.Parse(expectedMiddleStr);


            var rect = new Rectangle2(vertices);
            var expectedRotation = Angle.Parse(expectedRotationStr);

            Assert.AreEqual(vertices[0], rect.Location);
            Assert.AreEqual(expectedMiddle, rect.MiddlePoint);
            Assert.AreEqual(expectedRotation, rect.Rotation);
        }
        public void Constructor(string locationStr, string sizeStr, string rotationStr)
        {
            var location = Vector2.Parse(locationStr);
            var size = SizeD.Parse(sizeStr);
            var rotation = Angle.Parse(rotationStr);

            var rect = new Rectangle2(location, size, rotation);

            Assert.AreEqual(location, rect.Location);
            Assert.AreEqual(size.Width, rect.Width);
            Assert.AreEqual(size.Height, rect.Height);
            Assert.AreEqual(rotation, rect.Rotation);
        }
        [TestCase("(0,0),(10,0),(10,45), (0,45)", 200, 100)]        // Different origin size
        public void Constructor2(string rectStr, double witdh, double height)
        {
            var vertices = Vector2.ParseAll(rectStr);
            var rect = new Rectangle2(vertices);

            rect.Width = witdh;
            rect.Height = height;

            var location = rect.Location;

            Assert.AreEqual(vertices[0], location);         // Location must stay the same
            Assert.AreEqual(witdh, rect.Width);             // width must be as set
            Assert.AreEqual(height, rect.Height);           // height must be as set
            Assert.AreEqual(Angle.Zero, rect.Rotation);     // Rotation must be Zero
        }
        /// <summary>
        /// Find the Boundingbox with the given Algorythm
        /// </summary>
        /// <param name="boxfindingAlgorythm">Concrete implementation of the bounding finder Algorythm to use</param>
        /// <returns></returns>
        public Rectangle2 FindBoundingBox(IPolygonBoundingBoxAlgorythm boxfindingAlgorythm)
        {
            Rectangle2 rect = null;
            var        hull = !IsConvex() ? ToConvexPolygon() : this;

            var vertices = boxfindingAlgorythm.FindBounds(hull);

            if (vertices.Count() == 4)
            {
                rect = new Rectangle2(vertices);
            }

            if (rect == null || rect.Size.IsEmpty)
            {
                // Smallest boundingboxfinder failed - use simple boundingbox instead
                rect = this.BoundingBox.ToRectangle();
            }

            return(rect);
        }
 public VisualRectangle(Rectangle2 geometry)
 {
     _rectangle = geometry;
 }
예제 #8
0
 /// <summary>
 /// Creates a new rectangle from the given prototype
 /// </summary>
 /// <param name="prototype"></param>
 public Rectangle2(Rectangle2 prototype)
     : this(prototype.ToVertices().ToArray())
 {
 }
예제 #9
0
 /// <summary>
 /// Creates a new rectangle from the given prototype
 /// </summary>
 /// <param name="prototype"></param>
 public Rectangle2(Rectangle2 prototype)
     : this(prototype.ToVertices().ToArray())
 {
 }
 public void ConstructorFail(string rectStr)
 {
     var vertices = Vector2.ParseAll(rectStr);
     var rect = new Rectangle2(vertices);
 }
        public void MiddlepointException(string rectStr, string newMiddleStr)
        {
            var vertices = Vector2.ParseAll(rectStr);
            var rect = new Rectangle2(vertices);

            var newMid = Vector2.Parse(newMiddleStr);

            rect.MiddlePoint = newMid;


            Assert.AreEqual(newMid, rect.MiddlePoint);
        }
        /// <summary>
        /// Find the Boundingbox with the given Algorythm
        /// </summary>
        /// <param name="boxfindingAlgorythm">Concrete implementation of the bounding finder Algorythm to use</param>
        /// <returns></returns>
        public Rectangle2 FindBoundingBox(IPolygonBoundingBoxAlgorythm boxfindingAlgorythm)
        {
            Rectangle2 rect = null;
            var hull = !IsConvex() ? ToConvexPolygon() : this;

            var vertices = boxfindingAlgorythm.FindBounds(hull);

            if (vertices.Count() == 4)
            {
                rect = new Rectangle2(vertices);
            }

            if (rect == null || rect.Size.IsEmpty)
            {
                // Smallest boundingboxfinder failed - use simple boundingbox instead
                rect = this.BoundingBox.ToRectangle();
            }

            return rect;
        }