michael@0: /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- 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 GFX_QUAD_H michael@0: #define GFX_QUAD_H michael@0: michael@0: #include "gfxTypes.h" michael@0: #include "gfxRect.h" michael@0: #include "gfxLineSegment.h" michael@0: #include michael@0: michael@0: struct gfxQuad { michael@0: gfxQuad(const gfxPoint& aOne, const gfxPoint& aTwo, const gfxPoint& aThree, const gfxPoint& aFour) michael@0: { michael@0: mPoints[0] = aOne; michael@0: mPoints[1] = aTwo; michael@0: mPoints[2] = aThree; michael@0: mPoints[3] = aFour; michael@0: } michael@0: michael@0: bool Contains(const gfxPoint& aPoint) michael@0: { michael@0: return (gfxLineSegment(mPoints[0], mPoints[1]).PointsOnSameSide(aPoint, mPoints[2]) && michael@0: gfxLineSegment(mPoints[1], mPoints[2]).PointsOnSameSide(aPoint, mPoints[3]) && michael@0: gfxLineSegment(mPoints[2], mPoints[3]).PointsOnSameSide(aPoint, mPoints[0]) && michael@0: gfxLineSegment(mPoints[3], mPoints[0]).PointsOnSameSide(aPoint, mPoints[1])); michael@0: } michael@0: michael@0: gfxRect GetBounds() michael@0: { michael@0: gfxFloat min_x, max_x; michael@0: gfxFloat min_y, max_y; michael@0: michael@0: min_x = max_x = mPoints[0].x; michael@0: min_y = max_y = mPoints[0].y; michael@0: michael@0: for (int i=1; i<4; i++) { michael@0: min_x = std::min(mPoints[i].x, min_x); michael@0: max_x = std::max(mPoints[i].x, max_x); michael@0: min_y = std::min(mPoints[i].y, min_y); michael@0: max_y = std::max(mPoints[i].y, max_y); michael@0: } michael@0: return gfxRect(min_x, min_y, max_x - min_x, max_y - min_y); michael@0: } michael@0: michael@0: gfxPoint mPoints[4]; michael@0: }; michael@0: michael@0: #endif /* GFX_QUAD_H */