Bug 1274673 - Use binary space partitioning for sorting/drawing layers - Part 1: Add Point4D construction/conversion from/to Point3D draft
authorMiko Mynttinen <mikokm@gmail.com>
Mon, 21 Nov 2016 19:50:33 +0100
changeset 447639 31a7cd87166ed0b62832b32211bf6579f445b145
parent 447633 ad993783599ab2ede0cf931fdec02f4df40a7a6d
child 447640 0ad30c1d164ecb9de60d0b788451420c247188a4
child 447647 18ccb6d417b73dbf7e72054a03cbaf4d90d05273
push id38097
push userbmo:mikokm@gmail.com
push dateTue, 06 Dec 2016 23:25:04 +0000
bugs1274673
milestone53.0a1
Bug 1274673 - Use binary space partitioning for sorting/drawing layers - Part 1: Add Point4D construction/conversion from/to Point3D MozReview-Commit-ID: 2zvXkYcVV1A
gfx/2d/Point.h
--- a/gfx/2d/Point.h
+++ b/gfx/2d/Point.h
@@ -143,17 +143,17 @@ struct PointTyped :
 };
 typedef PointTyped<UnknownUnits> Point;
 typedef PointTyped<UnknownUnits, double> PointDouble;
 
 template<class units>
 IntPointTyped<units> RoundedToInt(const PointTyped<units>& aPoint) {
   return IntPointTyped<units>::Round(aPoint.x, aPoint.y);
 }
-  
+
 template<class units>
 IntPointTyped<units> TruncatedToInt(const PointTyped<units>& aPoint) {
   return IntPointTyped<units>::Truncate(aPoint.x, aPoint.y);
 }
 
 template<class units, class F = Float>
 struct Point3DTyped :
   public BasePoint3D< F, Point3DTyped<units, F> > {
@@ -213,29 +213,39 @@ struct Point4DTyped :
   static_assert(IsPixel<units>::value,
                 "'units' must be a coordinate system tag");
 
   typedef BasePoint4D< F, Point4DTyped<units, F> > Super;
 
   Point4DTyped() : Super() {}
   Point4DTyped(F aX, F aY, F aZ, F aW) : Super(aX, aY, aZ, aW) {}
 
+  explicit Point4DTyped(const Point3DTyped<units, F>& aPoint)
+    : Super(aPoint.x, aPoint.y, aPoint.z, 1) {}
+
   // XXX When all of the code is ported, the following functions to convert to and from
   // unknown types should be removed.
 
   static Point4DTyped<units, F> FromUnknownPoint(const Point4DTyped<UnknownUnits, F>& aPoint) {
     return Point4DTyped<units, F>(aPoint.x, aPoint.y, aPoint.z, aPoint.w);
   }
 
   Point4DTyped<UnknownUnits, F> ToUnknownPoint() const {
     return Point4DTyped<UnknownUnits, F>(this->x, this->y, this->z, this->w);
   }
 
-  PointTyped<units, F> As2DPoint() {
-    return PointTyped<units, F>(this->x / this->w, this->y / this->w);
+  PointTyped<units, F> As2DPoint() const {
+    return PointTyped<units, F>(this->x / this->w,
+                                this->y / this->w);
+  }
+
+  Point3DTyped<units, F> As3DPoint() const {
+    return Point3DTyped<units, F>(this->x / this->w,
+                                  this->y / this->w,
+                                  this->z / this->w);
   }
 };
 typedef Point4DTyped<UnknownUnits> Point4D;
 typedef Point4DTyped<UnknownUnits, double> PointDouble4D;
 
 template<class units>
 struct IntSizeTyped :
   public BaseSize< int32_t, IntSizeTyped<units> >,