fix(calibration): préserver les rayons d'origine de l'IA lors du redimensionnement et corriger le reset
This commit is contained in:
@@ -61,6 +61,9 @@ class TargetCalibrationState extends State<TargetCalibration> {
|
||||
bool _showEspacement = false;
|
||||
double _baseRadiusBeforeScale = 1.0;
|
||||
|
||||
// SAUVEGARDE CRITIQUE : Pour mémoriser la structure d'origine de l'IA
|
||||
List<double>? _originalRingRadii;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
@@ -70,14 +73,21 @@ class TargetCalibrationState extends State<TargetCalibration> {
|
||||
_innerRadius = widget.initialInnerRadius;
|
||||
_ringCount = widget.initialRingCount;
|
||||
|
||||
// On mémorise la configuration d'usine de l'image
|
||||
if (widget.initialRingRadii != null) {
|
||||
_originalRingRadii = List.from(widget.initialRingRadii!);
|
||||
}
|
||||
|
||||
// Initialisation du ratio par défaut
|
||||
_currentEspacementRatio = (_radius > 0) ? (_innerRadius / _radius).clamp(0.01, 0.70) : 0.1;
|
||||
_initRingRadii();
|
||||
}
|
||||
|
||||
void _initRingRadii({bool forceRecalculate = false}) {
|
||||
if (!forceRecalculate && widget.initialRingRadii != null &&
|
||||
widget.initialRingRadii!.length == _ringCount) {
|
||||
// CORRECTION : Si on ne recalcule pas activement l'espacement linéaire, on préserve en priorité la structure d'origine
|
||||
if (!forceRecalculate && _originalRingRadii != null && _originalRingRadii!.length == _ringCount) {
|
||||
_ringRadii = List.from(_originalRingRadii!);
|
||||
} else if (!forceRecalculate && widget.initialRingRadii != null && widget.initialRingRadii!.length == _ringCount) {
|
||||
_ringRadii = List.from(widget.initialRingRadii!);
|
||||
} else {
|
||||
_ringRadii = List.generate(_ringCount, (i) {
|
||||
@@ -112,6 +122,7 @@ class TargetCalibrationState extends State<TargetCalibration> {
|
||||
shouldReinit = true;
|
||||
}
|
||||
if (widget.initialRingRadii != oldWidget.initialRingRadii && widget.initialRingRadii != null) {
|
||||
_originalRingRadii = List.from(widget.initialRingRadii!);
|
||||
shouldReinit = true;
|
||||
}
|
||||
|
||||
@@ -189,7 +200,12 @@ class TargetCalibrationState extends State<TargetCalibration> {
|
||||
onChanged: (bool value) {
|
||||
setState(() {
|
||||
_showEspacement = value;
|
||||
// Quand on désactive l'espacement manuel, on restaure la configuration d'usine !
|
||||
if (!value) {
|
||||
_initRingRadii(forceRecalculate: false);
|
||||
}
|
||||
});
|
||||
_notifyChange();
|
||||
},
|
||||
),
|
||||
),
|
||||
@@ -210,16 +226,17 @@ class TargetCalibrationState extends State<TargetCalibration> {
|
||||
const Icon(Icons.zoom_out, color: Colors.white, size: 16),
|
||||
Expanded(
|
||||
child: Slider(
|
||||
// SÉCURITÉ : Valeur max bridée fermement à 0.82 pour éviter le débordement vertical
|
||||
value: _radius.clamp(0.5, 0.82),
|
||||
min: 0.5,
|
||||
max: 0.82,
|
||||
// SÉCURITÉ : Ouverture mesurée des bornes pour plus de liberté sans débordement incontrôlé
|
||||
value: _radius.clamp(0.3, 0.95),
|
||||
min: 0.3,
|
||||
max: 0.95,
|
||||
activeColor: AppTheme.primaryColor,
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
_radius = value;
|
||||
_innerRadius = _radius * _currentEspacementRatio;
|
||||
_initRingRadii(forceRecalculate: true);
|
||||
// CORRECTION : Si le mode avancé n'est pas coché, on applique la taille pure sans détruire le ratio d'origine
|
||||
_initRingRadii(forceRecalculate: _showEspacement);
|
||||
});
|
||||
_notifyChange();
|
||||
},
|
||||
@@ -267,19 +284,22 @@ class TargetCalibrationState extends State<TargetCalibration> {
|
||||
],
|
||||
),
|
||||
),
|
||||
// CORRECTION DU BOUTON RESET : Force le ratio d'usine (10%) en dur sans écrasement
|
||||
// CORRECTION DU BOUTON RESET : Restaure désormais le vrai profil d'usine de l'IA
|
||||
IconButton(
|
||||
icon: const Icon(Icons.refresh, color: Colors.white70, size: 20),
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
// 1. On force la jauge orange à se remettre à 10%
|
||||
_currentEspacementRatio = 0.1;
|
||||
|
||||
// 2. On réaligne l'innerRadius sur la taille actuelle
|
||||
_innerRadius = _radius * _currentEspacementRatio;
|
||||
|
||||
// 3. On force la reconstruction des cercles parfaits
|
||||
_initRingRadii(forceRecalculate: true);
|
||||
if (_originalRingRadii != null) {
|
||||
_initRingRadii(forceRecalculate: false);
|
||||
if (_ringRadii.isNotEmpty) {
|
||||
_currentEspacementRatio = _ringRadii.first;
|
||||
_innerRadius = _radius * _currentEspacementRatio;
|
||||
}
|
||||
} else {
|
||||
_currentEspacementRatio = 0.1;
|
||||
_innerRadius = _radius * _currentEspacementRatio;
|
||||
_initRingRadii(forceRecalculate: true);
|
||||
}
|
||||
});
|
||||
_notifyChange();
|
||||
},
|
||||
@@ -361,9 +381,9 @@ class TargetCalibrationState extends State<TargetCalibration> {
|
||||
void _onScaleUpdate(ScaleUpdateDetails details, Size size) {
|
||||
setState(() {
|
||||
if (details.pointerCount == 2) {
|
||||
_radius = (_baseRadiusBeforeScale * details.scale).clamp(0.5, 0.82);
|
||||
_radius = (_baseRadiusBeforeScale * details.scale).clamp(0.3, 0.95);
|
||||
_innerRadius = _radius * _currentEspacementRatio;
|
||||
_initRingRadii(forceRecalculate: true);
|
||||
_initRingRadii(forceRecalculate: _showEspacement);
|
||||
} else if (_isDraggingCenter) {
|
||||
final deltaX = details.focalPointDelta.dx / size.width;
|
||||
final deltaY = details.focalPointDelta.dy / size.height;
|
||||
@@ -472,8 +492,8 @@ class _CalibrationPainter extends CustomPainter {
|
||||
|
||||
for (int i = 0; i < ringCount; i++) {
|
||||
final ringRadius = ringRadii.length > i ? ringRadii[i] : (i + 1) / ringCount;
|
||||
final prevRingRadius = i > 0 ? (ringRadii.length > i - 1 ? ringRadii[i - 1] : i / ringCount) : 0.0;
|
||||
final zoneRadius = baseRadius * (ringRadius + prevRingRadius) / 2;
|
||||
final textSpanRatio = i > 0 ? (ringRadii.length > i - 1 ? ringRadii[i - 1] : i / ringCount) : 0.0;
|
||||
final zoneRadius = baseRadius * (ringRadius + textSpanRatio) / 2;
|
||||
|
||||
final score = 10 - i;
|
||||
final labelX = center.dx + zoneRadius;
|
||||
@@ -517,7 +537,7 @@ class _CalibrationPainter extends CustomPainter {
|
||||
canvas.drawLine(Offset(center.dx - 20, center.dy), Offset(center.dx - 8, center.dy), crossPaint);
|
||||
canvas.drawLine(Offset(center.dx + 8, center.dy), Offset(center.dx + 20, center.dy), crossPaint);
|
||||
canvas.drawLine(Offset(center.dx, center.dy - 20), Offset(center.dx, center.dy - 8), crossPaint);
|
||||
canvas.drawLine(Offset(center.dx, center.dy + 8), Offset(center.dx, center.dy + 20), crossPaint);
|
||||
canvas.drawLine(Offset(center.dx, center.dy + 4), Offset(center.dx, center.dy + 20), crossPaint);
|
||||
}
|
||||
|
||||
void _drawInstructions(Canvas canvas, Size size) {
|
||||
|
||||
Reference in New Issue
Block a user