64ad721ed7
- CMake: INTERFACE 库修复、vde_compile_options 顺序修复 - 命名空间: 所有模块添加 using 声明 - 类型补全: Ray3Dd、Point4D - 头文件: tolerance 泛型化、std::optional include - 警告: 放宽 -Wconversion/-Wsign-conversion - 构建结果: 0 errors, 22/25 tests passed
51 lines
1.5 KiB
C++
51 lines
1.5 KiB
C++
#pragma once
|
|
#include "vde/core/point.h"
|
|
#include <vector>
|
|
#include <string>
|
|
|
|
namespace vde::sketch {
|
|
using core::Point2D;
|
|
using core::Vector2D;
|
|
|
|
struct SketchPoint { int id; Point2D pos; bool fixed = false; };
|
|
struct SketchLine { int id, p0, p1; };
|
|
struct SketchCircle { int id, center; double radius; };
|
|
|
|
enum class ConstraintType {
|
|
Horizontal, Vertical, Parallel, Perpendicular, Coincident,
|
|
EqualLength, Distance, Radius, Tangent, Concentric, FixedPoint
|
|
};
|
|
|
|
struct Constraint {
|
|
ConstraintType type;
|
|
std::vector<int> elements;
|
|
double value = 0.0;
|
|
};
|
|
|
|
struct SolverResult {
|
|
bool converged = false; int iterations = 0; double residual = 0.0;
|
|
std::vector<Point2D> points; std::string message;
|
|
};
|
|
|
|
class ConstraintSolver {
|
|
public:
|
|
int add_point(double x, double y, bool fixed = false);
|
|
int add_line(int p0, int p1);
|
|
int add_circle(int center, double radius);
|
|
void add_constraint(ConstraintType type, const std::vector<int>& elements, double val = 0.0);
|
|
void fix_point(int pid) { if(pid>=0&&pid<(int)points_.size()) points_[pid].fixed=true; }
|
|
|
|
[[nodiscard]] SolverResult solve(int max_iter = 100, double tol = 1e-8);
|
|
[[nodiscard]] int degrees_of_freedom() const;
|
|
[[nodiscard]] const std::vector<SketchPoint>& points() const { return points_; }
|
|
|
|
private:
|
|
std::vector<SketchPoint> points_;
|
|
std::vector<SketchLine> lines_;
|
|
std::vector<SketchCircle> circles_;
|
|
std::vector<Constraint> constraints_;
|
|
double eval_constraint(const Constraint& c) const;
|
|
};
|
|
|
|
} // namespace vde::sketch
|