Bug 1351426 - Part 4: Refactor gfx::Polygon to avoid unnecessary work and memory allocations r=kip
MozReview-Commit-ID: ASusoTqZxuY
This commit is contained in:
@@ -57,13 +57,19 @@ BSPTree::BuildTree(BSPTreeNode* aRoot,
|
||||
}
|
||||
|
||||
const gfx::Polygon& plane = aRoot->First();
|
||||
MOZ_ASSERT(!plane.IsEmpty());
|
||||
|
||||
const gfx::Point4D& planeNormal = plane.GetNormal();
|
||||
const gfx::Point4D& planePoint = plane.GetPoints()[0];
|
||||
|
||||
std::list<LayerPolygon> backLayers, frontLayers;
|
||||
for (LayerPolygon& layerPolygon : aLayers) {
|
||||
const Maybe<gfx::Polygon>& geometry = layerPolygon.geometry;
|
||||
const nsTArray<gfx::Point4D>& geometry = layerPolygon.geometry->GetPoints();
|
||||
|
||||
// Calculate the plane-point distances for the polygon classification.
|
||||
size_t pos = 0, neg = 0;
|
||||
nsTArray<float> dots = geometry->CalculateDotProducts(plane, pos, neg);
|
||||
nsTArray<float> distances =
|
||||
CalculatePointPlaneDistances(geometry, planeNormal, planePoint, pos, neg);
|
||||
|
||||
// Back polygon
|
||||
if (pos == 0 && neg > 0) {
|
||||
@@ -80,10 +86,13 @@ BSPTree::BuildTree(BSPTreeNode* aRoot,
|
||||
// Polygon intersects with the splitting plane.
|
||||
else if (pos > 0 && neg > 0) {
|
||||
nsTArray<gfx::Point4D> backPoints, frontPoints;
|
||||
geometry->SplitPolygon(plane.GetNormal(), dots, backPoints, frontPoints);
|
||||
// Clip the polygon against the plane. We reuse the previously calculated
|
||||
// distances to find the plane-edge intersections.
|
||||
ClipPointsWithPlane(geometry, planeNormal, distances,
|
||||
backPoints, frontPoints);
|
||||
|
||||
const gfx::Point4D& normal = geometry->GetNormal();
|
||||
Layer *layer = layerPolygon.layer;
|
||||
const gfx::Point4D& normal = layerPolygon.geometry->GetNormal();
|
||||
Layer* layer = layerPolygon.layer;
|
||||
|
||||
if (backPoints.Length() >= 3) {
|
||||
backLayers.emplace_back(layer, Move(backPoints), normal);
|
||||
|
||||
Reference in New Issue
Block a user