Index: cc/quads/draw_polygon.cc |
diff --git a/cc/quads/draw_polygon.cc b/cc/quads/draw_polygon.cc |
index bfc2b49296d0e09891a3df43e13531449b92ea75..fce2c901c1b923a334c5f26fed569f125d0e8686 100644 |
--- a/cc/quads/draw_polygon.cc |
+++ b/cc/quads/draw_polygon.cc |
@@ -12,11 +12,11 @@ |
namespace { |
// This allows for some imperfection in the normal comparison when checking if |
// two pieces of geometry are coplanar. |
-static const float coplanar_dot_epsilon = 0.01f; |
+static const float coplanar_dot_epsilon = 0.000001f; |
enne (OOO)
2014/09/24 17:35:30
Can you give me some examples that helped motivate
|
// This threshold controls how "thick" a plane is. If a point's distance is |
// <= |compare_threshold|, then it is considered on the plane. Only when this |
// boundary is crossed do we consider doing splitting. |
-static const float compare_threshold = 1.0f; |
+static const float compare_threshold = 0.0001f; |
// |split_threshold| is lower in this case because we want the points created |
// during splitting to be well within the range of |compare_threshold| for |
// comparison purposes. The splitting operation will produce intersection points |
@@ -25,12 +25,13 @@ static const float compare_threshold = 1.0f; |
// points that SHOULD be intersecting the "thick plane", but actually fail to |
// test positively for it because |split_threshold| allowed them to be outside |
// this range. |
-static const float split_threshold = 0.5f; |
+static const float split_threshold = 0.00005f; |
enne (OOO)
2014/09/24 17:35:30
Should this split threshold be relative to the com
|
} // namespace |
namespace cc { |
-gfx::Vector3dF DrawPolygon::default_normal = gfx::Vector3dF(0.0f, 0.0f, -1.0f); |
+//TODO (awoloszyn) Why did we switch the sign of the default normal |
+gfx::Vector3dF DrawPolygon::default_normal = gfx::Vector3dF(0.0f, 0.0f, 1.0f); |
DrawPolygon::DrawPolygon() { |
} |
@@ -53,8 +54,9 @@ DrawPolygon::DrawPolygon(DrawQuad* original_ref, |
const gfx::RectF& visible_content_rect, |
const gfx::Transform& transform, |
int draw_order_index) |
- : order_index_(draw_order_index), original_ref_(original_ref) { |
- normal_ = default_normal; |
+ : normal_(default_normal), |
+ order_index_(draw_order_index), |
+ original_ref_(original_ref) { |
gfx::Point3F points[8]; |
int num_vertices_in_clipped_quad; |
gfx::QuadF send_quad(visible_content_rect); |
@@ -97,6 +99,10 @@ float DrawPolygon::SignedPointDistance(const gfx::Point3F& point) const { |
// Assumes that layers are split and there are no intersecting planes. |
BspCompareResult DrawPolygon::SideCompare(const DrawPolygon& a, |
const DrawPolygon& b) { |
+ |
+ // Let's make sure that both of these are normalized. |
+ DCHECK_GE(0.001f, std::abs(a.normal_.LengthSquared() - 1.0f)); |
+ DCHECK_GE(0.001f, std::abs(b.normal_.LengthSquared() - 1.0f)); |
// Right away let's check if they're coplanar |
double dot = gfx::DotProduct(a.normal_, b.normal_); |
float sign = 0.0f; |
@@ -105,7 +111,7 @@ BspCompareResult DrawPolygon::SideCompare(const DrawPolygon& a, |
if (std::abs(dot) >= 1.0f - coplanar_dot_epsilon) { |
normal_match = true; |
// The normals are matching enough that we only have to test one point. |
- sign = gfx::DotProduct(a.points_[0] - b.points_[0], b.normal_); |
+ sign = b.SignedPointDistance(a.points_[0]); |
// Is it on either side of the splitter? |
if (sign < -compare_threshold) { |
return BSP_BACK; |
@@ -168,7 +174,7 @@ static bool LineIntersectPlane(const gfx::Point3F& line_start, |
// The case where one vertex lies on the thick-plane and the other |
// is outside of it. |
- if (std::abs(start_distance) < distance_threshold && |
+ if (std::abs(start_distance) <= distance_threshold && |
std::abs(end_distance) > distance_threshold) { |
intersection->SetPoint(line_start.x(), line_start.y(), line_start.z()); |
return true; |
@@ -270,11 +276,14 @@ bool DrawPolygon::Split(const DrawPolygon& splitter, |
break; |
} |
} |
- if (current_vertex++ > points_size) { |
+ if (current_vertex++ > (points_size + 1)) { |
break; |
} |
} |
DCHECK_EQ(current_intersection, static_cast<size_t>(2)); |
+ if (current_intersection != 2) { //TODO (awoloszyn) we should definitely remove this |
+ return false; |
+ } |
// Since we found both the intersection points, we can begin building the |
// vertex set for both our new polygons. |
@@ -284,6 +293,7 @@ bool DrawPolygon::Split(const DrawPolygon& splitter, |
// First polygon. |
out_points[0].push_back(intersections[0]); |
+ DCHECK_GE(vertex_before[1], start1); |
for (size_t i = start1; i <= vertex_before[1]; i++) { |
out_points[0].push_back(points_[i]); |
--points_remaining; |
@@ -306,6 +316,9 @@ bool DrawPolygon::Split(const DrawPolygon& splitter, |
scoped_ptr<DrawPolygon> poly2( |
new DrawPolygon(original_ref_, out_points[1], normal_, order_index_)); |
+ DCHECK_GE(poly1->points().size(), 3u); |
+ DCHECK_GE(poly2->points().size(), 3u); |
+ |
if (SideCompare(*poly1, splitter) == BSP_FRONT) { |
*front = poly1.Pass(); |
*back = poly2.Pass(); |