You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

150 lines
2.7 KiB

#pragma once
#ifdef _WIN32
#ifdef WIREROUTINGDLL_EXPORTS // VisualStudio DLL 项目模板会将 <PROJECTNAME>_EXPORTS 添加到定义预处理器宏。
#define GEOMETRY_API __declspec(dllexport) // _WIN32
#else
#define GEOMETRY_API __declspec(dllimport)
#endif
#else
#define GEOMETRY_API
#endif
#include <numeric>
#include <limits>
#include <cmath>
#include <vector>
using namespace std;
template <typename T>
class Vec3
{
public:
T a, b, c;
Vec3(T x = T(), T y = T(), T z = T()) : a(x), b(y), c(z) {} // 修改后代码
T operator[](int i) const
{
if (i == 0)
{
return a;
}
else if (i == 1)
{
return b;
}
else if (i == 2)
{
return c;
}
return a;
}
T &operator[](int i)
{
if (i == 0)
{
return a;
}
else if (i == 1)
{
return b;
}
else if (i == 2)
{
return c;
}
return a;
}
Vec3 operator+(const Vec3 &other) const
{
return Vec3(a + other.a, b + other.b, c + other.c);
}
Vec3 operator/(const float w) const
{
return Vec3(a / w, b / w, c / w);
}
Vec3 operator-(const Vec3 &other) const
{
return Vec3(a - other.a, b - other.b, c - other.c);
}
Vec3 operator*(const float &w) const
{
return Vec3(a * w, b * w, c * w);
}
float length() const
{
return sqrt(a * a + b * b + c * c);
}
Vec3 norm() const
{
return *this / length();
}
Vec3 cross(const Vec3 &other) const
{
return Vec3(b * other.c - c * other.b, c * other.a - a * other.c, a * other.b - b * other.a);
}
float dot(const Vec3 &other) const
{
return a * other.a + b * other.b + c * other.c;
}
};
typedef Vec3<float> Vec3f;
typedef Vec3<unsigned int> Vec3u;
extern vector<Vec3f> GEOMETRY_API vertices;
extern vector<Vec3u> GEOMETRY_API indices;
class GEOMETRY_API Mesh
{
public:
std::vector<Vec3f> vertices;
std::vector<Vec3u> indices;
};
extern Mesh GEOMETRY_API mesh;
class GEOMETRY_API AABB
{
public:
Vec3f min, max;
AABB();
};
class GEOMETRY_API LineSegment
{
public:
Vec3f start;
Vec3f end;
float length;
Vec3f dir;
LineSegment(const Vec3f &s, const Vec3f &e);
float getLength() const;
Vec3f getDir() const;
void calculate();
};
struct GEOMETRY_API FaceCenterComparator
{
const vector<Vec3f> &faceCenters; // 替换 YourVectorType 为你的向量类型
int longAxis;
FaceCenterComparator(const vector<Vec3f> &centers, int axis);
bool operator()(const size_t &a, const size_t &b) const;
};