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.
 
 

66 lines
1.9 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 h1 = std::hash<Point>()(s.position);
// 法向和切向离散化
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));
size_t h2 = std::hash<int>()(nx + ny * 100 + nz * 10000);
size_t h3 = std::hash<int>()(tx);
return h1 ^ (h2 << 1) ^ (h3 << 2);
}
};
}
#endif