Пример #1
0
        public Rectangle2 Transform(Rectangle2 area, Vector2 oldSize)
        {
            Vector2 first  = Transform(area.Start, oldSize);
            Vector2 second = Transform(area.End, oldSize);

            return(new Rectangle2(Vector2.Min(first, second), Vector2.Max(first, second)));
        }
Пример #2
0
        public RectangleF ToVisualCoord(Rectangle2 area)
        {
            PointF start = ToVisualCoord(area.Start);
            PointF end   = ToVisualCoord(area.End);

            return(RectangleF.FromLTRB(Math.Min(start.X, end.X), Math.Min(start.Y, end.Y), Math.Max(start.X, end.X), Math.Max(start.Y, end.Y)));
        }
Пример #3
0
        /// <summary>
        /// Creates an object type derived from EncodedRectangle, based on the value of encoding.
        /// </summary>
        /// <param name="rectangle">A node object from the Screen Handler defining the bounds of the rectangle and the pixel data. IT SHOULD BE CONSIDERED LOCALLY AGAINST pixels param, not globally against the screen size</param>
        /// <param name="encoding">An Integer indicating the encoding type to be used for this rectangle.  Used to determine the type of EncodedRectangle to create.</param>
        /// <returns></returns>
        public EncodedRectangle Build(Rectangle2 rectangle, VncHost.Encoding encoding)
        {
            Bitmap bmp = PixelGrabber.CreateScreenCapture(rectangle.ToRectangle());

            int[] pixels = PixelGrabber.GrabPixels(bmp, rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height, bmp.PixelFormat);
            return(Build(rectangle, pixels, encoding));
        }
Пример #4
0
        public MainForm()
        {
            InitializeComponent();
            DoubleBuffered     = true;
            renderPanel.Paint += RenderPanel_Paint;
            Circle     c1 = new Circle(10);
            Circle     c2 = new Circle(100);
            Rectangle2 r  = new Rectangle2(renderPanel.Width / 2, 20);
            Rectangle2 r2 = new Rectangle2(renderPanel.Width / 4, 20);

            //Body2 b1 = new Body2(new Transform2(new Vec2(120,150)),0.6f, c1);
            Body2 b1 = new Body2(new Transform2(new Vec2(renderPanel.Width / 2, 10), 0), 0.6f, r2);

            b1.CoR = 0.95f;
            Body2 b2 = new Body2(new Transform2(new Vec2(renderPanel.Width / 2, renderPanel.Height - 100), 0), 0.0f, r);

            //Body2 b2 = new Body2(new Transform2(new Vec2(150,400), 0), 0.0f, c2);
            b2.CoR             = 0.4f;
            b1.Rotation        = 95;
            b2.Rotation        = 30;
            b2.EnableGravity   = false;
            b1.EnableGravity   = false;
            b1.DynamicFriction = 0.2f;
            b1.StaticFriction  = 0.4f;
            b2.DynamicFriction = 0.2f;
            b2.StaticFriction  = 0.4f;
            //b1.Collider = c1;
            //b2.Collider = c2;
            physics.AddBody(b1, true);
            // physics.ApplyForce(b1, new WindTest());
            physics.AddBody(b2, false);
            timer1.Start();
        }
Пример #5
0
 public Canny()//构造函数
 {
     rectangle2 = new Rectangle2();
     hv_Alpha   = 1.1;
     hv_Low     = 30;
     hv_High    = 70;
 }
