5 #include <unordered_map>
174 if (pid >= 0 && pid <
static_cast<int>(points_.size()))
175 points_[pid].fixed =
true;
201 [[nodiscard]]
const std::vector<SketchPoint>&
points()
const {
return points_; }
211 std::vector<SketchPoint> points_;
212 std::vector<SketchLine> lines_;
213 std::vector<SketchCircle> circles_;
214 std::vector<Constraint> constraints_;
221 void sync_from_vars(
const double* vars,
int nv);
228 double eval_constraint(
const Constraint& c)
const;
235 int count_equations(
const Constraint& c)
const;
246 void fill_jacobian_rows(
const Constraint& c,
int ci,
247 const std::vector<int>& row_map,
248 double* J_data,
int nv,
int stride)
const;
Point2D get_point(int id) const
查询点坐标
int add_point(double x, double y, bool fixed=false)
添加自由点
void fix_point(int pid)
标记点为固定(硬约束)
SolverResult solve(int max_iter=100, double tol=1e-8)
执行约束求解
int degrees_of_freedom() const
计算自由度
const std::vector< SketchPoint > & points() const
当前点集访问
void add_constraint(ConstraintType type, const std::vector< int > &elements, double val=0.0)
添加约束
int add_line(int p0, int p1)
添加线段
int add_circle(int center, double radius)
添加圆
@ Vertical
垂直线: x1 - x0 = 0 [1 eq]
@ Distance
距离约束: |p1-p0| - d = 0 [1 eq]
@ FixedPoint
固定点(硬约束,排除变量)[0 eq — 系统预处理]
@ Fixed
固定点位置: x-x0=0, y-y0=0 [2 eqs]
@ Angle
角度约束: atan2(cross(d0,d1), dot(d0,d1)) - θ = 0 [1 eq]
@ EqualLength
等长度: |d0| - |d1| = 0 [1 eq]
@ Coincident
两点重合: |p1-p0| = 0 [2 eqs: Δx=0, Δy=0]
@ Parallel
两线平行: cross(d0, d1) = 0 [1 eq]
@ Horizontal
水平线: y1 - y0 = 0 [1 eq]
@ Perpendicular
两线垂直: dot(d0, d1) = 0 [1 eq]
foundation::Point2D Point2D
双精度二维点(重新导出)
foundation::Vector2D Vector2D
双精度二维向量(重新导出)
std::vector< int > elements
引用的元素索引(点/线/圆 ID)
std::string message
诊断信息(成功或失败原因)
std::vector< Point2D > points
求解后的点坐标