コード例 #1
0
ファイル: AreaTests.cs プロジェクト: alistairfrith/Fractal
        public void PointFromProportionTest()
        {
            IArea      area  = new Area(new Cartesian(100, 150), new Cartesian(200, 50));
            ICartesian point = area.PointFromProportion(new Cartesian(0.3, 0.7));

            Assert.AreEqual(130, point.X);
            Assert.AreEqual(120, point.Y);
        }
コード例 #2
0
ファイル: AreaTests.cs プロジェクト: alistairfrith/Fractal
        public void ProportionFromPointTest()
        {
            IArea      area       = new Area(new Cartesian(100, 150), new Cartesian(200, 50));
            ICartesian proportion = area.ProportionFromPoint(new Cartesian(130, 120));

            Assert.AreEqual(0.3, proportion.X);
            Assert.AreEqual(0.7, proportion.Y);
        }
コード例 #3
0
        public ICartesian PointFromProportion(ICartesian proportion)
        {
            if (Width == 0 || Height == 0)
            {
                throw new Exception("Cannot calculate on 0-sized area");
            }

            return(new Cartesian(Left + (proportion.X * Width),
                                 Bottom + (proportion.Y * Height)));
        }
コード例 #4
0
        public ICartesian ProportionFromPoint(ICartesian point)
        {
            if (Width == 0 || Height == 0)
            {
                throw new Exception("Cannot calculate on 0-sized area");
            }

            return(new Cartesian((point.X - Left) / Width,
                                 (point.Y - Bottom) / Height));
        }
コード例 #5
0
        private void myImage_MouseWheel(object sender, MouseWheelEventArgs e)
        {
            ICartesian imageCenterCoordinates = new Cartesian(e.GetPosition(myImage).X, e.GetPosition(myImage).Y);
            ICartesian imageCenterProportion  = DrawingArea.ProportionFromPoint(imageCenterCoordinates);

            double zoomFactor = 3;

            zoomFactor = (e.Delta > 0) ? zoomFactor : 1 / zoomFactor;
            Fractal.Zoom(imageCenterProportion, new Cartesian(zoomFactor, zoomFactor));
            Render(myImage.ActualWidth, myImage.ActualHeight);
        }
コード例 #6
0
        private int[] ColumnValues(int colNum, int height, IArea drawingArea)
        {
            int[] column = new int[height];

            for (int rowNum = 0; rowNum < height; rowNum++)
            {
                ICartesian coordinate = drawingArea.ProportionFromPoint(new Cartesian(colNum, rowNum));

                column[rowNum] = PointValue(coordinate);
            }

            return(column);
        }
コード例 #7
0
        public void Transform(ICartesian newCenter, ICartesian zoom)
        {
            // first translate
            double oldCenterX = Left + (Width / 2);
            double xBy        = newCenter.X - oldCenterX;

            Left  += xBy;
            Right += xBy;

            double oldCenterY = Bottom + (Height / 2);
            double yBy        = newCenter.Y - oldCenterY;

            Top    += yBy;
            Bottom += yBy;

            // then scale
            xBy    = Width * (1 - (1 / zoom.X));
            Left  += xBy / 2;
            Right -= xBy / 2;

            yBy     = Height * (1 - (1 / zoom.Y));
            Top    -= yBy / 2;
            Bottom += yBy / 2;
        }
コード例 #8
0
        public int PointValue(ICartesian proportion)
        {
            ICartesian coordinates = mRenderArea.PointFromProportion(proportion);

            return(PointValue(coordinates.X, coordinates.Y));
        }
コード例 #9
0
        public void Zoom(ICartesian newCenterByProportion, ICartesian zoomFactor)
        {
            ICartesian newCenter = mRenderArea.PointFromProportion(newCenterByProportion);

            mRenderArea.Transform(newCenter, zoomFactor);
        }
コード例 #10
0
 public Area(ICartesian topLeft, ICartesian bottomRight)
 {
     TopLeft     = new Cartesian(topLeft.X, topLeft.Y);
     BottomRight = new Cartesian(bottomRight.X, bottomRight.Y);
 }