Пример #6
0
        /// <summary>
        /// Draws the specified text string at the specified location with the specified Brush and Font objects.
        /// </summary>
        /// <param name="s">String to draw.</param>
        /// <param name="font">Font that defines the text format of the string.</param>
        /// <param name="brush">Brush that determines the color and texture of the drawn text.</param>
        /// <param name="rectangleF">System.Drawing.RectangleF structure that specifies the location of the drawn text.</param>
        /// <param name="format">System.Drawing.StringFormat that specifies formatting attributes, such as line spacing and alignment, that are applied to the drawn text.</param>
        public void DrawString(string s, Font2 font, Brush2 brush, Rectangle2 rectangleF, StringFormat2 format)
        {
            if (format != null && rectangleF.Width > 0)
            {
                switch (format.Alignment)
                {
                case StringAlignment2.Center:
                    rectangleF.X += (rectangleF.Width - MeasureString(s, font, (int)rectangleF.Width, format).Width) * 0.5f;
                    break;

                case StringAlignment2.Far:
                    rectangleF.X += rectangleF.Width - MeasureString(s, font, (int)rectangleF.Width, format).Width;
                    break;
                }
            }
            textList.Add(new Text {
                X          = rectangleF.X,
                Y          = rectangleF.Y + (font.Height * 0.5f),
                FontFamily = font.Name,
                FontSize   = font.Size * 1.2f,
                FontWeight = font.Bold ? "bold" : "normal",
                Value      = s,
                Fill       = BrushColor(brush),
                Transform  = Transform
            });
        }
Пример #7
0
        //public void Draw()
        //{
        //    foreach (KeyValuePair<ObjectId, List<GripPoint>> kvp in _gripPnts)
        //    {
        //        foreach (GripPoint gripPnt in kvp.Value)
        //        {
        //            double width = 10;
        //            double height = 10;
        //            CADPoint posInCanvas = _drawing.ModelToCanvas(gripPnt.Position);
        //            posInCanvas.X -= width / 2;
        //            posInCanvas.Y -= height / 2;
        //            _drawing.FillRectangle(graphics, Color.Blue, posInCanvas, width, height, CSYS.Canvas);
        //        }
        //    }
        //}

        public CADPoint Snap(CADPoint posInCanvas)
        {
            CADPoint posInModel = _drawing.CanvasToModel(posInCanvas);

            foreach (KeyValuePair <ObjectId, List <GripPoint> > kvp in _gripPnts)
            {
                int index = -1;
                foreach (GripPoint gripPnt in kvp.Value)
                {
                    ++index;
                    double   width           = 10;
                    double   height          = 10;
                    CADPoint gripPosInCanvas = _drawing.ModelToCanvas(gripPnt.Position);
                    gripPosInCanvas.X -= width / 2;
                    gripPosInCanvas.Y -= height / 2;
                    Rectangle2 rect = new Rectangle2(gripPosInCanvas, width, height);

                    if (MathUtils.IsPointInRectangle(posInCanvas, rect))
                    {
                        currentGripPoint      = gripPnt;
                        currentGripEntityId   = kvp.Key;
                        currentGripPointIndex = index;
                        return(gripPnt.Position);
                    }
                }
            }

            currentGripPoint      = null;
            currentGripEntityId   = ObjectId.Null;
            currentGripPointIndex = -1;
            return(posInModel);
        }
Пример #8
0
 public void SetClip(Rectangle2 rectangle)
 {
     template = topTemplate.CreateTemplate(rectangle.Width, rectangle.Height);
     topTemplate.AddTemplate(template, rectangle.X, topTemplate.Height - rectangle.Height - rectangle.Y);
     currentWidth  = rectangle.Width;
     currentHeight = rectangle.Height;
 }
        static void Main(string[] args)
        {
            List <Polygon> polygons = new List <Polygon>();

            polygons.Add(new Polygon());
            polygons.Add(new Rectangle());
            polygons.Add(new Triangle());

            foreach (Polygon p in polygons)
            {
                p.Draw();
            }

            //Inheritance Example
            Rectangle2 R = new Rectangle2(5, 4);

            Console.WriteLine(R.GetArea());

            //Interface Example
            Console.WriteLine("Enter the Car model:");
            string model = Console.ReadLine();

            Console.WriteLine("Enter the Car company:");
            string     company = Console.ReadLine();
            CarDetails c       = new CarDetails();

            c.Get(model, company);
            c.Display();
            Console.ReadKey();
        }
Пример #10
0
 public static VisualRectangle Create(Rectangle2 rect, Pen pen = null, Brush brush = null)
 {
     return(new VisualRectangle(rect)
     {
         Pen = pen,
         FillBrush = brush
     });
 }
