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

51 lines
1.2 KiB
C

1 month ago
/*------------------------------------------------------------------------------
* Copyright (c) 2023 by Bai Bing (seread@163.com)
* See COPYING file for copying and redistribution conditions.
*
* Alians IT Studio.
*----------------------------------------------------------------------------*/
#pragma once
#include "_Define.h"
#include "ASPoint.h"
namespace ais
{
template <class PT = Point>
class AIS_EXPORT Edge
{
public:
PT points[2];
size_t hash{0};
Edge() = default;
Edge(const PT &p0, const PT &p1)
{
points[0] = p0;
points[1] = p1;
get_hash();
}
inline size_t get_hash()
{
if (hash != 0)
return hash;
bool flag = points[0] < points[1];
auto h0 = flag ? points[0].hash() : points[1].hash();
auto h1 = flag ? points[1].hash() : points[0].hash();
hash = h0 ^ (h1 << 1);
return hash;
}
bool operator==(const Edge<PT> &rhs) const
{
return (points[0] == rhs.points[0] && points[1] == rhs.points[1]) ||
(points[0] == rhs.points[1] && points[1] == rhs.points[0]);
}
};
} // namespace ais