Chromium Code Reviews| Index: cc/quads/draw_polygon.cc |
| diff --git a/cc/quads/draw_polygon.cc b/cc/quads/draw_polygon.cc |
| index b4f132a8f85ee6630cd84344f4f1b1dfb700ef99..852b6e5eb45949a588c3575ae75b81dfb435706d 100644 |
| --- a/cc/quads/draw_polygon.cc |
| +++ b/cc/quads/draw_polygon.cc |
| @@ -70,7 +70,7 @@ DrawPolygon::DrawPolygon(const DrawQuad* original_ref, |
| for (int i = 0; i < num_vertices_in_clipped_quad; i++) { |
| points_.push_back(points[i]); |
| } |
| - ApplyTransformToNormal(transform); |
| + ConstructNormal(); |
| } |
| DrawPolygon::~DrawPolygon() { |
| @@ -88,6 +88,28 @@ scoped_ptr<DrawPolygon> DrawPolygon::CreateCopy() { |
| return new_polygon; |
| } |
| +// |
| +// If this were to be more generally used and expected to be applicable |
| +// replacing this with Newell's algorithm (or an improvement thereof) |
| +// would be preferable, but usually this is coming in from a rectangle |
| +// that has been transformed to screen space and clipped. |
| +// Averaging a few near diagonal cross products is pretty good in that case. |
| +// |
| +void DrawPolygon::ConstructNormal() { |
| + normal_.set_x(0.0f); |
| + normal_.set_y(0.0f); |
| + normal_.set_z(0.0f); |
|
Peter Mayo
2015/12/04 16:40:41
What about saving the old normal and adding a fall
|
| + int delta = points_.size() / 2; |
| + for (size_t i = 1; i + delta < points_.size(); i++) { |
| + normal_ += |
| + CrossProduct(points_[i] - points_[0], points_[i + delta] - points_[0]); |
| + } |
| + float normal_magnitude = normal_.Length(); |
| + if (normal_magnitude != 0 && normal_magnitude != 1) { |
| + normal_.Scale(1.0f / normal_magnitude); |
| + } |
| +} |
| + |
| float DrawPolygon::SignedPointDistance(const gfx::Point3F& point) const { |
| return gfx::DotProduct(point - points_[0], normal_); |
| } |
| @@ -210,7 +232,7 @@ void DrawPolygon::ApplyTransform(const gfx::Transform& transform) { |
| // be transformed along with the vertices. |
| void DrawPolygon::TransformToScreenSpace(const gfx::Transform& transform) { |
| ApplyTransform(transform); |
| - ApplyTransformToNormal(transform); |
| + ConstructNormal(); |
| } |
| // In the case of TransformToLayerSpace, we assume that we are giving the |