1
0
forked from 0ad/0ad

Optimize RasterizeRectWithClearance slightly further. Thanks mimo for noticing.

This was SVN commit r17209.
This commit is contained in:
wraitii 2015-11-08 18:08:49 +00:00
parent 313d324fac
commit 0ba9fa1cc1

View File

@ -44,6 +44,7 @@ void SimRasterize::RasterizeRectWithClearance(Spans& spans,
// Get the bounds of cells that might possibly be within the shape // Get the bounds of cells that might possibly be within the shape
// (We'll then test each of those cells more precisely) // (We'll then test each of those cells more precisely)
CFixedVector2D shapeHalfSize(CFixedVector2D(shape.hw, shape.hh));
CFixedVector2D halfSize(shape.hw + rasterClearance, shape.hh + rasterClearance); CFixedVector2D halfSize(shape.hw + rasterClearance, shape.hh + rasterClearance);
CFixedVector2D halfBound = Geometry::GetHalfBoundingBox(shape.u, shape.v, halfSize); CFixedVector2D halfBound = Geometry::GetHalfBoundingBox(shape.u, shape.v, halfSize);
i16 i0 = ((shape.x - halfBound.X) / cellSize).ToInt_RoundToNegInfinity(); i16 i0 = ((shape.x - halfBound.X) / cellSize).ToInt_RoundToNegInfinity();
@ -69,33 +70,21 @@ void SimRasterize::RasterizeRectWithClearance(Spans& spans,
i16 spanI1 = std::numeric_limits<i16>::min(); i16 spanI1 = std::numeric_limits<i16>::min();
for (i16 i = i0; i < i1; ++i) for (i16 i = i0; i < i1; ++i)
{ {
if (Geometry::DistanceToSquareSquared( if (Geometry::DistanceToSquareSquared(CFixedVector2D(cellSize*i-shape.x, cellSize*j-shape.z),
CFixedVector2D(cellSize*i, cellSize*j) - CFixedVector2D(shape.x, shape.z), shape.u, shape.v, shapeHalfSize, true) > rasterClearance)
shape.u, shape.v, CFixedVector2D(shape.hw, shape.hh), true) > rasterClearance)
{
continue; continue;
}
if (Geometry::DistanceToSquareSquared( if (Geometry::DistanceToSquareSquared(CFixedVector2D(cellSize*(i+1)-shape.x, cellSize*j-shape.z),
CFixedVector2D(cellSize*(i+1), cellSize*j) - CFixedVector2D(shape.x, shape.z), shape.u, shape.v, shapeHalfSize, true) > rasterClearance)
shape.u, shape.v, CFixedVector2D(shape.hw, shape.hh), true) > rasterClearance)
{
continue; continue;
}
if (Geometry::DistanceToSquareSquared( if (Geometry::DistanceToSquareSquared(CFixedVector2D(cellSize*i-shape.x, cellSize*(j+1)-shape.z),
CFixedVector2D(cellSize*i, cellSize*(j+1)) - CFixedVector2D(shape.x, shape.z), shape.u, shape.v, shapeHalfSize, true) > rasterClearance)
shape.u, shape.v, CFixedVector2D(shape.hw, shape.hh), true) > rasterClearance)
{
continue; continue;
}
if (Geometry::DistanceToSquareSquared( if (Geometry::DistanceToSquareSquared(CFixedVector2D(cellSize*(i+1)-shape.x, cellSize*(j+1)-shape.z),
CFixedVector2D(cellSize*(i+1), cellSize*(j+1)) - CFixedVector2D(shape.x, shape.z), shape.u, shape.v, shapeHalfSize, true) > rasterClearance)
shape.u, shape.v, CFixedVector2D(shape.hw, shape.hh), true) > rasterClearance)
{
continue; continue;
}
spanI0 = std::min(spanI0, i); spanI0 = std::min(spanI0, i);
spanI1 = std::max(spanI1, (i16)(i+1)); spanI1 = std::max(spanI1, (i16)(i+1));