Пример #11
0
            public MonitorInfo()
            {
                rcMonitor = new Rectangle2();
                rcWork    = new Rectangle2();

                cbSize  = (uint)System.Runtime.InteropServices.Marshal.SizeOf(typeof(MonitorInfo));
                dwFlags = 0;
            }
        public void Collides_RectangleEnvelopsLineFromLeft_ReturnsTrue()
        {
            rectangle = new Rectangle2(0, -3, 8, 3);
            verticalLine = new Line2(10, -1, 10, 1);
            movement = new Vector2(4, 0);

            Assert.IsTrue(CollisionDetector.Collides(rectangle, movement, verticalLine));
        }
        public void Collides_RectangleMovesAcrossLineButUnderIt_ReturnsFalse()
        {
            rectangle = new Rectangle2(-20, 20, 20, -20);
            verticalLine = new Line2(50, -50, 50, 50);
            movement = new Vector2(50, -150);

            Assert.IsFalse(CollisionDetector.Collides(rectangle, movement, verticalLine));
        }
Пример #14
0
        public void TestTask2_2()
        {
            Square2    square    = new Square2(3, 4);
            Rectangle2 rectangle = new Rectangle2(5, 7);

            Assert.AreEqual(square.Draw(), square.GetType().Name);
            Assert.AreEqual(rectangle.Draw(), rectangle.GetType().Name);
        }
Пример #15
0
        public override void Encode()
        {
            int x = 0; //rectangle.X;
            int y = 0; //rectangle.Y;
            int w = rectangle.Width;
            int h = rectangle.Height;

            CoRRE        rect;
            List <CoRRE> vector = new List <CoRRE>();


            if ((w <= 0xFF) && (h <= 0xFF))
            {
                rect = new CoRRE(rfb, framebuffer, pixels, rectangle);
                rect.Encode();
                vector.Add(rect);
            }
            else
            {
                int currentW, currentH;
                for (int currentY = 0; currentY < h; currentY += 0xFF)
                {
                    for (int currentX = 0; currentX < w; currentX += 0xFF)
                    {
                        try
                        {
                            currentW = w - currentX;
                            currentH = h - currentY;

                            if (currentW > 0xFF)
                            {
                                currentW = 0xFF;
                            }
                            if (currentH > 0xFF)
                            {
                                currentH = 0xFF;
                            }
                            Rectangle2 rc = new Rectangle2(x + currentX, y + currentY, currentW, currentH);
                            rect = new CoRRE(rfb, framebuffer, pixels, rc);

                            //problem ... WHY ?
                            rect.Encode();
                            vector.Add(rect);
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.ToString());
                            Console.ReadLine();
                        }
                    }
                }
            }

            rects = vector.ToArray();
            //count = rects.length;
        }
Пример #16
0
        private void tsmi_Next_Click(object sender, EventArgs e)
        {
            DrawMode(true);                                                                                         //绘制模式开启
            Rectangle2 rectangle2 = Func_HalconFunction.DrawRectangle2(hWindow_Final1.hWindowControl.HalconWindow); //画矩形

            DrawMode(false);                                                                                        //绘制模式关闭
            HObject ho_Rectangle = Func_HalconFunction.GenRectangle2(rectangle2);                                   //创建矩形

            hWindow_Final1.DispObj(ho_Rectangle, "blue");                                                           //显示矩形
            getCircleUseThreshold.AddRegion(new GetRegionUseThreshold(new Threshold(rectangle2)));                  //添加该项
        }
Пример #17
0
        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);
        }
