michael@0: /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef MOZILLA_GFX_POINT_H_ michael@0: #define MOZILLA_GFX_POINT_H_ michael@0: michael@0: #include "mozilla/Attributes.h" michael@0: #include "Types.h" michael@0: #include "BasePoint.h" michael@0: #include "BasePoint3D.h" michael@0: #include "BasePoint4D.h" michael@0: #include "BaseSize.h" michael@0: michael@0: #include michael@0: michael@0: namespace mozilla { michael@0: namespace gfx { michael@0: michael@0: // This should only be used by the typedefs below. michael@0: struct UnknownUnits {}; michael@0: michael@0: template michael@0: struct IntPointTyped : michael@0: public BasePoint< int32_t, IntPointTyped >, michael@0: public units { michael@0: typedef BasePoint< int32_t, IntPointTyped > Super; michael@0: michael@0: MOZ_CONSTEXPR IntPointTyped() : Super() {} michael@0: MOZ_CONSTEXPR IntPointTyped(int32_t aX, int32_t aY) : Super(aX, aY) {} michael@0: michael@0: // XXX When all of the code is ported, the following functions to convert to and from michael@0: // unknown types should be removed. michael@0: michael@0: static IntPointTyped FromUnknownPoint(const IntPointTyped& aPoint) { michael@0: return IntPointTyped(aPoint.x, aPoint.y); michael@0: } michael@0: michael@0: IntPointTyped ToUnknownPoint() const { michael@0: return IntPointTyped(this->x, this->y); michael@0: } michael@0: }; michael@0: typedef IntPointTyped IntPoint; michael@0: michael@0: template michael@0: struct PointTyped : michael@0: public BasePoint< Float, PointTyped >, michael@0: public units { michael@0: typedef BasePoint< Float, PointTyped > Super; michael@0: michael@0: MOZ_CONSTEXPR PointTyped() : Super() {} michael@0: MOZ_CONSTEXPR PointTyped(Float aX, Float aY) : Super(aX, aY) {} michael@0: MOZ_CONSTEXPR PointTyped(const IntPointTyped& point) : Super(float(point.x), float(point.y)) {} michael@0: michael@0: // XXX When all of the code is ported, the following functions to convert to and from michael@0: // unknown types should be removed. michael@0: michael@0: static PointTyped FromUnknownPoint(const PointTyped& aPoint) { michael@0: return PointTyped(aPoint.x, aPoint.y); michael@0: } michael@0: michael@0: PointTyped ToUnknownPoint() const { michael@0: return PointTyped(this->x, this->y); michael@0: } michael@0: }; michael@0: typedef PointTyped Point; michael@0: michael@0: template michael@0: IntPointTyped RoundedToInt(const PointTyped& aPoint) { michael@0: return IntPointTyped(int32_t(floorf(aPoint.x + 0.5f)), michael@0: int32_t(floorf(aPoint.y + 0.5f))); michael@0: } michael@0: michael@0: template michael@0: struct Point3DTyped : michael@0: public BasePoint3D< Float, Point3DTyped > { michael@0: typedef BasePoint3D< Float, Point3DTyped > Super; michael@0: michael@0: Point3DTyped() : Super() {} michael@0: Point3DTyped(Float aX, Float aY, Float aZ) : Super(aX, aY, aZ) {} michael@0: michael@0: // XXX When all of the code is ported, the following functions to convert to and from michael@0: // unknown types should be removed. michael@0: michael@0: static Point3DTyped FromUnknownPoint(const Point3DTyped& aPoint) { michael@0: return Point3DTyped(aPoint.x, aPoint.y, aPoint.z); michael@0: } michael@0: michael@0: Point3DTyped ToUnknownPoint() const { michael@0: return Point3DTyped(this->x, this->y, this->z); michael@0: } michael@0: }; michael@0: typedef Point3DTyped Point3D; michael@0: michael@0: template michael@0: struct Point4DTyped : michael@0: public BasePoint4D< Float, Point4DTyped > { michael@0: typedef BasePoint4D< Float, Point4DTyped > Super; michael@0: michael@0: Point4DTyped() : Super() {} michael@0: Point4DTyped(Float aX, Float aY, Float aZ, Float aW) : Super(aX, aY, aZ, aW) {} michael@0: michael@0: // XXX When all of the code is ported, the following functions to convert to and from michael@0: // unknown types should be removed. michael@0: michael@0: static Point4DTyped FromUnknownPoint(const Point4DTyped& aPoint) { michael@0: return Point4DTyped(aPoint.x, aPoint.y, aPoint.z, aPoint.w); michael@0: } michael@0: michael@0: Point4DTyped ToUnknownPoint() const { michael@0: return Point4DTyped(this->x, this->y, this->z, this->w); michael@0: } michael@0: }; michael@0: typedef Point4DTyped Point4D; michael@0: michael@0: template michael@0: struct IntSizeTyped : michael@0: public BaseSize< int32_t, IntSizeTyped >, michael@0: public units { michael@0: typedef BaseSize< int32_t, IntSizeTyped > Super; michael@0: michael@0: MOZ_CONSTEXPR IntSizeTyped() : Super() {} michael@0: MOZ_CONSTEXPR IntSizeTyped(int32_t aWidth, int32_t aHeight) : Super(aWidth, aHeight) {} michael@0: michael@0: // XXX When all of the code is ported, the following functions to convert to and from michael@0: // unknown types should be removed. michael@0: michael@0: static IntSizeTyped FromUnknownSize(const IntSizeTyped& aSize) { michael@0: return IntSizeTyped(aSize.width, aSize.height); michael@0: } michael@0: michael@0: IntSizeTyped ToUnknownSize() const { michael@0: return IntSizeTyped(this->width, this->height); michael@0: } michael@0: }; michael@0: typedef IntSizeTyped IntSize; michael@0: michael@0: template michael@0: struct SizeTyped : michael@0: public BaseSize< Float, SizeTyped >, michael@0: public units { michael@0: typedef BaseSize< Float, SizeTyped > Super; michael@0: michael@0: MOZ_CONSTEXPR SizeTyped() : Super() {} michael@0: MOZ_CONSTEXPR SizeTyped(Float aWidth, Float aHeight) : Super(aWidth, aHeight) {} michael@0: explicit SizeTyped(const IntSizeTyped& size) : michael@0: Super(float(size.width), float(size.height)) {} michael@0: michael@0: // XXX When all of the code is ported, the following functions to convert to and from michael@0: // unknown types should be removed. michael@0: michael@0: static SizeTyped FromUnknownSize(const SizeTyped& aSize) { michael@0: return SizeTyped(aSize.width, aSize.height); michael@0: } michael@0: michael@0: SizeTyped ToUnknownSize() const { michael@0: return SizeTyped(this->width, this->height); michael@0: } michael@0: }; michael@0: typedef SizeTyped Size; michael@0: michael@0: template michael@0: IntSizeTyped RoundedToInt(const SizeTyped& aSize) { michael@0: return IntSizeTyped(int32_t(floorf(aSize.width + 0.5f)), michael@0: int32_t(floorf(aSize.height + 0.5f))); michael@0: } michael@0: michael@0: } michael@0: } michael@0: michael@0: #endif /* MOZILLA_GFX_POINT_H_ */