Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1265)

Unified Diff: cc/quads/draw_polygon.cc

Issue 1497153002: Replace inverse transform with Cross-product computation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Moved section and rebased again Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « cc/quads/draw_polygon.h ('k') | cc/quads/draw_polygon_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/quads/draw_polygon.cc
diff --git a/cc/quads/draw_polygon.cc b/cc/quads/draw_polygon.cc
index b4f132a8f85ee6630cd84344f4f1b1dfb700ef99..b279fe6ac6fba65497b1f96db1c3dc7f33907c59 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,37 @@ 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);
+ 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);
+ }
+}
+
+#if defined(OS_WIN)
+//
+// Allows the unittest to invoke this for the more general constructor.
+//
+void DrawPolygon::RecomputeNormalForTesting() {
+ ConstructNormal();
+}
+#endif
+
float DrawPolygon::SignedPointDistance(const gfx::Point3F& point) const {
return gfx::DotProduct(point - points_[0], normal_);
}
@@ -210,7 +241,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
« no previous file with comments | « cc/quads/draw_polygon.h ('k') | cc/quads/draw_polygon_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698