FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Performance optimization of the Vector class by ruevs · Pull Request #762 · solvespace/solvespace · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .cpp  (1) .h  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
46 changes: 46 additions & 0 deletions src/dsc.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,52 @@ inline bool Vector::Equals(Vector v, double tol) const {
return dv.MagSquared() < tol*tol;
}

inline Vector Vector::From(double x, double y, double z) {
return {x, y, z};
}

inline Vector Vector::Plus(Vector b) const {
return {x + b.x, y + b.y, z + b.z};
}

inline Vector Vector::Minus(Vector b) const {
return {x - b.x, y - b.y, z - b.z};
}

inline Vector Vector::Negated() const {
return {-x, -y, -z};
}

inline Vector Vector::Cross(Vector b) const {
return {-(z * b.y) + (y * b.z), (z * b.x) - (x * b.z), -(y * b.x) + (x * b.y)};
}

inline double Vector::Dot(Vector b) const {
return (x * b.x + y * b.y + z * b.z);
}

inline double Vector::MagSquared() const {
return x * x + y * y + z * z;
}

inline double Vector::Magnitude() const {
return sqrt(x * x + y * y + z * z);
}

inline Vector Vector::ScaledBy(const double v) const {
return {x * v, y * v, z * v};
}

inline void Vector::MakeMaxMin(Vector *maxv, Vector *minv) const {
maxv->x = max(maxv->x, x);
maxv->y = max(maxv->y, y);
maxv->z = max(maxv->z, z);

minv->x = min(minv->x, x);
minv->y = min(minv->y, y);
minv->z = min(minv->z, z);
}

struct VectorHash {
size_t operator()(const Vector &v) const;
};
Expand Down
78 changes: 0 additions & 78 deletions src/util.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -428,12 +428,6 @@ Quaternion Quaternion::Mirror() const {
}


Vector Vector::From(double x, double y, double z) {
Vector v;
v.x = x; v.y = y; v.z = z;
return v;
}

Vector Vector::From(hParam x, hParam y, hParam z) {
Vector v;
v.x = SK.GetParam(x)->val;
Expand All @@ -448,50 +442,6 @@ bool Vector::EqualsExactly(Vector v) const {
z == v.z);
}

Vector Vector::Plus(Vector b) const {
Vector r;

r.x = x + b.x;
r.y = y + b.y;
r.z = z + b.z;

return r;
}

Vector Vector::Minus(Vector b) const {
Vector r;

r.x = x - b.x;
r.y = y - b.y;
r.z = z - b.z;

return r;
}

Vector Vector::Negated() const {
Vector r;

r.x = -x;
r.y = -y;
r.z = -z;

return r;
}

Vector Vector::Cross(Vector b) const {
Vector r;

r.x = -(z*b.y) + (y*b.z);
r.y = (z*b.x) - (x*b.z);
r.z = -(y*b.x) + (x*b.y);

return r;
}

double Vector::Dot(Vector b) const {
return (x*b.x + y*b.y + z*b.z);
}

double Vector::DirectionCosineWith(Vector b) const {
Vector a = this->WithMagnitude(1);
b = b.WithMagnitude(1);
Expand Down Expand Up @@ -629,24 +579,6 @@ Vector Vector::ClosestPointOnLine(Vector p0, Vector dp) const {
return this->Plus(n.WithMagnitude(d));
}

double Vector::MagSquared() const {
return x*x + y*y + z*z;
}

double Vector::Magnitude() const {
return sqrt(x*x + y*y + z*z);
}

Vector Vector::ScaledBy(double v) const {
Vector r;

r.x = x * v;
r.y = y * v;
r.z = z * v;

return r;
}

Vector Vector::WithMagnitude(double v) const {
double m = Magnitude();
if(EXACT(m == 0)) {
Expand Down Expand Up @@ -729,16 +661,6 @@ Vector Vector::ClampWithin(double minv, double maxv) const {
return ret;
}

void Vector::MakeMaxMin(Vector *maxv, Vector *minv) const {
maxv->x = max(maxv->x, x);
maxv->y = max(maxv->y, y);
maxv->z = max(maxv->z, z);

minv->x = min(minv->x, x);
minv->y = min(minv->y, y);
minv->z = min(minv->z, z);
}

bool Vector::OutsideAndNotOn(Vector maxv, Vector minv) const {
return (x > maxv.x + LENGTH_EPS) || (x < minv.x - LENGTH_EPS) ||
(y > maxv.y + LENGTH_EPS) || (y < minv.y - LENGTH_EPS) ||
Expand Down

Back | FazBrowse Home | New Git URL