mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-04 02:02:41 +08:00
Remove some format rule (#10919)
* remove some rules * format all codes with new format rule
This commit is contained in:
@@ -2,34 +2,29 @@
|
||||
#include "BoundingBoxData.h"
|
||||
#include "DisplayData.h"
|
||||
|
||||
|
||||
DRAGONBONES_NAMESPACE_BEGIN
|
||||
|
||||
void BoundingBoxData::_onClear()
|
||||
{
|
||||
void BoundingBoxData::_onClear() {
|
||||
color = 0x000000;
|
||||
width = 0.0f;
|
||||
height = 0.0f;
|
||||
}
|
||||
|
||||
int RectangleBoundingBoxData::_computeOutCode(float x, float y, float xMin, float yMin, float xMax, float yMax)
|
||||
{
|
||||
int code = OutCode::InSide; // initialised as being inside of [[clip window]]
|
||||
int RectangleBoundingBoxData::_computeOutCode(float x, float y, float xMin, float yMin, float xMax, float yMax) {
|
||||
int code = OutCode::InSide; // initialised as being inside of [[clip window]]
|
||||
|
||||
if (x < xMin) // to the left of clip window
|
||||
if (x < xMin) // to the left of clip window
|
||||
{
|
||||
code |= OutCode::Left;
|
||||
}
|
||||
else if (x > xMax) // to the right of clip window
|
||||
} else if (x > xMax) // to the right of clip window
|
||||
{
|
||||
code |= OutCode::Right;
|
||||
}
|
||||
|
||||
if (y < yMin) // below the clip window
|
||||
if (y < yMin) // below the clip window
|
||||
{
|
||||
code |= OutCode::Top;
|
||||
}
|
||||
else if (y > yMax) // above the clip window
|
||||
} else if (y > yMax) // above the clip window
|
||||
{
|
||||
code |= OutCode::Bottom;
|
||||
}
|
||||
@@ -42,14 +37,11 @@ int RectangleBoundingBoxData::rectangleIntersectsSegment(
|
||||
float xMin, float yMin, float xMax, float yMax,
|
||||
Point* intersectionPointA,
|
||||
Point* intersectionPointB,
|
||||
Point* normalRadians
|
||||
)
|
||||
{
|
||||
Point* normalRadians) {
|
||||
const auto inSideA = xA > xMin && xA < xMax && yA > yMin && yA < yMax;
|
||||
const auto inSideB = xB > xMin && xB < xMax && yB > yMin && yB < yMax;
|
||||
|
||||
if (inSideA && inSideB)
|
||||
{
|
||||
if (inSideA && inSideB) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -57,14 +49,12 @@ int RectangleBoundingBoxData::rectangleIntersectsSegment(
|
||||
auto outcode0 = RectangleBoundingBoxData::_computeOutCode(xA, yA, xMin, yMin, xMax, yMax);
|
||||
auto outcode1 = RectangleBoundingBoxData::_computeOutCode(xB, yB, xMin, yMin, xMax, yMax);
|
||||
|
||||
while (true)
|
||||
{
|
||||
while (true) {
|
||||
if ((outcode0 | outcode1) == 0) // Bitwise OR is 0. Trivially accept and get out of loop
|
||||
{
|
||||
intersectionCount = 2;
|
||||
break;
|
||||
}
|
||||
else if ((outcode0 & outcode1) != 0) // Bitwise AND is not 0. Trivially reject and get out of loop
|
||||
} else if ((outcode0 & outcode1) != 0) // Bitwise AND is not 0. Trivially reject and get out of loop
|
||||
{
|
||||
break;
|
||||
}
|
||||
@@ -79,128 +69,102 @@ int RectangleBoundingBoxData::rectangleIntersectsSegment(
|
||||
const auto outcodeOut = outcode0 != 0 ? outcode0 : outcode1;
|
||||
|
||||
// Now find the intersection point;
|
||||
if ((outcodeOut & OutCode::Top) != 0) // point is above the clip rectangle
|
||||
if ((outcodeOut & OutCode::Top) != 0) // point is above the clip rectangle
|
||||
{
|
||||
x = xA + (xB - xA) * (yMin - yA) / (yB - yA);
|
||||
y = yMin;
|
||||
|
||||
if (normalRadians != nullptr)
|
||||
{
|
||||
if (normalRadians != nullptr) {
|
||||
normalRadian = -Transform::PI * 0.5f;
|
||||
}
|
||||
}
|
||||
else if ((outcodeOut & OutCode::Bottom) != 0) // point is below the clip rectangle
|
||||
} else if ((outcodeOut & OutCode::Bottom) != 0) // point is below the clip rectangle
|
||||
{
|
||||
x = xA + (xB - xA) * (yMax - yA) / (yB - yA);
|
||||
y = yMax;
|
||||
|
||||
if (normalRadians != nullptr)
|
||||
{
|
||||
if (normalRadians != nullptr) {
|
||||
normalRadian = Transform::PI * 0.5;
|
||||
}
|
||||
}
|
||||
else if ((outcodeOut & OutCode::Right) != 0) // point is to the right of clip rectangle
|
||||
} else if ((outcodeOut & OutCode::Right) != 0) // point is to the right of clip rectangle
|
||||
{
|
||||
y = yA + (yB - yA) * (xMax - xA) / (xB - xA);
|
||||
x = xMax;
|
||||
|
||||
if (normalRadians != nullptr)
|
||||
{
|
||||
if (normalRadians != nullptr) {
|
||||
normalRadian = 0;
|
||||
}
|
||||
}
|
||||
else if ((outcodeOut & OutCode::Left) != 0) // point is to the left of clip rectangle
|
||||
} else if ((outcodeOut & OutCode::Left) != 0) // point is to the left of clip rectangle
|
||||
{
|
||||
y = yA + (yB - yA) * (xMin - xA) / (xB - xA);
|
||||
x = xMin;
|
||||
|
||||
if (normalRadians != nullptr)
|
||||
{
|
||||
if (normalRadians != nullptr) {
|
||||
normalRadian = Transform::PI;
|
||||
}
|
||||
}
|
||||
|
||||
// Now we move outside point to intersection point to clip
|
||||
// and get ready for next pass.
|
||||
if (outcodeOut == outcode0)
|
||||
{
|
||||
if (outcodeOut == outcode0) {
|
||||
xA = x;
|
||||
yA = y;
|
||||
outcode0 = RectangleBoundingBoxData::_computeOutCode(xA, yA, xMin, yMin, xMax, yMax);
|
||||
|
||||
if (normalRadians != nullptr)
|
||||
{
|
||||
if (normalRadians != nullptr) {
|
||||
normalRadians->x = normalRadian;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
xB = x;
|
||||
yB = y;
|
||||
outcode1 = RectangleBoundingBoxData::_computeOutCode(xB, yB, xMin, yMin, xMax, yMax);
|
||||
|
||||
if (normalRadians != nullptr)
|
||||
{
|
||||
if (normalRadians != nullptr) {
|
||||
normalRadians->y = normalRadian;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (intersectionCount)
|
||||
{
|
||||
if (inSideA)
|
||||
{
|
||||
if (intersectionCount) {
|
||||
if (inSideA) {
|
||||
intersectionCount = 2; // 10
|
||||
|
||||
if (intersectionPointA != nullptr)
|
||||
{
|
||||
if (intersectionPointA != nullptr) {
|
||||
intersectionPointA->x = xB;
|
||||
intersectionPointA->y = yB;
|
||||
}
|
||||
|
||||
if (intersectionPointB != nullptr)
|
||||
{
|
||||
if (intersectionPointB != nullptr) {
|
||||
intersectionPointB->x = xB;
|
||||
intersectionPointB->y = xB;
|
||||
}
|
||||
|
||||
if (normalRadians != nullptr)
|
||||
{
|
||||
if (normalRadians != nullptr) {
|
||||
normalRadians->x = normalRadians->y + Transform::PI;
|
||||
}
|
||||
}
|
||||
else if (inSideB)
|
||||
{
|
||||
} else if (inSideB) {
|
||||
intersectionCount = 1; // 01
|
||||
|
||||
if (intersectionPointA != nullptr)
|
||||
{
|
||||
if (intersectionPointA != nullptr) {
|
||||
intersectionPointA->x = xA;
|
||||
intersectionPointA->y = yA;
|
||||
}
|
||||
|
||||
if (intersectionPointB != nullptr)
|
||||
{
|
||||
if (intersectionPointB != nullptr) {
|
||||
intersectionPointB->x = xA;
|
||||
intersectionPointB->y = yA;
|
||||
}
|
||||
|
||||
if (normalRadians != nullptr)
|
||||
{
|
||||
if (normalRadians != nullptr) {
|
||||
normalRadians->y = normalRadians->x + Transform::PI;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
intersectionCount = 3; // 11
|
||||
if (intersectionPointA != nullptr)
|
||||
{
|
||||
if (intersectionPointA != nullptr) {
|
||||
intersectionPointA->x = xA;
|
||||
intersectionPointA->y = yA;
|
||||
}
|
||||
|
||||
if (intersectionPointB != nullptr)
|
||||
{
|
||||
if (intersectionPointB != nullptr) {
|
||||
intersectionPointB->x = xB;
|
||||
intersectionPointB->y = yB;
|
||||
}
|
||||
@@ -210,21 +174,17 @@ int RectangleBoundingBoxData::rectangleIntersectsSegment(
|
||||
return intersectionCount;
|
||||
}
|
||||
|
||||
void RectangleBoundingBoxData::_onClear()
|
||||
{
|
||||
void RectangleBoundingBoxData::_onClear() {
|
||||
BoundingBoxData::_onClear();
|
||||
|
||||
type = BoundingBoxType::Rectangle;
|
||||
}
|
||||
|
||||
bool RectangleBoundingBoxData::containsPoint(float pX, float pY)
|
||||
{
|
||||
bool RectangleBoundingBoxData::containsPoint(float pX, float pY) {
|
||||
const auto widthH = width * 0.5f;
|
||||
if (pX >= -widthH && pX <= widthH)
|
||||
{
|
||||
if (pX >= -widthH && pX <= widthH) {
|
||||
const auto heightH = height * 0.5f;
|
||||
if (pY >= -heightH && pY <= heightH)
|
||||
{
|
||||
if (pY >= -heightH && pY <= heightH) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -236,16 +196,13 @@ int RectangleBoundingBoxData::intersectsSegment(
|
||||
float xA, float yA, float xB, float yB,
|
||||
Point* intersectionPointA,
|
||||
Point* intersectionPointB,
|
||||
Point* normalRadians
|
||||
)
|
||||
{
|
||||
Point* normalRadians) {
|
||||
const auto widthH = width * 0.5f;
|
||||
const auto heightH = height * 0.5f;
|
||||
const auto intersectionCount = RectangleBoundingBoxData::rectangleIntersectsSegment(
|
||||
xA, yA, xB, yB,
|
||||
-widthH, -heightH, widthH, heightH,
|
||||
intersectionPointA, intersectionPointB, normalRadians
|
||||
);
|
||||
intersectionPointA, intersectionPointB, normalRadians);
|
||||
|
||||
return intersectionCount;
|
||||
}
|
||||
@@ -255,9 +212,7 @@ int EllipseBoundingBoxData::ellipseIntersectsSegment(
|
||||
float xC, float yC, float widthH, float heightH,
|
||||
Point* intersectionPointA,
|
||||
Point* intersectionPointB,
|
||||
Point* normalRadians
|
||||
)
|
||||
{
|
||||
Point* normalRadians) {
|
||||
const auto d = widthH / heightH;
|
||||
const auto dd = d * d;
|
||||
|
||||
@@ -276,8 +231,7 @@ int EllipseBoundingBoxData::ellipseIntersectsSegment(
|
||||
const auto dR = rr - ee + aa;
|
||||
auto intersectionCount = 0;
|
||||
|
||||
if (dR >= 0.0f)
|
||||
{
|
||||
if (dR >= 0.0f) {
|
||||
const auto dT = sqrt(dR);
|
||||
const auto sA = a - dT;
|
||||
const auto sB = a + dT;
|
||||
@@ -285,82 +239,64 @@ int EllipseBoundingBoxData::ellipseIntersectsSegment(
|
||||
const auto inSideB = sB < 0.0f ? -1 : (sB <= lAB ? 0 : 1);
|
||||
const auto sideAB = inSideA * inSideB;
|
||||
|
||||
if (sideAB < 0)
|
||||
{
|
||||
if (sideAB < 0) {
|
||||
return -1;
|
||||
}
|
||||
else if (sideAB == 0)
|
||||
{
|
||||
if (inSideA == -1)
|
||||
{
|
||||
} else if (sideAB == 0) {
|
||||
if (inSideA == -1) {
|
||||
intersectionCount = 2; // 10
|
||||
xB = xA + sB * xD;
|
||||
yB = (yA + sB * yD) / d;
|
||||
|
||||
if (intersectionPointA != nullptr)
|
||||
{
|
||||
if (intersectionPointA != nullptr) {
|
||||
intersectionPointA->x = xB;
|
||||
intersectionPointA->y = yB;
|
||||
}
|
||||
|
||||
if (intersectionPointB != nullptr)
|
||||
{
|
||||
if (intersectionPointB != nullptr) {
|
||||
intersectionPointB->x = xB;
|
||||
intersectionPointB->y = yB;
|
||||
}
|
||||
|
||||
if (normalRadians != nullptr)
|
||||
{
|
||||
if (normalRadians != nullptr) {
|
||||
normalRadians->x = atan2(yB / rr * dd, xB / rr);
|
||||
normalRadians->y = normalRadians->x + Transform::PI;
|
||||
}
|
||||
}
|
||||
else if (inSideB == 1)
|
||||
{
|
||||
} else if (inSideB == 1) {
|
||||
intersectionCount = 1; // 01
|
||||
xA = xA + sA * xD;
|
||||
yA = (yA + sA * yD) / d;
|
||||
|
||||
if (intersectionPointA != nullptr)
|
||||
{
|
||||
if (intersectionPointA != nullptr) {
|
||||
intersectionPointA->x = xA;
|
||||
intersectionPointA->y = yA;
|
||||
}
|
||||
|
||||
if (intersectionPointB != nullptr)
|
||||
{
|
||||
if (intersectionPointB != nullptr) {
|
||||
intersectionPointB->x = xA;
|
||||
intersectionPointB->y = yA;
|
||||
}
|
||||
|
||||
if (normalRadians != nullptr)
|
||||
{
|
||||
if (normalRadians != nullptr) {
|
||||
normalRadians->x = atan2(yA / rr * dd, xA / rr);
|
||||
normalRadians->y = normalRadians->x + Transform::PI;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
intersectionCount = 3; // 11
|
||||
|
||||
if (intersectionPointA != nullptr)
|
||||
{
|
||||
if (intersectionPointA != nullptr) {
|
||||
intersectionPointA->x = xA + sA * xD;
|
||||
intersectionPointA->y = (yA + sA * yD) / d;
|
||||
|
||||
if (normalRadians != nullptr)
|
||||
{
|
||||
if (normalRadians != nullptr) {
|
||||
normalRadians->x = atan2(intersectionPointA->y / rr * dd, intersectionPointA->x / rr);
|
||||
}
|
||||
}
|
||||
|
||||
if (intersectionPointB != nullptr)
|
||||
{
|
||||
if (intersectionPointB != nullptr) {
|
||||
intersectionPointB->x = xA + sB * xD;
|
||||
intersectionPointB->y = (yA + sB * yD) / d;
|
||||
|
||||
if (normalRadians != nullptr)
|
||||
{
|
||||
if (normalRadians != nullptr) {
|
||||
normalRadians->y = atan2(intersectionPointB->y / rr * dd, intersectionPointB->x / rr);
|
||||
}
|
||||
}
|
||||
@@ -379,14 +315,11 @@ void EllipseBoundingBoxData::_onClear()
|
||||
type = BoundingBoxType::Ellipse;
|
||||
}
|
||||
|
||||
bool EllipseBoundingBoxData::containsPoint(float pX, float pY)
|
||||
{
|
||||
bool EllipseBoundingBoxData::containsPoint(float pX, float pY) {
|
||||
const auto widthH = width * 0.5f;
|
||||
if (pX >= -widthH && pX <= widthH)
|
||||
{
|
||||
if (pX >= -widthH && pX <= widthH) {
|
||||
const auto heightH = height * 0.5f;
|
||||
if (pY >= -heightH && pY <= heightH)
|
||||
{
|
||||
if (pY >= -heightH && pY <= heightH) {
|
||||
pY *= widthH / heightH;
|
||||
return sqrt(pX * pX + pY * pY) <= widthH;
|
||||
}
|
||||
@@ -399,14 +332,11 @@ int EllipseBoundingBoxData::intersectsSegment(
|
||||
float xA, float yA, float xB, float yB,
|
||||
Point* intersectionPointA,
|
||||
Point* intersectionPointB,
|
||||
Point* normalRadians
|
||||
)
|
||||
{
|
||||
Point* normalRadians) {
|
||||
const auto intersectionCount = EllipseBoundingBoxData::ellipseIntersectsSegment(
|
||||
xA, yA, xB, yB,
|
||||
0.0f, 0.0f, width * 0.5f, height * 0.5f,
|
||||
intersectionPointA, intersectionPointB, normalRadians
|
||||
);
|
||||
intersectionPointA, intersectionPointB, normalRadians);
|
||||
|
||||
return intersectionCount;
|
||||
}
|
||||
@@ -416,15 +346,12 @@ int PolygonBoundingBoxData::polygonIntersectsSegment(
|
||||
const std::vector<float>& vertices,
|
||||
Point* intersectionPointA,
|
||||
Point* intersectionPointB,
|
||||
Point* normalRadians)
|
||||
{
|
||||
if (xA == xB)
|
||||
{
|
||||
Point* normalRadians) {
|
||||
if (xA == xB) {
|
||||
xA = xB + 0.000001f;
|
||||
}
|
||||
|
||||
if (yA == yB)
|
||||
{
|
||||
if (yA == yB) {
|
||||
yA = yB + 0.000001f;
|
||||
}
|
||||
|
||||
@@ -442,18 +369,15 @@ int PolygonBoundingBoxData::polygonIntersectsSegment(
|
||||
auto xMax = 0.0f;
|
||||
auto yMax = 0.0f;
|
||||
|
||||
for (std::size_t i = 0; i < count; i += 2)
|
||||
{
|
||||
for (std::size_t i = 0; i < count; i += 2) {
|
||||
const auto xD = vertices[i];
|
||||
const auto yD = vertices[i + 1];
|
||||
|
||||
if (xC == xD)
|
||||
{
|
||||
if (xC == xD) {
|
||||
xC = xD + 0.000001f;
|
||||
}
|
||||
|
||||
if (yC == yD)
|
||||
{
|
||||
if (yC == yD) {
|
||||
yC = yD + 0.000001f;
|
||||
}
|
||||
|
||||
@@ -463,21 +387,16 @@ int PolygonBoundingBoxData::polygonIntersectsSegment(
|
||||
const auto ll = dXAB * dYCD - dYAB * dXCD;
|
||||
const auto x = (llAB * dXCD - dXAB * llCD) / ll;
|
||||
|
||||
if (((x >= xC && x <= xD) || (x >= xD && x <= xC)) && (dXAB == 0.0f || (x >= xA && x <= xB) || (x >= xB && x <= xA)))
|
||||
{
|
||||
if (((x >= xC && x <= xD) || (x >= xD && x <= xC)) && (dXAB == 0.0f || (x >= xA && x <= xB) || (x >= xB && x <= xA))) {
|
||||
const auto y = (llAB * dYCD - dYAB * llCD) / ll;
|
||||
if (((y >= yC && y <= yD) || (y >= yD && y <= yC)) && (dYAB == 0.0f || (y >= yA && y <= yB) || (y >= yB && y <= yA)))
|
||||
{
|
||||
if (intersectionPointB != nullptr)
|
||||
{
|
||||
if (((y >= yC && y <= yD) || (y >= yD && y <= yC)) && (dYAB == 0.0f || (y >= yA && y <= yB) || (y >= yB && y <= yA))) {
|
||||
if (intersectionPointB != nullptr) {
|
||||
float d = x - xA;
|
||||
if (d < 0.0f)
|
||||
{
|
||||
if (d < 0.0f) {
|
||||
d = -d;
|
||||
}
|
||||
|
||||
if (intersectionCount == 0)
|
||||
{
|
||||
if (intersectionCount == 0) {
|
||||
dMin = d;
|
||||
dMax = d;
|
||||
xMin = x;
|
||||
@@ -485,28 +404,22 @@ int PolygonBoundingBoxData::polygonIntersectsSegment(
|
||||
xMax = x;
|
||||
yMax = y;
|
||||
|
||||
if (normalRadians != nullptr)
|
||||
{
|
||||
if (normalRadians != nullptr) {
|
||||
normalRadians->x = atan2(yD - yC, xD - xC) - Transform::PI * 0.5f;
|
||||
normalRadians->y = normalRadians->x;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (d < dMin)
|
||||
{
|
||||
} else {
|
||||
if (d < dMin) {
|
||||
dMin = d;
|
||||
xMin = x;
|
||||
yMin = y;
|
||||
|
||||
if (normalRadians != nullptr)
|
||||
{
|
||||
if (normalRadians != nullptr) {
|
||||
normalRadians->x = atan2(yD - yC, xD - xC) - Transform::PI * 0.5f;
|
||||
}
|
||||
}
|
||||
|
||||
if (d > dMax)
|
||||
{
|
||||
if (d > dMax) {
|
||||
dMax = d;
|
||||
xMax = x;
|
||||
yMax = y;
|
||||
@@ -518,17 +431,14 @@ int PolygonBoundingBoxData::polygonIntersectsSegment(
|
||||
}
|
||||
|
||||
intersectionCount++;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
xMin = x;
|
||||
yMin = y;
|
||||
xMax = x;
|
||||
yMax = y;
|
||||
intersectionCount++;
|
||||
|
||||
if (normalRadians != nullptr)
|
||||
{
|
||||
if (normalRadians != nullptr) {
|
||||
normalRadians->x = atan2(yD - yC, xD - xC) - Transform::PI * 0.5f;
|
||||
normalRadians->y = normalRadians->x;
|
||||
}
|
||||
@@ -541,37 +451,29 @@ int PolygonBoundingBoxData::polygonIntersectsSegment(
|
||||
yC = yD;
|
||||
}
|
||||
|
||||
if (intersectionCount == 1)
|
||||
{
|
||||
if (intersectionPointA != nullptr)
|
||||
{
|
||||
if (intersectionCount == 1) {
|
||||
if (intersectionPointA != nullptr) {
|
||||
intersectionPointA->x = xMin;
|
||||
intersectionPointA->y = yMin;
|
||||
}
|
||||
|
||||
if (intersectionPointB != nullptr)
|
||||
{
|
||||
if (intersectionPointB != nullptr) {
|
||||
intersectionPointB->x = xMin;
|
||||
intersectionPointB->y = yMin;
|
||||
}
|
||||
|
||||
if (normalRadians != nullptr)
|
||||
{
|
||||
if (normalRadians != nullptr) {
|
||||
normalRadians->y = normalRadians->x + Transform::PI;
|
||||
}
|
||||
}
|
||||
else if (intersectionCount > 1)
|
||||
{
|
||||
} else if (intersectionCount > 1) {
|
||||
intersectionCount++;
|
||||
|
||||
if (intersectionPointA != nullptr)
|
||||
{
|
||||
if (intersectionPointA != nullptr) {
|
||||
intersectionPointA->x = xMin;
|
||||
intersectionPointA->y = yMin;
|
||||
}
|
||||
|
||||
if (intersectionPointB != nullptr)
|
||||
{
|
||||
if (intersectionPointB != nullptr) {
|
||||
intersectionPointB->x = xMax;
|
||||
intersectionPointB->y = yMax;
|
||||
}
|
||||
@@ -580,12 +482,10 @@ int PolygonBoundingBoxData::polygonIntersectsSegment(
|
||||
return intersectionCount;
|
||||
}
|
||||
|
||||
void PolygonBoundingBoxData::_onClear()
|
||||
{
|
||||
void PolygonBoundingBoxData::_onClear() {
|
||||
BoundingBoxData::_onClear();
|
||||
|
||||
if (weight != nullptr)
|
||||
{
|
||||
if (weight != nullptr) {
|
||||
weight->returnToPool();
|
||||
}
|
||||
|
||||
@@ -596,21 +496,16 @@ void PolygonBoundingBoxData::_onClear()
|
||||
weight = nullptr;
|
||||
}
|
||||
|
||||
bool PolygonBoundingBoxData::containsPoint(float pX, float pY)
|
||||
{
|
||||
bool PolygonBoundingBoxData::containsPoint(float pX, float pY) {
|
||||
auto isInSide = false;
|
||||
if (pX >= x && pX <= width && pY >= y && pY <= height)
|
||||
{
|
||||
for (std::size_t i = 0, l = vertices.size(), iP = l - 2; i < l; i += 2)
|
||||
{
|
||||
if (pX >= x && pX <= width && pY >= y && pY <= height) {
|
||||
for (std::size_t i = 0, l = vertices.size(), iP = l - 2; i < l; i += 2) {
|
||||
const auto yA = vertices[iP + 1];
|
||||
const auto yB = vertices[i + 1];
|
||||
if ((yB < pY && yA >= pY) || (yA < pY && yB >= pY))
|
||||
{
|
||||
if ((yB < pY && yA >= pY) || (yA < pY && yB >= pY)) {
|
||||
const auto xA = vertices[iP];
|
||||
const auto xB = vertices[i];
|
||||
if ((pY - yB) * (xA - xB) / (yA - yB) + xB < pX)
|
||||
{
|
||||
if ((pY - yB) * (xA - xB) / (yA - yB) + xB < pX) {
|
||||
isInSide = !isInSide;
|
||||
}
|
||||
}
|
||||
@@ -626,16 +521,13 @@ int PolygonBoundingBoxData::intersectsSegment(
|
||||
float xA, float yA, float xB, float yB,
|
||||
Point* intersectionPointA,
|
||||
Point* intersectionPointB,
|
||||
Point* normalRadians
|
||||
)
|
||||
{
|
||||
Point* normalRadians) {
|
||||
auto intersectionCount = 0;
|
||||
if (RectangleBoundingBoxData::rectangleIntersectsSegment(xA, yA, xB, yB, x, y, x + width, y + height, nullptr, nullptr, nullptr) != 0) {
|
||||
intersectionCount = PolygonBoundingBoxData::polygonIntersectsSegment(
|
||||
xA, yA, xB, yB,
|
||||
vertices,
|
||||
intersectionPointA, intersectionPointB, normalRadians
|
||||
);
|
||||
intersectionPointA, intersectionPointB, normalRadians);
|
||||
}
|
||||
|
||||
return intersectionCount;
|
||||
|
||||
Reference in New Issue
Block a user