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.
 
 

75 lines
2.3 KiB

#ifndef BUSBAR_TYPES_HPP
#define BUSBAR_TYPES_HPP
#include "point.hpp"
#include "vector3.hpp"
// 段类型枚举
enum class SegmentType {
BEGIN = 0,
STRAIGHT = 1,
FLAT_BEND = 2, // 竖直方向弯曲,法向改变
VERTICAL_BEND = 3, // 水平面内弯曲,法向不变
TWIST = 4, // 扭转,法向旋转90度
BEND_45 = 5,
END = 6
};
// 段的终点状态(搜索节点)
struct SegmentEndState {
Point position; // 终点位置
Vector3 normal; // 终点法向(厚度方向)
Vector3 tangent; // 终点切向(前进方向)
SegmentType last_type; // 刚完成的段类型
SegmentEndState(const Point& pos = Point(0, 0, 0),
const Vector3& n = Vector3(0, 0, 1),
const Vector3& t = Vector3(1, 0, 0),
SegmentType type = SegmentType::BEGIN)
: position(pos),
normal(n.normalized()),
tangent(t.normalized()),
last_type(type) {}
bool operator==(const SegmentEndState& other) const {
return position == other.position &&
(normal - other.normal).normSquared() < 0.01f &&
(tangent - other.tangent).normSquared() < 0.01f;
}
bool operator!=(const SegmentEndState& other) const {
return !(*this == other);
}
};
// Hash函数
namespace std {
template<>
struct hash<SegmentEndState> {
size_t operator()(const SegmentEndState& s) const {
size_t seed = std::hash<Point>()(s.position);
// Use 0.1 quantization to match operator== tolerance.
int nx = static_cast<int>(std::round(s.normal.x() * 10));
int ny = static_cast<int>(std::round(s.normal.y() * 10));
int nz = static_cast<int>(std::round(s.normal.z() * 10));
int tx = static_cast<int>(std::round(s.tangent.x() * 10));
int ty = static_cast<int>(std::round(s.tangent.y() * 10));
int tz = static_cast<int>(std::round(s.tangent.z() * 10));
auto hash_combine = [&seed](int v) {
seed ^= std::hash<int>()(v) + 0x9e3779b97f4a7c15ULL + (seed << 6) + (seed >> 2);
};
hash_combine(nx);
hash_combine(ny);
hash_combine(nz);
hash_combine(tx);
hash_combine(ty);
hash_combine(tz);
return seed;
}
};
}
#endif