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