2018-11-30 22:52:05 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
2012-05-21 15:12:37 +04:00
|
|
|
* 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/. */
|
2011-10-07 01:22:18 +04:00
|
|
|
|
|
|
|
#ifndef GFX_QUAD_H
|
|
|
|
#define GFX_QUAD_H
|
|
|
|
|
|
|
|
#include "gfxTypes.h"
|
2013-08-23 21:22:49 +04:00
|
|
|
#include "gfxRect.h"
|
2011-10-15 00:45:01 +04:00
|
|
|
#include "gfxLineSegment.h"
|
2013-01-15 16:22:03 +04:00
|
|
|
#include <algorithm>
|
2011-10-07 01:22:18 +04:00
|
|
|
|
2013-05-30 01:59:24 +04:00
|
|
|
struct gfxQuad {
|
2011-10-07 01:22:18 +04:00
|
|
|
gfxQuad(const gfxPoint& aOne, const gfxPoint& aTwo, const gfxPoint& aThree,
|
|
|
|
const gfxPoint& aFour) {
|
|
|
|
mPoints[0] = aOne;
|
|
|
|
mPoints[1] = aTwo;
|
|
|
|
mPoints[2] = aThree;
|
|
|
|
mPoints[3] = aFour;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2012-02-14 20:17:19 +04:00
|
|
|
bool Contains(const gfxPoint& aPoint) {
|
2011-10-15 00:45:01 +04:00
|
|
|
return (gfxLineSegment(mPoints[0], mPoints[1])
|
|
|
|
.PointsOnSameSide(aPoint, mPoints[2]) &&
|
|
|
|
gfxLineSegment(mPoints[1], mPoints[2])
|
|
|
|
.PointsOnSameSide(aPoint, mPoints[3]) &&
|
|
|
|
gfxLineSegment(mPoints[2], mPoints[3])
|
|
|
|
.PointsOnSameSide(aPoint, mPoints[0]) &&
|
|
|
|
gfxLineSegment(mPoints[3], mPoints[0])
|
|
|
|
.PointsOnSameSide(aPoint, mPoints[1]));
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2011-10-15 00:45:01 +04:00
|
|
|
gfxRect GetBounds() {
|
|
|
|
gfxFloat min_x, max_x;
|
|
|
|
gfxFloat min_y, max_y;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2011-10-15 00:45:01 +04:00
|
|
|
min_x = max_x = mPoints[0].x;
|
|
|
|
min_y = max_y = mPoints[0].y;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2011-10-15 00:45:01 +04:00
|
|
|
for (int i = 1; i < 4; i++) {
|
2013-01-15 16:22:03 +04:00
|
|
|
min_x = std::min(mPoints[i].x, min_x);
|
|
|
|
max_x = std::max(mPoints[i].x, max_x);
|
|
|
|
min_y = std::min(mPoints[i].y, min_y);
|
|
|
|
max_y = std::max(mPoints[i].y, max_y);
|
2011-10-07 01:22:18 +04:00
|
|
|
}
|
2011-10-15 00:45:01 +04:00
|
|
|
return gfxRect(min_x, min_y, max_x - min_x, max_y - min_y);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2011-10-07 01:22:18 +04:00
|
|
|
|
2011-10-15 00:45:01 +04:00
|
|
|
gfxPoint mPoints[4];
|
2011-10-07 01:22:18 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* GFX_QUAD_H */
|