153 lines
5.4 KiB
C++
153 lines
5.4 KiB
C++
#pragma once
|
|
#pragma once
|
|
#include <QDebug>
|
|
#include <QMap>
|
|
#include <QPainter>
|
|
#include <QQueue>
|
|
#include <QResizeEvent>
|
|
#include <QString>
|
|
#include <QTime>
|
|
#include <QTimer>
|
|
#include <QWidget>
|
|
#include <cstdint>
|
|
#include <iostream>
|
|
#include <memory>
|
|
// Q_DECL_IMPORT
|
|
#ifdef NDEBUG
|
|
#define ASSERT(condition, message) ((void)0) // 在发布模式下什么都不做
|
|
#else
|
|
#define ASSERT(condition, message) \
|
|
do { \
|
|
if (!(condition)) { \
|
|
std::cerr << "Assertion failed: " << message \
|
|
<< "\nFile: " << __FILE__ \
|
|
<< "\nLine: " << __LINE__ \
|
|
<< std::endl; \
|
|
throw std::runtime_error(message); \
|
|
} \
|
|
} \
|
|
while (0)
|
|
#endif
|
|
#if defined(buildLib)
|
|
#define LIB_DECL
|
|
#elif defined(buildDll)
|
|
#define LIB_DECL Q_DECL_EXPORT
|
|
#elif defined(buildExe)
|
|
#define LIB_DECL
|
|
#else
|
|
#define LIB_DECL
|
|
#endif
|
|
namespace YSG {
|
|
QVector<QRgb> get_turbo_color_gradient();
|
|
class Abs_Axis;
|
|
class Axis;
|
|
struct Render_Data;
|
|
struct Renderable;
|
|
class Abs_Plot;
|
|
class Plot;
|
|
// 注意这仅仅只是一个范围 这是一个向量,大小相反就反向画
|
|
struct LIB_DECL Range {
|
|
double origin;
|
|
double target;
|
|
double center() {
|
|
return (origin + target) / 2.0;
|
|
}
|
|
[[nodiscard]] double size() const {
|
|
return qAbs(target - origin);
|
|
}
|
|
[[nodiscard]] double length() const {
|
|
return target - origin;
|
|
}
|
|
[[nodiscard]] double middle() const {
|
|
return origin + (target - origin) / 2;
|
|
}
|
|
bool operator==(const Range& other) const {
|
|
return (origin == other.origin && target == other.target);
|
|
}
|
|
bool operator!=(const Range& other) const {
|
|
return !(*this == other);
|
|
}
|
|
[[nodiscard]] bool contain(double value) const {
|
|
if (origin < target) {
|
|
return value > origin - 0.0001 && value < target + 0.0001;
|
|
}
|
|
else {
|
|
return value > target - 0.0001 && value < origin + 0.0001;
|
|
}
|
|
}
|
|
};
|
|
QDebug operator<<(QDebug debug, const Range& range);
|
|
enum class LIB_DECL SRC : std::uint8_t {
|
|
Edit,
|
|
Ready,
|
|
Render
|
|
};
|
|
} // namespace YSG
|
|
#define PROP(Type, Name) \
|
|
Type Name(SRC src = SRC::Edit); \
|
|
void set_##Name(Type);
|
|
#define PROP_B(TYPE, FIELD) \
|
|
public: \
|
|
Builder& set_##FIELD(TYPE value) { \
|
|
this->FIELD = std::move(value); \
|
|
return *this; \
|
|
}
|
|
#define PROP_BT(TYPE, FIELD) \
|
|
public: \
|
|
That& set_##FIELD(TYPE value) { \
|
|
static_cast<That*>(this)->FIELD = std::move(value); \
|
|
return *static_cast<That*>(this); \
|
|
}
|
|
#define PROP_R(TYPE, FIELD) sc->FIELD = this->FIELD;
|
|
#define PROP_RT(TYPE, FIELD) sc->FIELD = static_cast<That*>(this)->FIELD;
|
|
#define SETTER_T(TYPE, FIELD, DEFAULT) \
|
|
private: \
|
|
TYPE FIELD = DEFAULT; \
|
|
public: \
|
|
That& set_##FIELD(TYPE value) { \
|
|
static_cast<That*>(this)->FIELD = value; \
|
|
return *static_cast<That*>(this); \
|
|
}
|
|
#define SETTER_2_RANGE_T(bits, FIELD, DEFAULT) \
|
|
private: \
|
|
int FIELD = DEFAULT; \
|
|
public: \
|
|
T& set_##FIELD(int value) { \
|
|
if (value < 0 || value >= (1 << bits)) { \
|
|
throw std::out_of_range("Value out of range: " #FIELD); \
|
|
} \
|
|
static_cast<T*>(this)->FIELD = value; \
|
|
return *static_cast<T*>(this); \
|
|
}
|
|
#define SETTER_RANGE_T(lower, upper, FIELD, DEFAULT) \
|
|
private: \
|
|
int FIELD = DEFAULT; \
|
|
public: \
|
|
Builder& set_##FIELD(int value) { \
|
|
if (value < lower || value > upper) { \
|
|
throw std::out_of_range("Value out of range: " #FIELD); \
|
|
} \
|
|
static_cast<T*>(this)->FIELD = value; \
|
|
return *static_cast<T*>(this); \
|
|
}
|
|
#define SETTER(TYPE, FIELD, DEFAULT) \
|
|
protected: \
|
|
TYPE FIELD = DEFAULT; \
|
|
public: \
|
|
Builder& set_##FIELD(TYPE value) { \
|
|
this->FIELD = std::move(value); \
|
|
return *this; \
|
|
}
|
|
namespace YSG {
|
|
template <typename T>
|
|
constexpr const T& clamp(const T& v, const T& lo, const T& hi) {
|
|
return (v < lo)
|
|
? lo
|
|
: (v > hi)
|
|
? hi
|
|
: v;
|
|
}
|
|
} // namespace YSG
|
|
#undef min
|
|
#undef max
|