Ticket #3588: optimize-rasterize.patch
File optimize-rasterize.patch, 2.7 KB (added by , 8 years ago) |
---|
-
source/simulation2/helpers/Rasterize.cpp
65 65 // Find the min/max range of cells that are strictly inside the square+rasterClearance. 66 66 // (Since the square+rasterClearance is a convex shape, we can just test each 67 67 // corner of each cell is inside the shape.) 68 // (TODO: This potentially does a lot of redundant work.) 68 // When looping on i, if the previous cell was inside, no need to check again the left corners. 69 // and we can stop the loop when exiting the shape. 70 // Futhermore if one of the right corners of a cell is outside, no need to check the following cell 69 71 i16 spanI0 = std::numeric_limits<i16>::max(); 70 72 i16 spanI1 = std::numeric_limits<i16>::min(); 73 bool previousInside = false; 74 bool skipNextCell = false; 71 75 for (i16 i = i0; i < i1; ++i) 72 76 { 73 if (Geometry::DistanceToSquareSquared(CFixedVector2D(cellSize*i-shape.x, cellSize*j-shape.z), 74 shape.u, shape.v, shapeHalfSize, true) > rasterClearance) 77 if (skipNextCell) 78 { 79 skipNextCell = false; 75 80 continue; 81 } 76 82 77 83 if (Geometry::DistanceToSquareSquared(CFixedVector2D(cellSize*(i+1)-shape.x, cellSize*j-shape.z), 78 shape.u, shape.v, shapeHalfSize, true) > rasterClearance) 84 shape.u, shape.v, shapeHalfSize, true) > rasterClearance) 85 { 86 if (previousInside) 87 break; 88 skipNextCell = true; 79 89 continue; 90 } 80 91 81 if (Geometry::DistanceToSquareSquared(CFixedVector2D(cellSize*i-shape.x, cellSize*(j+1)-shape.z),82 shape.u, shape.v, shapeHalfSize, true) > rasterClearance)83 continue;84 85 92 if (Geometry::DistanceToSquareSquared(CFixedVector2D(cellSize*(i+1)-shape.x, cellSize*(j+1)-shape.z), 86 shape.u, shape.v, shapeHalfSize, true) > rasterClearance) 93 shape.u, shape.v, shapeHalfSize, true) > rasterClearance) 94 { 95 if (previousInside) 96 break; 97 skipNextCell = true; 87 98 continue; 99 } 88 100 89 spanI0 = std::min(spanI0, i); 90 spanI1 = std::max(spanI1, (i16)(i+1)); 101 if (!previousInside) 102 { 103 if (Geometry::DistanceToSquareSquared(CFixedVector2D(cellSize*i-shape.x, cellSize*j-shape.z), 104 shape.u, shape.v, shapeHalfSize, true) > rasterClearance) 105 continue; 106 107 if (Geometry::DistanceToSquareSquared(CFixedVector2D(cellSize*i-shape.x, cellSize*(j+1)-shape.z), 108 shape.u, shape.v, shapeHalfSize, true) > rasterClearance) 109 continue; 110 111 previousInside = true; 112 spanI0 = i; 113 } 114 115 spanI1 = i+1; 91 116 } 92 117 93 118 // Add non-empty spans onto the list