/** * @return Model_Road */ private function calculateAverageRoad() { $model = new Model_Road(); $road = $this->getSourceRoad(); $start = $road->getStart(); $end = $road->getEnd(); $step = $this->getStep(); $base = $this->getBase(); $sumStep = 0.1; $points = $base / $sumStep + 1; $dStep = $step / $sumStep; $positiveOffsetValue = $base / 2; $negativeOffsetValue = $positiveOffsetValue; // $dSum = 0; // // for ( $j = $start - $negativeOffsetValue; $j < $start - $negativeOffsetValue + $step - $sumStep; $j += $sumStep ){ // $dSum += $road->getCoordinate( $j ); // } $sum = 0; for ($j = $start - $negativeOffsetValue; $j <= $start + $positiveOffsetValue; $j += $sumStep) { $sum += $road->getCoordinate($j); } for ($coordinate = $start; $coordinate < $end; $i++, $coordinate += $step) { $model->addCoordinate(new Model_Coordinate($coordinate, $sum / $points)); // Remove first N points from sum for ($i = 0, $j = $coordinate - $negativeOffsetValue; $i < $dStep; $j += $sumStep, $i++) { $sum -= $road->getCoordinate($j); } // Add next N points to the sum for ($i = 0, $j = $coordinate + $positiveOffsetValue + $sumStep; $i < $dStep; $j += $sumStep, $i++) { $sum += $road->getCoordinate($j); } } return $model; }
/** * @return \Model_Road */ public function getSmoothedRoad() { if (is_null($this->smoothedRoad)) { $r = new Model_Road(); $x = $this->getSourceRoad()->getStart(); $step = $this->getStep(); for (; $x < $this->getSourceRoad()->getEnd(); $x += $step) { $r->addCoordinate(new Model_Coordinate($x, $this->getSourceRoad()->getCoordinate($x) - $this->getAverageRoad()->getCoordinate($x))); } $this->setSmoothedRoad($r); } return $this->smoothedRoad; }