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); }
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); }
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))); }
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)); }
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); }
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); }
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; }
public int PointValue(ICartesian proportion) { ICartesian coordinates = mRenderArea.PointFromProportion(proportion); return(PointValue(coordinates.X, coordinates.Y)); }
public void Zoom(ICartesian newCenterByProportion, ICartesian zoomFactor) { ICartesian newCenter = mRenderArea.PointFromProportion(newCenterByProportion); mRenderArea.Transform(newCenter, zoomFactor); }
public Area(ICartesian topLeft, ICartesian bottomRight) { TopLeft = new Cartesian(topLeft.X, topLeft.Y); BottomRight = new Cartesian(bottomRight.X, bottomRight.Y); }