mirror of
https://github.com/Bodmer/TFT_eSPI.git
synced 2024-09-21 10:27:11 +00:00
Change parameter passing to "by ref" for all structs.
This commit is contained in:
parent
a9b9bd69f1
commit
fb05bce211
@ -5,10 +5,10 @@ constexpr float HiAlphaThreshold = 1.0 - LoAlphaThreshold;
|
||||
|
||||
//--------------------------------------------------------------------------------
|
||||
// Calculates closest distance of point to a vector (with origin at 0,0)
|
||||
float TFT_eSPI::calcDistance(tFPoint *aPoint, tFPoint *aVector) {
|
||||
float lH = fmaxf(fminf((aPoint->X * aVector->X + aPoint->Y * aVector->Y) / (aVector->X * aVector->X + aVector->Y * aVector->Y), 1.0f), 0.0f);
|
||||
float lDx = aPoint->X - (aVector->X * lH);
|
||||
float lDy = aPoint->Y - (aVector->Y * lH);
|
||||
float TFT_eSPI::calcDistance(const tFPoint& aPoint, const tFPoint& aVector) {
|
||||
float lH = fmaxf(fminf((aPoint.X * aVector.X + aPoint.Y * aVector.Y) / (aVector.X * aVector.X + aVector.Y * aVector.Y), 1.0f), 0.0f);
|
||||
float lDx = aPoint.X - (aVector.X * lH);
|
||||
float lDy = aPoint.Y - (aVector.Y * lH);
|
||||
return sqrtf(lDx * lDx + lDy * lDy);
|
||||
}
|
||||
|
||||
@ -18,23 +18,23 @@ float TFT_eSPI::calcDistance(tFPoint *aPoint, tFPoint *aVector) {
|
||||
// 0: No intersection
|
||||
// 1: Intersection with ascending vector
|
||||
// -1: Intersection with descending vector
|
||||
int TFT_eSPI::checkIntersection(tFPoint *aPoint, tFPoint *aVector) {
|
||||
int TFT_eSPI::checkIntersection(const tFPoint& aPoint, const tFPoint& aVector) {
|
||||
// Detect intersection with vector to -inf
|
||||
bool lInter = false;
|
||||
int lResult = 0;
|
||||
if ((aVector->Y != 0) && (((aPoint->Y >= 0) && (aPoint->Y <= aVector->Y)) || ((aPoint->Y <= 0) && (aPoint->Y >= aVector->Y)))) {
|
||||
if ((aVector->X != 0) && (aPoint->X != 0)) {
|
||||
float lV = aVector->Y / aVector->X;
|
||||
float lP = aPoint->Y / aPoint->X;
|
||||
if (aPoint->X > 0)
|
||||
lInter = ((aVector->X < 0) || (fabsf(lP) <= fabsf(lV)));
|
||||
if ((aVector.Y != 0) && (((aPoint.Y >= 0) && (aPoint.Y <= aVector.Y)) || ((aPoint.Y <= 0) && (aPoint.Y >= aVector.Y)))) {
|
||||
if ((aVector.X != 0) && (aPoint.X != 0)) {
|
||||
float lV = aVector.Y / aVector.X;
|
||||
float lP = aPoint.Y / aPoint.X;
|
||||
if (aPoint.X > 0)
|
||||
lInter = ((aVector.X < 0) || (fabsf(lP) <= fabsf(lV)));
|
||||
else
|
||||
lInter = ((aVector->X < 0) && (fabsf(lP) >= fabsf(lV)));
|
||||
lInter = ((aVector.X < 0) && (fabsf(lP) >= fabsf(lV)));
|
||||
} else
|
||||
lInter = (aPoint->X >= aVector->X);
|
||||
lInter = (aPoint.X >= aVector.X);
|
||||
}
|
||||
if (lInter) {
|
||||
lResult = (aVector->Y >= 0) ? 1 : -1;
|
||||
lResult = (aVector.Y >= 0) ? 1 : -1;
|
||||
}
|
||||
// Serial.printf("%f, %f, %f, %f lV= %f lP= %f res= %d\r\n", aPoint.X, aPoint.Y, aVector.X, aVector.Y, lV, lP, lResult);
|
||||
return lResult;
|
||||
@ -42,19 +42,19 @@ int TFT_eSPI::checkIntersection(tFPoint *aPoint, tFPoint *aVector) {
|
||||
|
||||
//----------------------------------------------------
|
||||
// in degrees (0..360)
|
||||
void TFT_eSPI::rotatePoint(tFPoint *aPoint, float aAngle) {
|
||||
void TFT_eSPI::rotatePoint(tFPoint& aPoint, float aAngle) {
|
||||
float lAngle = aAngle * PI / 180;
|
||||
float lX = (aPoint->X * cos(lAngle)) - (aPoint->Y * sin(lAngle));
|
||||
float lY = (aPoint->X * sin(lAngle)) + (aPoint->Y * cos(lAngle));
|
||||
aPoint->X = lX;
|
||||
aPoint->Y = lY;
|
||||
float lX = (aPoint.X * cos(lAngle)) - (aPoint.Y * sin(lAngle));
|
||||
float lY = (aPoint.X * sin(lAngle)) + (aPoint.Y * cos(lAngle));
|
||||
aPoint.X = lX;
|
||||
aPoint.Y = lY;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------
|
||||
// Rotation in degrees (0..360)
|
||||
void TFT_eSPI::fillSmoothPolygon(const tFPoints aPoints, float aLineWidth, uint32_t aLineColor,
|
||||
void TFT_eSPI::fillSmoothPolygon(const tFPoints& aPoints, float aLineWidth, uint32_t aLineColor,
|
||||
uint32_t aFillColor,
|
||||
const tFPoint aOffset, float aRotationAngle, const tFPoint aRotationPoint,
|
||||
const tFPoint& aOffset, float aRotationAngle, const tFPoint& aRotationPoint,
|
||||
uint32_t aBackgroundColor) {
|
||||
|
||||
tFPoints lPoints = aPoints;
|
||||
@ -66,7 +66,7 @@ void TFT_eSPI::fillSmoothPolygon(const tFPoints aPoints, float aLineWidth, uint3
|
||||
// Rotate
|
||||
lP->X -= aRotationPoint.X;
|
||||
lP->Y -= aRotationPoint.Y;
|
||||
rotatePoint(lP, aRotationAngle);
|
||||
rotatePoint(*lP, aRotationAngle);
|
||||
// Move
|
||||
lP->X += aOffset.X + aRotationPoint.X;
|
||||
lP->Y += aOffset.Y + aRotationPoint.Y;
|
||||
@ -121,11 +121,11 @@ void TFT_eSPI::fillSmoothPolygon(const tFPoints aPoints, float aLineWidth, uint3
|
||||
lP = &lPoints[li + 1];
|
||||
tFPoint lPtemp = {lXp - lPa->X, lYp - lPa->Y};
|
||||
tFPoint lVtemp = {lP->X - lPa->X, lP->Y - lPa->Y};
|
||||
lDistance = fminf(lDistance, calcDistance(&lPtemp, &lVtemp));
|
||||
lDistance = fminf(lDistance, calcDistance(lPtemp, lVtemp));
|
||||
if (aFillColor != TFT_NO_COLOR) {
|
||||
// Check intersections only for non-horizontal vectors
|
||||
if (lVtemp.Y != 0)
|
||||
lIntersections[lIntersectionCount++] = checkIntersection(&lPtemp, &lVtemp);
|
||||
lIntersections[lIntersectionCount++] = checkIntersection(lPtemp, lVtemp);
|
||||
}
|
||||
lPa = lP;
|
||||
}
|
||||
@ -178,8 +178,8 @@ void TFT_eSPI::fillSmoothPolygon(const tFPoints aPoints, float aLineWidth, uint3
|
||||
|
||||
//--------------------------------------------------------------------------------
|
||||
// Rotation in degrees (0..360)
|
||||
void TFT_eSPI::drawSmoothPolygon(const tFPoints aPoints, float aLineWidth, uint32_t aLineColor,
|
||||
const tFPoint aOffset, float aRotationAngle, const tFPoint aRotationPoint,
|
||||
void TFT_eSPI::drawSmoothPolygon(const tFPoints& aPoints, float aLineWidth, uint32_t aLineColor,
|
||||
const tFPoint& aOffset, float aRotationAngle, const tFPoint& aRotationPoint,
|
||||
uint32_t aBackgroundColor) {
|
||||
|
||||
fillSmoothPolygon(aPoints, aLineWidth, aLineColor, TFT_NO_COLOR, aOffset, aRotationAngle, aRotationPoint, aBackgroundColor);
|
||||
|
@ -9,17 +9,17 @@ public:
|
||||
} tFPoint;
|
||||
typedef std::vector<tFPoint> tFPoints;
|
||||
|
||||
void rotatePoint(tFPoint *aPoint, float aAngle);
|
||||
void drawSmoothPolygon(const tFPoints aPoints, float aLineWidth, uint32_t aLineColor,
|
||||
const tFPoint aOffset = {0, 0}, float aRotationAngle = 0.0, const tFPoint aRotationPoint = {0, 0},
|
||||
void rotatePoint(tFPoint& aPoint, float aAngle);
|
||||
void drawSmoothPolygon(const tFPoints& aPoints, float aLineWidth, uint32_t aLineColor,
|
||||
const tFPoint& aOffset = {0, 0}, float aRotationAngle = 0.0, const tFPoint& aRotationPoint = {0, 0},
|
||||
uint32_t aBackgroundColor = TFT_NO_COLOR);
|
||||
void fillSmoothPolygon(const tFPoints aPoints, float aLineWidth, uint32_t aLineColor,
|
||||
void fillSmoothPolygon(const tFPoints& aPoints, float aLineWidth, uint32_t aLineColor,
|
||||
uint32_t aFillColor = TFT_NO_COLOR,
|
||||
const tFPoint aOffset = {0, 0}, float aRotationAngle = 0.0, const tFPoint aRotationPoint = {0, 0},
|
||||
const tFPoint& aOffset = {0, 0}, float aRotationAngle = 0.0, const tFPoint& aRotationPoint = {0, 0},
|
||||
uint32_t aBackgroundColor = TFT_NO_COLOR);
|
||||
|
||||
private:
|
||||
float calcDistance(tFPoint *aPoint, tFPoint *aVector);
|
||||
int checkIntersection(tFPoint *aPoint, tFPoint *aVector);
|
||||
float calcDistance(const tFPoint& aPoint, const tFPoint& aVector);
|
||||
int checkIntersection(const tFPoint& aPoint, const tFPoint& aVector);
|
||||
|
||||
//--------------------------------------------------------------------------------
|
||||
|
Loading…
Reference in New Issue
Block a user