Sketcher: Use DenseQR for small sketches to avoid SparseQR rank issues (#26559)

This commit is contained in:
PaddleStroke
2026-01-04 21:57:13 +01:00
committed by GitHub
parent 212350acb8
commit c8106982de
6 changed files with 182 additions and 24 deletions

View File

@@ -641,6 +641,14 @@ public:
{
return debugMode;
}
inline void setAutoQRThreshold(int val)
{
GCSsys.autoQRThreshold = val;
}
inline void setSketchAutoAlgo(bool val)
{
GCSsys.autoChooseAlgorithm = val;
}
inline void setMaxIter(int maxiter)
{
GCSsys.maxIter = maxiter;

View File

@@ -486,6 +486,8 @@ System::System()
, convergence(1e-10)
, convergenceRedundant(1e-10)
, qrAlgorithm(EigenSparseQR)
, autoChooseAlgorithm(true)
, autoQRThreshold(1000)
, dogLegGaussStep(FullPivLU)
, qrpivotThreshold(1E-13)
, debugMode(Minimal)
@@ -4808,6 +4810,15 @@ int System::diagnose(Algorithm alg)
hasDiagnosis = true;
dofs = pdiagnoselist.size();
// Use DenseQR for small to medium systems to avoid SparseQR rank issues.
// SparseQR is known to fail rank detection on specific geometric structures (e.g. aligned slots).
// 200 parameters roughly corresponds to ~100 points/curves, covering most complex sketches
// where stability is preferred over pure O(N) performance.
// See: https://github.com/FreeCAD/FreeCAD/issues/10903
if (autoChooseAlgorithm) {
qrAlgorithm = dofs < autoQRThreshold ? EigenDenseQR : EigenSparseQR;
}
// There is a legacy decision to use QR decomposition. I (abdullah) do not know all the
// consideration taken in that decisions. I see that:
// - QR decomposition is able to provide information about the rank and

View File

@@ -239,6 +239,8 @@ public:
double convergence;
double convergenceRedundant;
QRAlgorithm qrAlgorithm;
bool autoChooseAlgorithm;
int autoQRThreshold;
DogLegGaussStep dogLegGaussStep;
double qrpivotThreshold;
DebugMode debugMode;