Skip to content

Commit

Permalink
[Base] Tools2D.h: a simplification and code style unification
Browse files Browse the repository at this point in the history
  • Loading branch information
donovaly committed Jul 3, 2022
1 parent 06edc2d commit 96cb9dc
Showing 1 changed file with 19 additions and 21 deletions.
40 changes: 19 additions & 21 deletions src/Base/Tools2D.h
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ inline Vector2d& Vector2d::operator-= (const Vector2d &v)

inline Vector2d Vector2d::operator* (double c) const
{
return Vector2d(c*x, c*y);
return Vector2d(c * x, c * y);
}

inline Vector2d& Vector2d::operator*= (double c)
Expand All @@ -276,17 +276,17 @@ inline Vector2d& Vector2d::operator*= (double c)

inline double Vector2d::operator* (const Vector2d &v) const
{
return x*v.x + y*v.y;
return x * v.x + y * v.y;
}

inline Vector2d operator* (double c, const Vector2d &v)
{
return Vector2d(c*v.x, c*v.y);
return Vector2d(c * v.x, c * v.y);
}

inline Vector2d Vector2d::operator/ (double c) const
{
return Vector2d(x/c, y/c);
return Vector2d(x / c, y / c);
}

inline Vector2d& Vector2d::operator/= (double c)
Expand All @@ -298,12 +298,12 @@ inline Vector2d& Vector2d::operator/= (double c)

inline bool Vector2d::IsNull(double tolerance) const
{
return x*x + y*y <= tolerance*tolerance;
return x * x + y * y <= tolerance * tolerance;
}

inline double Vector2d::Length() const
{
return sqrt(x*x + y*y);
return sqrt(x * x + y * y);
}

inline double Vector2d::Angle() const
Expand All @@ -313,7 +313,7 @@ inline double Vector2d::Angle() const

inline double Vector2d::Sqr() const
{
return x*x + y*y;
return x * x + y * y;
}

inline Vector2d& Vector2d::Set(double x, double y)
Expand All @@ -339,8 +339,8 @@ inline Vector2d& Vector2d::Scale(double factor)

inline Vector2d& Vector2d::Rotate(double angle)
{
decltype(x) tmp_x = x;
x = x*cos(angle) - y*sin(angle);
auto tmp_x = x;
x = x * cos(angle) - y * sin(angle);
y = tmp_x * sin(angle) + y * cos(angle);
return *this;
}
Expand All @@ -364,15 +364,15 @@ inline Vector2d Vector2d::Perpendicular(bool clockwise) const

inline Vector2d Vector2d::FromPolar(double r, double fi)
{
return Vector2d(r*cos(fi), r*sin(fi));
return Vector2d(r * cos(fi), r * sin(fi));
}

inline double Vector2d::Distance(const Vector2d& v) const
{
double dx = (x - v.x);
double dy = (y - v.y);

return sqrt(dx*dx + dy*dy);
return sqrt(dx * dx + dy * dy);
}

inline bool Vector2d::IsEqual(const Vector2d& v, double tolerance) const
Expand Down Expand Up @@ -415,7 +415,7 @@ inline bool Polygon2d::Delete (size_t ulNdx)
{
std::vector<Vector2d>::iterator it = _aclVct.begin();
std::advance(it, ulNdx);
_aclVct.erase ( it );
_aclVct.erase(it);
return true;
}

Expand Down Expand Up @@ -492,10 +492,10 @@ inline BoundBox2d::BoundBox2d (const BoundBox2d &rclBB)

inline BoundBox2d::BoundBox2d (double fX1, double fY1, double fX2, double fY2)
{
MinX = std::min<double>( fX1, fX2 );
MaxX = std::max<double>( fX1, fX2 );
MinY = std::min<double>( fY1, fY2 );
MaxY = std::max<double>( fY1, fY2 );
MinX = std::min<double>(fX1, fX2);
MaxX = std::max<double>(fX1, fX2);
MinY = std::min<double>(fY1, fY2);
MaxY = std::max<double>(fY1, fY2);
}

inline bool BoundBox2d::IsValid ()
Expand All @@ -505,8 +505,8 @@ inline bool BoundBox2d::IsValid ()

inline bool BoundBox2d::IsEqual(const BoundBox2d& b, double tolerance) const
{
return Vector2d(MinX,MinY).IsEqual(Vector2d(b.MinX,b.MinY), tolerance) &&
Vector2d(MaxX,MaxY).IsEqual(Vector2d(b.MaxX,b.MaxY), tolerance);
return Vector2d(MinX, MinY).IsEqual(Vector2d(b.MinX, b.MinY), tolerance) &&
Vector2d(MaxX, MaxY).IsEqual(Vector2d(b.MaxX, b.MaxY), tolerance);
}

inline BoundBox2d& BoundBox2d::operator= (const BoundBox2d& rclBB)
Expand Down Expand Up @@ -550,7 +550,7 @@ inline bool BoundBox2d::Contains(const Vector2d &v, double tolerance) const

inline Vector2d BoundBox2d::GetCenter() const
{
return Vector2d((MinX + MaxX)*0.5, (MinY + MaxY)*0.5);
return Vector2d((MinX + MaxX) * 0.5, (MinY + MaxY) * 0.5);
}

inline void BoundBox2d::SetVoid()
Expand All @@ -570,5 +570,3 @@ inline void BoundBox2d::Add(const Vector2d &v)
} // namespace Base

#endif // BASE_TOOLS2D_H


0 comments on commit 96cb9dc

Please sign in to comment.