Convert Math::Align to a template, so it doesn't depend on the uint32 type

Signed-off-by: Chris Burel <burelc@amazon.com>
This commit is contained in:
Chris Burel
2021-05-24 12:03:57 -07:00
parent 24fa61f59e
commit 5a4b0f5770
4 changed files with 26 additions and 52 deletions
@@ -918,8 +918,8 @@ namespace EMStudio
{
if (mIsCollapsed == false)
{
uint32 numPorts = MCore::Max<uint32>(mInputPorts.size(), mOutputPorts.size());
uint32 result = (numPorts * 15) + 34;
int32 numPorts = aznumeric_caster(AZStd::max(mInputPorts.size(), mOutputPorts.size()));
int32 result = (numPorts * 15) + 34;
return MCore::Math::Align(result, 10);
}
else
@@ -930,33 +930,26 @@ namespace EMStudio
// calc the max input port width
uint32 GraphNode::CalcMaxInputPortWidth() const
int GraphNode::CalcMaxInputPortWidth() const
{
// calc the maximum input port width
uint32 maxInputWidth = 0;
uint32 width;
const uint32 numInputPorts = mInputPorts.size();
for (uint32 i = 0; i < numInputPorts; ++i)
int maxInputWidth = 0;
for (const NodePort& nodePort : mInputPorts)
{
const NodePort* nodePort = &mInputPorts[i];
width = mPortFontMetrics->horizontalAdvance(nodePort->GetName());
maxInputWidth = MCore::Max<uint32>(maxInputWidth, width);
maxInputWidth = AZStd::max(maxInputWidth, mPortFontMetrics->horizontalAdvance(nodePort.GetName()));
}
return maxInputWidth;
}
// calculate the max output port width
uint32 GraphNode::CalcMaxOutputPortWidth() const
int GraphNode::CalcMaxOutputPortWidth() const
{
// calc the maximum output port width
uint32 width;
uint32 maxOutputWidth = 0;
const uint32 numOutputPorts = mOutputPorts.size();
for (uint32 i = 0; i < numOutputPorts; ++i)
int maxOutputWidth = 0;
for (const NodePort& nodePort : mOutputPorts)
{
width = mPortFontMetrics->horizontalAdvance(mOutputPorts[i].GetName());
maxOutputWidth = MCore::Max<uint32>(maxOutputWidth, width);
maxOutputWidth = AZStd::max(maxOutputWidth, mPortFontMetrics->horizontalAdvance(nodePort.GetName()));
}
return maxOutputWidth;
@@ -974,18 +967,17 @@ namespace EMStudio
mMaxInputWidth = CalcMaxInputPortWidth();
mMaxOutputWidth = CalcMaxOutputPortWidth();
const uint32 infoWidth = mInfoFontMetrics->horizontalAdvance(mElidedNodeInfo);
const uint32 totalPortWidth = mMaxInputWidth + mMaxOutputWidth + 40 + infoWidth;
const int infoWidth = mInfoFontMetrics->horizontalAdvance(mElidedNodeInfo);
const int totalPortWidth = mMaxInputWidth + mMaxOutputWidth + 40 + infoWidth;
// make sure the node is at least 100 units in width
uint32 headerWidth = mHeaderFontMetrics->horizontalAdvance(mElidedName) + 40;
headerWidth = MCore::Max<uint32>(headerWidth, 100);
mRequiredWidth = MCore::Max<uint32>(headerWidth, totalPortWidth);
mNameAndPortsUpdated = true;
const int headerWidth = AZStd::max(mHeaderFontMetrics->horizontalAdvance(mElidedName) + 40, 100);
mRequiredWidth = AZStd::max(headerWidth, totalPortWidth);
mRequiredWidth = MCore::Math::Align(mRequiredWidth, 10);
mNameAndPortsUpdated = true;
return mRequiredWidth;
}
@@ -150,8 +150,8 @@ namespace EMStudio
virtual int32 CalcRequiredHeight() const;
virtual int32 CalcRequiredWidth();
virtual uint32 CalcMaxInputPortWidth() const;
virtual uint32 CalcMaxOutputPortWidth() const;
virtual int CalcMaxInputPortWidth() const;
virtual int CalcMaxOutputPortWidth() const;
bool GetIsInside(const QPoint& globalPoint) const;
bool GetIsSelected() const;
@@ -273,8 +273,8 @@ namespace EMStudio
bool mHasVisualGraph;
bool mHasVisualOutputPorts;
uint32 mMaxInputWidth; // will be calculated automatically in CalcRequiredWidth()
uint32 mMaxOutputWidth; // will be calculated automatically in CalcRequiredWidth()
int mMaxInputWidth; // will be calculated automatically in CalcRequiredWidth()
int mMaxOutputWidth; // will be calculated automatically in CalcRequiredWidth()
// has child node indicator
QPolygonF mSubstPoly;
+3 -12
View File
@@ -300,24 +300,15 @@ namespace MCore
static MCORE_INLINE float SafeFMod(float x, float y);
/**
* Align a given uint32 value to a given alignment.
* For example when the input value of inOutValue contains a value of 50, and the alignment is set to 16, then the
* value is modified to be 64.
* @param inOutValue The input value to align. This will also be the output, so the value is modified.
* @param alignment The alignment to use, for example 16, 32 or 64, etc.
*/
static MCORE_INLINE void Align(uint32* inOutValue, uint32 alignment);
/**
* Align a given uint32 value to a given alignment.
* Align a given size_t value to a given alignment.
* For example when the input value of inOutValue contains a value of 50, and the alignment is set to 16, then the
* aligned return value would be 64.
* @param inValue The input value, which would be 50 in our above example.
* @param alignment The alignment touse, which would be 16 in our above example.
* @result The value returned is the input value aligned to the given alignment. In our example it would return a value of 64.
*/
static MCORE_INLINE uint32 Align(uint32 inValue, uint32 alignment);
template<typename T>
static MCORE_INLINE T Align(T inValue, T alignment);
/**
* Multiply a float value by its sign.
+3 -12
View File
@@ -310,19 +310,10 @@ MCORE_INLINE float Math::FastSqrt(float x)
// align a value
MCORE_INLINE void Math::Align(uint32* inOutValue, uint32 alignment)
template<typename T>
MCORE_INLINE T Math::Align(T inValue, T alignment)
{
const uint32 modValue = *inOutValue % alignment;
if (modValue > 0)
{
*inOutValue += alignment - modValue;
}
}
// align a value
MCORE_INLINE uint32 Math::Align(uint32 inValue, uint32 alignment)
{
const uint32 modValue = inValue % alignment;
const T modValue = inValue % alignment;
if (modValue > 0)
{
return inValue + (alignment - modValue);