diff --git a/include/line.hpp b/include/line.hpp index 6819ead..357b51a 100644 --- a/include/line.hpp +++ b/include/line.hpp @@ -93,6 +93,8 @@ public: circularArcs[i].h = ABHalf.norm() * std::tan(theta * 0.5); circularArcs[i].center = A + ABHalf + QONorm * circularArcs[i].h; circularArcs[i].theta = theta; + Vec3 a; + a = ABHalf.cross(QONorm); circularArcs[i].radius = (circularArcs[i].center - A).norm(); circularArcs[i].u = (A - circularArcs[i].center).normalize(); circularArcs[i].v = ABNorm.cross(circularArcs[i].u); @@ -192,7 +194,7 @@ public: else printf("Open Polyline: \n"); printf("Points: {\n"); for (int i = 0; i < _points.size(); ++i) { - printf("<%lf, %lf, %lf>", _points[i].x, _points[i].y, _points[i].z); + printf("<%lf, %lf, %lf>", _points[i].x(), _points[i].y(), _points[i].z()); if (i != _points.size() - 1) printf(", "); } std::cout << "}" << std::endl; diff --git a/include/solid.hpp b/include/solid.hpp index e586614..460f03a 100644 --- a/include/solid.hpp +++ b/include/solid.hpp @@ -44,7 +44,7 @@ public: auto uv = get2DRepOf3DPt(QP, N, B, Q); // test it {} - _localProfile2D.emplace_back(uv.x, uv.y); + _localProfile2D.emplace_back(uv.x(), uv.y()); } } @@ -59,7 +59,7 @@ public: Vec3 QP = p - Q; auto uv = get2DRepOf3DPt(QP, N, B, Q); // test it - {} + // TODO: to test if uv is in _localProfile2D return 0; } }; diff --git a/include/vec.hpp b/include/vec.hpp index a50ae7c..b10d6c6 100644 --- a/include/vec.hpp +++ b/include/vec.hpp @@ -24,13 +24,12 @@ public: static_assert(sizeof...(args) == N, "Argument count must match vector size."); } - explicit VecBase(const Derived &v) { + explicit VecBase(const VecBase &v) { data = v.data; } - VecBase& operator=(const VecBase &v) { - if (this == &v) return *this; - data = v.data; + VecBase &operator=(VecBase v) { + *this = std::move(v); return *this; } @@ -106,53 +105,61 @@ public: } }; - // Vec<2> 特化 class Vec2 : public VecBase { public: - union { - struct { - real &x, &y; - }; - struct { - real &u, &v; - }; - struct { - real &a, &b; - }; - }; - - Vec2(real xVal, real yVal) : VecBase(xVal, yVal), x(data[0]), y(data[1]) {} - - Vec2() : VecBase(), x(data[0]), y(data[1]) {} - - Vec2(const Vec2 &v) : VecBase(v), x(data[0]), y(data[1]) {} + Vec2() : VecBase() {} + Vec2(real x, real y) : VecBase(x, y) {} + Vec2(const Vec2& v) : VecBase(v.x(), v.y()) {} + + Vec2 &operator=(const Vec2& v) { + data = v.data; + return *this; + } + + real& x() { return data[0]; } + real& y() { return data[1]; } + + const real& x() const { return data[0]; } + const real& y() const { return data[1]; } + + real& u() { return data[0]; } + real& v() { return data[1]; } + + const real& u() const { return data[0]; } + const real& v() const { return data[1]; } }; -// specialize template class Vec<3>; class Vec3 : public VecBase { public: - union { - struct { - real &x, &y, &z; - }; - struct { - real &u, &v, &w; - }; - struct { - real &a, &b, &c; - }; - }; - - Vec3() : VecBase(), x(data[0]), y(data[1]), z(data[2]) {} - - Vec3(real xVal, real yVal, real zVal) : VecBase(xVal, yVal, zVal), x(data[0]), y(data[1]), z(data[2]) {} - - Vec3(const Vec3 &vec) : VecBase(vec), x(data[0]), y(data[1]), z(data[2]) {} - - Vec3 cross(const Vec3 &v) const { - return {y * v.z - z * v.y, z * v.x - x * v.z, x * v.y - y * v.x}; + Vec3() : VecBase() {} + Vec3(real x, real y, real z) : VecBase(x, y, z) {} + Vec3(const Vec3& v) : VecBase(v.x(), v.y(), v.z()) {} + + Vec3 &operator=(const Vec3& v) { + data = v.data; + return *this; + } + + real& x() { return data[0]; } + real& y() { return data[1]; } + real& z() { return data[2]; } + + real x() const { return data[0]; } + real y() const { return data[1]; } + real z() const { return data[2]; } + + real& u() { return data[0]; } + real& v() { return data[1]; } + real& w() { return data[2]; } + + real u() const { return data[0]; } + real v() const { return data[1]; } + real w() const { return data[2]; } + + Vec3 cross(const Vec3& v) const { + return {y() * v.z() - z() * v.y(), z() * v.x() - x() * v.z(), x() * v.y() - y() * v.x()}; } };