110 lines
3.2 KiB
C++
110 lines
3.2 KiB
C++
#pragma once
|
||
|
||
#include <string>
|
||
#include <deque>
|
||
#include <cstdint>
|
||
|
||
// 移动物体类型
|
||
enum class MovingObjectType {
|
||
AIRCRAFT, // 航空器
|
||
SPECIAL, // 特勤车
|
||
UNMANNED // 无人车(可控车辆)
|
||
};
|
||
|
||
// 基础数据类型
|
||
struct Vector2D {
|
||
double x;
|
||
double y;
|
||
|
||
double magnitude() const;
|
||
double direction() const;
|
||
};
|
||
|
||
struct GeoPosition {
|
||
double latitude;
|
||
double longitude;
|
||
};
|
||
|
||
struct PositionRecord {
|
||
GeoPosition geo;
|
||
uint64_t timestamp;
|
||
|
||
PositionRecord(const GeoPosition& g, uint64_t t) : geo(g), timestamp(t) {}
|
||
};
|
||
|
||
// 移动物体基类
|
||
class MovingObject {
|
||
public:
|
||
MovingObject() : heading(0.0), speed(0.0), timestamp(0), type(MovingObjectType::SPECIAL) {}
|
||
virtual ~MovingObject() = default;
|
||
|
||
std::string id;
|
||
Vector2D position;
|
||
GeoPosition geo;
|
||
double heading;
|
||
double speed;
|
||
int64_t timestamp;
|
||
MovingObjectType type; // 添加类型字段
|
||
|
||
std::deque<PositionRecord> positionHistory;
|
||
|
||
static double calculateDistance(const GeoPosition& pos1, const GeoPosition& pos2);
|
||
static double calculateHeading(const GeoPosition& from, const GeoPosition& to);
|
||
|
||
virtual bool isValidPosition(const GeoPosition& newPos) const = 0;
|
||
virtual bool isValidSpeed(double speed) const = 0;
|
||
virtual double getSpeedSmoothingFactor() const { return 0.3; }
|
||
|
||
void updateMotion(const GeoPosition& newPos, uint64_t newTime);
|
||
void copyHistoryFrom(const MovingObject& other);
|
||
bool hasPositionChanged() const;
|
||
|
||
// 添加类型识别虚函数
|
||
virtual bool isAircraft() const { return type == MovingObjectType::AIRCRAFT; }
|
||
virtual bool isSpecialVehicle() const { return type == MovingObjectType::SPECIAL; }
|
||
virtual bool isUnmannedVehicle() const { return type == MovingObjectType::UNMANNED; }
|
||
|
||
static constexpr size_t MAX_HISTORY = 10;
|
||
};
|
||
|
||
// 航空器类
|
||
class Aircraft : public MovingObject {
|
||
public:
|
||
Aircraft() { type = MovingObjectType::AIRCRAFT; }
|
||
|
||
std::string flightNo;
|
||
std::string trackNumber;
|
||
double altitude;
|
||
|
||
bool isValidPosition(const GeoPosition& newPos) const override;
|
||
bool isValidSpeed(double speed) const override;
|
||
|
||
static constexpr double MAX_SPEED = 100.0; // 最大速度(米/秒)
|
||
static constexpr double MAX_POSITION_JUMP = 50.0; // 最大位置跳变(米)
|
||
|
||
bool isAircraft() const override { return true; }
|
||
bool isSpecialVehicle() const override { return false; }
|
||
};
|
||
|
||
// 车辆类
|
||
class Vehicle : public MovingObject {
|
||
public:
|
||
Vehicle() {
|
||
type = MovingObjectType::UNMANNED; // 默认为无人车类型
|
||
isControllable = true; // 默认为可控
|
||
}
|
||
|
||
std::string vehicleNo;
|
||
bool isControllable; // true 表示无人车,false 表示特勤车
|
||
|
||
bool isValidPosition(const GeoPosition& newPos) const override;
|
||
bool isValidSpeed(double speed) const override;
|
||
|
||
static constexpr double MAX_SPEED = 20.0; // 最大速度(米/秒)
|
||
static constexpr double MAX_POSITION_JUMP = 10.0; // 最大位置跳变(米)
|
||
|
||
bool isAircraft() const override { return false; }
|
||
bool isSpecialVehicle() const override {
|
||
return type == MovingObjectType::SPECIAL; // 只判断类型
|
||
}
|
||
}; |