Пример #18
0
        /// <summary>
        /// Gets the connections whose start vertex is within the specified bounds.
        /// </summary>
        /// <remarks>
        /// <para>
        /// The out parameters will be null if the return result is zero.
        /// </para>
        /// </remarks>
        /// <param name="xmin">The minimum x-axis bounds.</param>
        /// <param name="zmin">The minimum z-axis bounds.</param>
        /// <param name="xmax">The maximum x-axis bounds.</param>
        /// <param name="zmax">The maximum z-axis bounds.</param>
        /// <param name="rverts">The connection vertices. [(start, end) * connCount]</param>
        /// <param name="rradii">The connection radii. [Length: connCount]</param>
        /// <param name="rdirs">The connection direction flags. [Length: connCount]</param>
        /// <param name="rareas">The connection areas. [Length: connCount]</param>
        /// <param name="rflags">The connection flags. [Length: connCount]</param>
        /// <param name="ruserIds">The connection user ids. [Length: connCount]</param>
        /// <returns>The number of connection returned.</returns>
        public int GetConnections(float xmin, float zmin, float xmax, float zmax
                                  , out Vector3[] rverts, out float[] rradii
                                  , out byte[] rdirs, out byte[] rareas, out ushort[] rflags, out uint[] ruserIds)
        {
            rverts   = null;
            rradii   = null;
            rdirs    = null;
            rareas   = null;
            rflags   = null;
            ruserIds = null;

            if (radii.Length == 0)
            {
                return(0);
            }

            List <Vector3> rlverts   = new List <Vector3>();
            List <float>   rlradii   = new List <float>();
            List <byte>    rldirs    = new List <byte>();
            List <byte>    rlareas   = new List <byte>();
            List <ushort>  rlflags   = new List <ushort>();
            List <uint>    rluserIds = new List <uint>();

            for (int i = 0; i < radii.Length; i++)
            {
                Vector3 v = verts[i * 2 + 0];
                if (Rectangle2.Contains(xmin, zmin, xmax, zmax, v.x, v.z))
                {
                    rlverts.Add(v);
                    rlverts.Add(verts[i * 2 + 1]);

                    rlradii.Add(radii[i]);
                    rldirs.Add(dirs[i]);
                    rlareas.Add(areas[i]);
                    rlflags.Add(flags[i]);
                    rluserIds.Add(userIds[i]);
                }
            }

            if (rlradii.Count == 0)
            {
                return(0);
            }

            rverts   = rlverts.ToArray();
            rradii   = rlradii.ToArray();
            rdirs    = rldirs.ToArray();
            rareas   = rlareas.ToArray();
            rflags   = rlflags.ToArray();
            ruserIds = rluserIds.ToArray();

            return(rradii.Length);
        }
Пример #19
0
        private static void DoPaint(IGraphics g, TextBox textBox)
        {
            g.FillRectangle(new Brush2(GraphUtils.ToColor2(textBox.BackColor)), textBox.Location.X, textBox.Location.Y,
                            textBox.Width - textBox.Margin.Left - textBox.Margin.Right,
                            textBox.Height - textBox.Margin.Top - textBox.Margin.Bottom);
            Rectangle2    rect   = new Rectangle2(GraphUtils.ToPointF2(textBox.Location), GraphUtils.ToSize2(textBox.Size));
            StringFormat2 format = new StringFormat2 {
                Alignment = StringAlignment2.Near, LineAlignment = StringAlignment2.Near
            };

            g.DrawString(textBox.Text, GraphUtils.ToFont2(textBox.Font), new Brush2(GraphUtils.ToColor2(textBox.ForeColor)), rect, format);
        }
Пример #20
0
        private static void DoPaint(IGraphics g, Label label)
        {
            Rectangle2 rect = new Rectangle2(GraphUtils.ToPointF2(label.Location), GraphUtils.ToSizeF2(label.Size));

            g.FillRectangle(new Brush2(GraphUtils.ToColor2(label.BackColor)), rect.X, rect.Y, label.Width - label.Margin.Left - label.Margin.Right,
                            label.Height - label.Margin.Top - label.Margin.Bottom);
            StringFormat2 format = new StringFormat2 {
                Alignment = StringAlignment2.Near, LineAlignment = StringAlignment2.Near
            };

            g.DrawString(label.Text, GraphUtils.ToFont2(label.Font), new Brush2(GraphUtils.ToColor2(label.ForeColor)), rect, format);
        }
