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.

76 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