1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/thebes/gfxQuad.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,51 @@ 1.4 +/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- 1.5 + * This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#ifndef GFX_QUAD_H 1.10 +#define GFX_QUAD_H 1.11 + 1.12 +#include "gfxTypes.h" 1.13 +#include "gfxRect.h" 1.14 +#include "gfxLineSegment.h" 1.15 +#include <algorithm> 1.16 + 1.17 +struct gfxQuad { 1.18 + gfxQuad(const gfxPoint& aOne, const gfxPoint& aTwo, const gfxPoint& aThree, const gfxPoint& aFour) 1.19 + { 1.20 + mPoints[0] = aOne; 1.21 + mPoints[1] = aTwo; 1.22 + mPoints[2] = aThree; 1.23 + mPoints[3] = aFour; 1.24 + } 1.25 + 1.26 + bool Contains(const gfxPoint& aPoint) 1.27 + { 1.28 + return (gfxLineSegment(mPoints[0], mPoints[1]).PointsOnSameSide(aPoint, mPoints[2]) && 1.29 + gfxLineSegment(mPoints[1], mPoints[2]).PointsOnSameSide(aPoint, mPoints[3]) && 1.30 + gfxLineSegment(mPoints[2], mPoints[3]).PointsOnSameSide(aPoint, mPoints[0]) && 1.31 + gfxLineSegment(mPoints[3], mPoints[0]).PointsOnSameSide(aPoint, mPoints[1])); 1.32 + } 1.33 + 1.34 + gfxRect GetBounds() 1.35 + { 1.36 + gfxFloat min_x, max_x; 1.37 + gfxFloat min_y, max_y; 1.38 + 1.39 + min_x = max_x = mPoints[0].x; 1.40 + min_y = max_y = mPoints[0].y; 1.41 + 1.42 + for (int i=1; i<4; i++) { 1.43 + min_x = std::min(mPoints[i].x, min_x); 1.44 + max_x = std::max(mPoints[i].x, max_x); 1.45 + min_y = std::min(mPoints[i].y, min_y); 1.46 + max_y = std::max(mPoints[i].y, max_y); 1.47 + } 1.48 + return gfxRect(min_x, min_y, max_x - min_x, max_y - min_y); 1.49 + } 1.50 + 1.51 + gfxPoint mPoints[4]; 1.52 +}; 1.53 + 1.54 +#endif /* GFX_QUAD_H */