Пример #21
0
        public override void Encode()
        {
            var x = 0; //rectangle.X;
            var y = 0; //rectangle.Y;
            var w = rectangle.Width;
            var h = rectangle.Height;

            CoRRE rect;
            var vector = new List<CoRRE>();


            if ((w <= 0xFF) && (h <= 0xFF))
            {
                rect = new CoRRE(rfb, framebuffer, pixels, rectangle);
                rect.Encode();
                vector.Add(rect);
            }
            else
            {
                int currentW, currentH;
                for (var currentY = 0; currentY < h; currentY += 0xFF)
                {
                    for (var currentX = 0; currentX < w; currentX += 0xFF)
                    {
                        try
                        {
                            currentW = w - currentX;
                            currentH = h - currentY;

                            if (currentW > 0xFF)
                                currentW = 0xFF;
                            if (currentH > 0xFF)
                                currentH = 0xFF;
                            var rc = new Rectangle2(x + currentX, y + currentY, currentW, currentH);
                            rect = new CoRRE(rfb, framebuffer, pixels, rc);

                            //problem ... WHY ?
                            rect.Encode();
                            vector.Add(rect);
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.ToString());
                            Console.ReadLine();
                        }
                    }
                }
            }

            rects = vector.ToArray();
            //count = rects.length;
        }
Пример #22
0
        private void btn3_MouseEnter(object sender, MouseEventArgs e)
        {
            StackPanel1.Visibility = Visibility.Hidden;
            StackPanel2.Visibility = Visibility.Visible;
            StackPanel3.Visibility = Visibility.Hidden;
            StackPanel4.Visibility = Visibility.Hidden;
            czy_otwarta_pierwsza   = false;
            czy_otwarta_druga      = true;
            czy_otwarta_trzecia    = false;
            czy_otwarta_czwarta    = false;

            Rectangle2.BeginAnimation(WidthProperty, BorderAnimation1);
        }
Пример #23
0
        //[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);
        }
Пример #24
0
        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);
        }
Пример #25
0
        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);
        }
Пример #26
0
    static void Main(string[] args)
    {
        // Rectangle1 r = new Rectangle1();
        // r.length = 4.2;
        // r.width = 5;
        // r.Display();

        Rectangle2 r = new Rectangle2();

        r.Acceptdetails();
        r.Display();

        Console.ReadKey();
    }
Пример #27
0
 private void btn2_MouseEnter(object sender, MouseEventArgs e)
 {
     if (StackPanel2.Visibility == Visibility.Hidden)
     {
         StackPanel2.BeginAnimation(HeightProperty, DropDownAnimation);
         StackPanel2.BeginAnimation(OpacityProperty, DropDownOpacityAnimation);
         StackPanel2.Effect.BeginAnimation(OpacityProperty, DropDownOpacityAnimation);
     }
     StackPanel1.Visibility = Visibility.Hidden;
     StackPanel2.Visibility = Visibility.Visible;
     StackPanel3.Visibility = Visibility.Hidden;
     StackPanel4.Visibility = Visibility.Hidden;
     Rectangle2.BeginAnimation(WidthProperty, BorderAnimation1);
 }
Пример #28
0
        [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
        }
Пример #29
0
        public Rectangle2 GetRect(bool?isTriangle = null)
        {
            if (!isTriangle.HasValue)
            {
                isTriangle = TextureIsTriangle;
            }

            if (isTriangle.Value)
            {
                return(Rectangle2.FromCoordinates(TexCoord0, TexCoord1, TexCoord2));
            }
            else
            {
                return(Rectangle2.FromCoordinates(TexCoord0, TexCoord1, TexCoord2, TexCoord3));
            }
        }
