/* -*- 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 "Types.h" #include "BasePoint.h" #include "BaseSize.h" #include namespace mozilla { namespace gfx { // This should only be used by the typedefs below. struct UnknownUnits {}; template struct IntPointTyped : public BasePoint< int32_t, IntPointTyped >, public units { typedef BasePoint< int32_t, IntPointTyped > Super; IntPointTyped() : Super() {} 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 { typedef BasePoint< Float, PointTyped > Super; PointTyped() : Super() {} PointTyped(Float aX, Float aY) : Super(aX, aY) {} 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 IntSizeTyped : public BaseSize< int32_t, IntSizeTyped >, public units { typedef BaseSize< int32_t, IntSizeTyped > Super; IntSizeTyped() : Super() {} 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 { typedef BaseSize< Float, SizeTyped > Super; SizeTyped() : Super() {} 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; } } #endif /* MOZILLA_GFX_POINT_H_ */