public ReturnedData doStuff(Point[] withPoints) { setStuff(withPoints[0], withPoints[1], withPoints[2], withPoints[3]); ReturnedData data = new ReturnedData(); Stopwatch watch = new Stopwatch(); watch.Start(); var actuallySquare = calculateActualSquare(leftPoint_, upPoint_, downPoint_); data.actualSquare = actuallySquare; var number = new Random(); int insideCounter; double randomX; double randomY; for (var i = 0; i < 5; i++) { watch.Start(); double n = Math.Pow(10, i + 3); insideCounter = 0; for (var j = 0; j < n; j++) { randomX = minX_ + ToDouble(number.Next(0, 132767)) / 132767 * (maxX_ - minX_); //minX_ * number.Next (ToInt32 ( minX_ ), ToInt32(maxX_)); randomY = minY_ + ToDouble(number.Next(0, 132767)) / 132767 * (maxY_ - minY_); //number.Next (ToInt32 ( minY_ ), ToInt32(maxY_)); if (isInside(new Point(randomX, randomY))) { insideCounter++; } } var square = square_ * insideCounter / n; watch.Stop(); data.addSquare(square); data.addAcc(Math.Abs(square - actuallySquare) / actuallySquare); data.addPoints(n); data.addPointsInside(insideCounter); data.addTime(watch.Elapsed); watch.Reset(); } return(data); }
public ReturnedData calculate() { ReturnedData data = new ReturnedData(); Stopwatch watch = new Stopwatch(); watch.Start(); var actualSquare = calculatedFigure_.calculateActualSquare(); data.actualSquare = actualSquare; var number = new Random(); int insideCounter; double randomX; double randomY; for (var i = 0; i < 5; i++) { watch.Start(); double n = Math.Pow(10, i + 3); insideCounter = 0; for (var j = 0; j < n; j++) { randomX = mainFigure_.minX_ + ToDouble(number.Next(0, 132767)) / 132767 * (mainFigure_.maxX_ - mainFigure_.minX_); //minX_ * number.Next (ToInt32 ( minX_ ), ToInt32(maxX_)); randomY = mainFigure_.minY_ + ToDouble(number.Next(0, 132767)) / 132767 * (mainFigure_.maxY_ - mainFigure_.minY_); //number.Next (ToInt32 ( minY_ ), ToInt32(maxY_)); if (calculatedFigure_.isInside(new Point(randomX, randomY))) { insideCounter++; } } var square = mainFigure_.square_ * insideCounter / n; watch.Stop(); data.addSquare(square); data.addAcc(Math.Abs(square - actualSquare) / actualSquare); data.addPoints(n); data.addPointsInside(insideCounter); data.addTime(watch.Elapsed); watch.Reset(); } return(data); }