Skip to content

Commit

Permalink
Merge pull request rism-digital#3920 from brdvd/refactor/vrv
Browse files Browse the repository at this point in the history
A few vrv utility improvements
  • Loading branch information
lpugin authored Jan 27, 2025
2 parents 4adb291 + efbce82 commit 5392150
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 30 deletions.
16 changes: 11 additions & 5 deletions include/vrv/vrv.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ LogLevel StrToLogLevel(const std::string &level);
/**
* Utility for comparing doubles
*/
bool AreEqual(double dFirstVal, double dSecondVal);
bool ApproximatelyEqual(double firstVal, double secondVal);

/**
* Utility to check if the string is a valid integer for std::stoi
Expand Down Expand Up @@ -132,11 +132,17 @@ std::string FromCamelCase(const std::string &s);
*/
std::string ToCamelCase(const std::string &s);

/*
* Min / Max for data_DURATION (std::min/max not possible)
/**
* Min / Max for data_DURATION
*/
data_DURATION DurationMin(data_DURATION dur1, data_DURATION dur2);
data_DURATION DurationMax(data_DURATION dur1, data_DURATION dur2);
inline data_DURATION DurationMin(data_DURATION dur1, data_DURATION dur2)
{
return std::min(dur1, dur2);
}
inline data_DURATION DurationMax(data_DURATION dur1, data_DURATION dur2)
{
return std::max(dur1, dur2);
}

/**
*
Expand Down
4 changes: 2 additions & 2 deletions src/bboxdevicecontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ void BBoxDeviceContext::EndResumedGraphic(Object *object, View *view)

void BBoxDeviceContext::RotateGraphic(Point const &orig, double angle)
{
assert(AreEqual(m_rotationAngle, 0.0));
assert(ApproximatelyEqual(m_rotationAngle, 0.0));

m_rotationAngle = angle;
m_rotationOrigin = orig;
Expand Down Expand Up @@ -401,7 +401,7 @@ void BBoxDeviceContext::UpdateBB(int x1, int y1, int x2, int y2, char32_t glyph)
return;
}

if (!AreEqual(m_rotationAngle, 0.0)) {
if (!ApproximatelyEqual(m_rotationAngle, 0.0)) {
Point p1 = BoundingBox::CalcPositionAfterRotation(Point(x1, y1), DegToRad(m_rotationAngle), m_rotationOrigin);
Point p2 = BoundingBox::CalcPositionAfterRotation(Point(x2, y2), DegToRad(m_rotationAngle), m_rotationOrigin);
x1 = p1.x;
Expand Down
2 changes: 1 addition & 1 deletion src/horizontalaligner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -938,7 +938,7 @@ TimestampAttr *TimestampAligner::GetTimestampAtTime(double time)
assert(timestampAttr);

double alignmentTime = timestampAttr->GetActualDurPos();
if (AreEqual(alignmentTime, time)) {
if (ApproximatelyEqual(alignmentTime, time)) {
return timestampAttr;
}
// nothing found, do not go any further but keep the index
Expand Down
25 changes: 3 additions & 22 deletions src/vrv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,16 +178,7 @@ LogLevel StrToLogLevel(const std::string &level)

bool LogBufferContains(const std::string &s)
{
for (const std::string &logStr : logBuffer) {
if (logStr == s) return true;
}
return false;
}

bool Check(Object *object)
{
assert(object);
return (object != NULL);
return (std::find(logBuffer.cbegin(), logBuffer.cend(), s) != logBuffer.cend());
}

//----------------------------------------------------------------------------
Expand Down Expand Up @@ -227,9 +218,9 @@ std::string StringFormatVariable(const char *format, va_list arg)
return str;
}

bool AreEqual(double dFirstVal, double dSecondVal)
bool ApproximatelyEqual(double firstVal, double secondVal)
{
return std::fabs(dFirstVal - dSecondVal) < 1E-3;
return std::fabs(firstVal - secondVal) < 1E-3;
}

bool IsValidInteger(const std::string &value)
Expand Down Expand Up @@ -459,16 +450,6 @@ std::string ToCamelCase(const std::string &s)
return result;
}

data_DURATION DurationMin(data_DURATION dur1, data_DURATION dur2)
{
return (dur1 < dur2) ? dur1 : dur2;
}

data_DURATION DurationMax(data_DURATION dur1, data_DURATION dur2)
{
return (dur1 > dur2) ? dur1 : dur2;
}

//----------------------------------------------------------------------------
// Notation type checks
//----------------------------------------------------------------------------
Expand Down

0 comments on commit 5392150

Please sign in to comment.