Пример #30
0
        /// <summary>
        /// 点是否在矩形内
        /// </summary>
        public static bool IsPointInRectangle(CADPoint point, Rectangle2 rect)
        {
            CADPoint rectLeftBottom = rect.leftBottom;
            CADPoint rectRightTop   = rect.rightTop;

            if (point.X >= rectLeftBottom.X &&
                point.X <= rectRightTop.X &&
                point.Y >= rectLeftBottom.Y &&
                point.Y <= rectRightTop.Y)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Пример #31
0
        public static IRectangle2 UpdateRelativeCoordinate(this IRectangle2 rectangle2,
                                                           IRelativeCoordinate relativeCoordinate)
        {
            var relativeCenterVector = new Vector(rectangle2.X, rectangle2.Y);
            var actualCenterVector   = relativeCoordinate.GetOriginalVector(relativeCenterVector);

            var relativeRect = new Rectangle2
            {
                X          = actualCenterVector.X,
                Y          = actualCenterVector.Y,
                Angle      = relativeCoordinate.GetCoordinateAngle() + rectangle2.Angle,
                HalfWidth  = rectangle2.HalfWidth,
                HalfHeight = rectangle2.HalfHeight
            };

            return(relativeRect);
        }
        public static void FixedRectangle()
        {
            // Simple, unrotated rectangle test
            Rectangle2 r;
            Point2     p;

            r = new Rectangle2(0f, 10f, 8f, new Point2(1f, 1f));
            p = new Point2(-6f, -6f);
            Assert.That(r.HasCollided(p), Is.False, "(-6f, -6f) is not contained within the rectangle.");

            p = new Point2(-3.5f, 4.5f);
            Assert.That(r.HasCollided(p), Is.True, "(-3.5f, 4.5f) is contained within the rectangle.");

            // Points which belong to a bounding line are not considered to have "collided" with the Rectangle
            p = new Point2(-3.5f, 5.0f);
            Assert.That(r.HasCollided(p), Is.False, "(-3.5f, 5.0f) is not contained within the rectangle.");
        }
Пример #33
0
        /// <summary>
        /// Main program flow for UI input and output.
        /// Some error handling is done below.  Some edge cases are not accounted for currently.
        /// </summary>
        /// <param name="problemModel"></param>
        public void BeginProgramFlow(ProblemModel problemModel, bool startAllOver)
        {
            if (startAllOver)
            {
                problemModel = new ProblemModel(); objectResponseValid = false; computeResponseValid = false;
            }

            if (!objectResponseValid)
            {
                ShowObjectTypeQuestion(problemModel);
            }
            ;
            if (!computeResponseValid)
            {
                ShowComputeTypeQuestion(problemModel);
            }
            ;

            GetWidthAndHeight(problemModel);

            if (problemModel.ComputeType.ToUpper() == "COMPUTEAREA")
            {
                Console.WriteLine("Use 'Problem1' or 'Problem2' ?");
                problemModel.ProblemNumber = Console.ReadLine().ToUpper();
            }
            else if (problemModel.ComputeType.ToUpper() == "COMPUTEPREMITER")
            {
                Console.WriteLine("Use 'Problem1' or 'Problem2' ?");
                problemModel.ProblemNumber = Console.ReadLine().ToUpper();
            }

            //Process the results
            if (problemModel.ProblemNumber == "PROBLEM1")
            {
                var squareClass = new Square1(problemModel);
                Console.WriteLine(problemModel.ComputeType + " = " + squareClass.GetResults());
                BeginProgramFlow(problemModel, true);
            }
            else if (problemModel.ProblemNumber == "PROBLEM2")
            {
                var rectangleClass = new Rectangle2(problemModel);
                Console.WriteLine(problemModel.ComputeType + " = " + rectangleClass.GetResults());
                BeginProgramFlow(problemModel, true);
            }
        }
        public void Collides_RectangleMovesIntoDiagonalLineAndOnlyOneCornerEndsUpOnTheOtherSideOfTheLine_ReturnsFalse()
        {
            rectangle = new Rectangle2(-2, 2, 2, -2);
            var diagonalLine = new Line2(5, -1, 8, 1);
            movement = new Vector2(5, 0);

            Assert.IsFalse(CollisionDetector.Collides(rectangle, movement, diagonalLine));
        }
Пример #35
0
 public void DrawArc(Pen2 pen, Rectangle2 rec, float startAngle, float sweepAngle)
 {
     throw new System.NotImplementedException();
 }
        public void FindCollision_RectangleStartsInsideLineItFullyEnvelopsMovesLeft_ReturnsMinus1()
        {
            rectangle = new Rectangle2(-2, -2, 2, 2);
            movement = new Vector2(2, 0);
            verticalLine = new Line2(0, -1, 0, 1);

            Assert.AreEqual(-1, CollisionDetector.FindCollision(rectangle, movement, verticalLine).Value.Value);
        }
Пример #37
0
 public CopyRectRectangle(VncHost rfb, Framebuffer framebuffer, Rectangle2 rectangle)
     : base(rfb, framebuffer, rectangle)
 {
 }
        public void FindCollision_RectangleStartsInsideLineMovesRight_ReturnsMinus1()
        {
            rectangle = new Rectangle2(-2, -2, 2, 2);
            movement = new Vector2(-2, 0);
            verticalLine = new Line2(0, 5, 0, -5);

            Assert.AreEqual(-1, CollisionDetector.FindCollision(rectangle, movement, verticalLine).Value.Value);
        }
Пример #39
0
 /// <summary>
 /// Creates an object type derived from EncodedRectangle, based on the value of encoding.
 /// </summary>
 /// <param name="rectangle">A node object from the Screen Handler defining the bounds of the rectangle and the pixel data. IT SHOULD BE CONSIDERED LOCALLY AGAINST pixels param, not globally against the screen size</param>
 /// <param name="encoding">An Integer indicating the encoding type to be used for this rectangle.  Used to determine the type of EncodedRectangle to create.</param>
 /// <returns></returns>
 public EncodedRectangle Build(Rectangle2 rectangle, VncHost.Encoding encoding)
 {
     Bitmap bmp = PixelGrabber.CreateScreenCapture(rectangle.ToRectangle());
     int[] pixels = PixelGrabber.GrabPixels(bmp, rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height, bmp.PixelFormat);
     return Build(rectangle, pixels, encoding);
 }
Пример #40
0
        //private object syncLock = new object();
        public QuadTree(Rectangle2 screenSize, int[] pixels, int minTileHeight = 64, int minTileWidth = 64)
        {
            var t = Stopwatch.StartNew();
            QuadNode.MIN_HEIGHT = minTileHeight; //Any better way ?
            QuadNode.MIN_WIDTH = minTileWidth;

            ScreenSize = screenSize;
            ScreenPixels = pixels;
            LocationToNode = new Dictionary<Rectangle2, QuadNode>();

            Root = new QuadNode(screenSize, pixels);

            //Very time consuming method ! Needs optimization
            //Root.Expand();

            var a = Stopwatch.StartNew();
            var lowestLevel = BFSLowest();
            a.Stop();
            Trace.WriteLine("Found lowest in:" + a.ElapsedMilliseconds + "ms");

            a = Stopwatch.StartNew();
            var numberOfTasks = lowestLevel.Count*4;
            var signal = new ManualResetEvent(false);

            var arr = lowestLevel.ToArray();
            for (var iter = 0; iter < arr.Length; iter++)
            {
                var currNode = arr[iter];
                for (var i = 0; i < 4; i++)
                {
                    var li = i;
                    //ThreadPool.QueueUserWorkItem(func =>
                    //{
                    var occurances = new Dictionary<int, long>();
                    long h = 1;
                    long maxO = -1;
                    long maxV = -1;

                    for (long j = 0; j < currNode.childrenData[li].Length; j++)
                    {
                        var px = currNode.childrenData[li][j];
                        h = h*((px + j)%QuadNode.Q)%QuadNode.Q;

                        var val = px;
                        if (!occurances.ContainsKey(val))
                            occurances.Add(val, 0);
                        occurances[val]++;

                        if (occurances[val] > maxO)
                        {
                            maxO = occurances[val];
                            maxV = val;
                        }
                    }

                    currNode.childrenHashes[li] = h;
                    long diff = occurances.Count;

                    //Calculates the percentage of different pixels in the rectangle
                    //If it is less than 10 in 1024, the tile is considered to be filled with a solid color
                    //The solid color used for filling is the color which occured the most times
                    var percDiff = (float) diff/currNode.childrenData[li].Length;
                    if (percDiff < 0.01)
                    {
                        currNode.childrenRect[li].SetSolidColor((int) maxV);
                        currNode.childrenHashes[li] = (long) Math.Pow(maxV*maxO*diff, 3)%QuadNode.Q;
                        //idk if the previous hash would be better or this one
                    }
                    currNode.DataHash = (currNode.DataHash + currNode.childrenHashes[li])%QuadNode.Q;

                    if (Interlocked.Decrement(ref numberOfTasks) == 0)
                    {
                        signal.Set();
                    }
                    //});
                }
            }
            signal.WaitOne();
            a.Stop();
            Trace.WriteLine("Processed nodes in:" + a.ElapsedMilliseconds + "ms");

            Root.CalculateHash();
            //IEnumerable<QuadNode> nodes = GetChildren(Root);
            //foreach (QuadNode ch in nodes)
            //{
            //LocationToNode.Add(ch.Bounds, ch);
            //}
            t.Stop();
            Trace.WriteLine("QuadTree construction: " + t.ElapsedMilliseconds + "ms");
        }
Пример #41
0
 public QuadNode this[Rectangle2 location]
 {
     get { return LocationToNode[location]; }
 }
Пример #42
0
 public void SetClip(Rectangle2 rectangle)
 {
     throw new System.NotImplementedException();
 }
Пример #43
0
 public EncodedRectangle Build(Rectangle2 rectangle, int[] pixels, VncHost.Encoding encoding)
 {
     EncodedRectangle e;
     switch (encoding)
     {
         case VncHost.Encoding.RawEncoding:
             e = new RawRectangle(rfb, framebuffer, pixels, rectangle);
             break;
         case VncHost.Encoding.CopyRectEncoding:
             e = new CopyRectRectangle(rfb, framebuffer, rectangle);
             break;
         case VncHost.Encoding.RreEncoding:
             e = new RreRectangle(rfb, framebuffer, pixels, rectangle);
             break;
         case VncHost.Encoding.CoRreEncoding:
             e = new CoRreRectangle(rfb, framebuffer, pixels, rectangle);
             break;
         case VncHost.Encoding.HextileEncoding:
             e = new HextileRectangle(rfb, framebuffer, pixels, rectangle);
             break;
         case VncHost.Encoding.ZrleEncoding:
             e = new ZrleRectangle(rfb, framebuffer, pixels, rectangle);
             break;
         case VncHost.Encoding.ZlibEncoding:
             e = new ZlibRectangle(rfb, framebuffer, pixels, rectangle);
             break;
         default:
             // Sanity check
             throw new Exception("Unsupported Encoding Format received: " + encoding + ".");
     }
     return e;
 }
Пример #44
0
 public EncodedRectangle(VncHost rfb, Framebuffer framebuffer, Rectangle2 rectangle)
 {
     this.rfb = rfb;
     this.framebuffer = framebuffer;
     this.rectangle = rectangle;
 }
 public void SetUp()
 {
     position = new Vector2(0, 0);
     rectangle = new Rectangle2(-1, 1, 1, -1);
     movement = new Vector2(10, 0);
     verticalLine = new Line2(5, -5, 5, 5);
     horizontalLine = new Line2(-5, 5, 5, 5);
 }
        public void FindCollision_RectangleEnvelopsLineFromLeft2_Returns0p25()
        {
            rectangle = new Rectangle2(-50, 25, -25, -25);
            verticalLine = new Line2(0, -10, 0, 10);
            movement = new Vector2(100, 0);

            Assert.AreEqual(0.25f, CollisionDetector.FindCollision(rectangle, movement, verticalLine).Value.Value);
        }
 public void SetUp()
 {
     rectangle = new Rectangle2(-1, 1, 1, -1);
     line = new Line2(0, -10, 0, 10);
 }
Пример #48
0
 public CoRreRectangle(VncHost rfb, Framebuffer framebuffer, int[] pixels, Rectangle2 rectangle)
     : base(rfb, framebuffer, rectangle)
 {
     this.pixels = pixels;
 }
        public void FindCollision_RectangleMovesFullyAcrossLineFromRight_Returns0p4()
        {
            rectangle = new Rectangle2(9, -1, 11, 1);
            movement = new Vector2(-10, 0);
            verticalLine = new Line2(5, 5, 5, -5);

            Assert.AreEqual(0.4f, CollisionDetector.FindCollision(rectangle, movement, verticalLine).Value.Value);
        }
        public void FindCollision_RectangleCollidesWithSideOfLine_ReturnsNull()
        {
            rectangle = new Rectangle2(-50, 25, 0, -25);
            horizontalLine = new Line2(50, -50, 100, -50);
            movement = new Vector2(100, -100);

            Assert.IsNull(CollisionDetector.FindCollision(rectangle, movement, horizontalLine));
        }
Пример #51
0
 public void DrawString(string s, Font2 font, Brush2 brush, Rectangle2 rectangleF)
 {
     throw new System.NotImplementedException();
 }