Exemplo n.º 1
0
        /// <summary>
        /// Quick controller for fun image display. Better to split it out if more is needed in the future.
        /// </summary>
        /// <param name="rows">Number of rows to create</param>
        /// <param name="columns">Number of columns to create</param>
        /// <returns>An image and 200 response</returns>
        /// <remarks>
        ///		The call is http://yourserverhere/api/Image?row=r&column=c. For example, from the sample:
        ///		http://localhost:64876/api/Image?row=F&column=12
        /// </remarks>
        public HttpResponseMessage Get(string row, int column)
        {
            Triangle          tri1  = new Triangle(new Vertex(0.0, 0.0), new Vertex(10.0, 0.0), new Vertex(0.0, 10.0));
            Triangle          tri2  = (Triangle)TransformationFactory.Translate(TransformationFactory.RotateOnCenter(tri1, Math.PI), 10.0, 10.0);
            KaleidoscopeImage image = new KaleidoscopeImage(new List <IPolygon>()
            {
                tri1, tri2
            }, 10, 10);
            KaledioscopeRepeater repeater = new KaledioscopeRepeater(image, row, column);
            KaleidoscopeDrawer   drawer   = new KaleidoscopeDrawer(repeater);
            Bitmap bmp = drawer.GetImage();

            using (MemoryStream ms = new MemoryStream())
            {
                bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
                HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK);
                response.Content = new ByteArrayContent(ms.ToArray());
                response.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("image/png");
                return(response);
            }
        }
Exemplo n.º 2
0
        public void TranslateTest_Success()
        {
            // Setup: Create simple triangle poly (right triangle)
            Triangle tri = new Triangle(new List <Vertex>()
            {
                new Vertex(0.0, 0.0),
                new Vertex(1.0, 0.0),
                new Vertex(0.0, 1.0)
            });

            // Test
            Triangle translatedTri = (Triangle)TransformationFactory.Translate(tri, 1.0, 1.0);

            // Assert: Make sure all vertices are what we would expect
            bool pointC = false;
            bool pointB = false;
            bool pointA = false;

            foreach (Line line in translatedTri.GetLines())
            {
                // This will make sure all three points are the same
                if ((line.V1.X == 1.0 && line.V1.Y == 1.0) || (line.V2.X == 1.0 && line.V2.Y == 1.0))
                {
                    pointC = true;
                }

                if (line.V1.X == 2.0 && line.V1.Y == 1.0 || (line.V2.X == 2.0 && line.V2.Y == 1.0))
                {
                    pointB = true;
                }

                if (line.V1.X == 1.0 && line.V1.Y == 2.0 || (line.V2.X == 1.0 && line.V2.Y == 2.0))
                {
                    pointA = true;
                }
            }
            Assert.IsTrue(pointA && pointB && pointC, "Point A: " + pointA.ToString() + " Point B: " + pointB.ToString() + " Point C: " + pointC.ToString());
        }