Skip to content

Commit 94e4d21

Browse files
committed
Main bug fixed. Animation pending.
1 parent 0152eed commit 94e4d21

File tree

1 file changed

+18
-52
lines changed

1 file changed

+18
-52
lines changed

lib/circles_selector/CirclesHomeWidget.dart

+18-52
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,6 @@ import 'dart:math';
22

33
import 'package:flutter/material.dart';
44

5-
//Code snips
6-
// print("""distance == sqrt(2) \n
7-
// | Displacement: $displacement \n
8-
// | currentDistance($currentDistance) = distance($distance) * defaultSpacing($defaultSpacing) \n
9-
// | desiredDistance($desiredDistance) = defaultSpacing($defaultSpacing) * expansionAmount($expansionAmount)
10-
// """);
11-
125
class CirclesHomeWidget extends StatelessWidget {
136
const CirclesHomeWidget({Key? key}) : super(key: key);
147

@@ -85,6 +78,13 @@ class CircleGridPainter extends CustomPainter {
8578
final int? selectedIndex;
8679
final int columns;
8780

81+
static const double maxDisplacementDistance =
82+
6.0; // Maximum distance for displacement effect
83+
static const double fullDisplacementDistance =
84+
0.5; // Distance for full displacement
85+
static const double falloffExponent =
86+
1.0; // Controls the steepness of falloff
87+
8888
CircleGridPainter({
8989
required this.offset,
9090
required this.circleSize,
@@ -161,12 +161,20 @@ class CircleGridPainter extends CustomPainter {
161161
double distance = sqrt(dx * dx + dy * dy);
162162
double angle = atan2(dy.toDouble(), dx.toDouble());
163163

164-
// Replace this line with the fixed version
165-
// double displacement =
166-
// _getDisplacement(distance, expansionAmount, defaultSpacing);
164+
// Determine if the circle is diagonal or orthogonal
165+
bool isDiagonal = dx != 0 && dy != 0;
166+
167+
// Calculate the base displacement
167168
double displacement =
168169
_getDisplacementFixed(distance, expansionAmount, defaultSpacing);
169170

171+
// diagonal adjustment
172+
if (isDiagonal) {
173+
double diagonalCorrectionFactor =
174+
0.1; // or use 1 / sqrt(2) ≈ 0.707 for exact diagonal adjustment
175+
displacement *= diagonalCorrectionFactor;
176+
}
177+
170178
if (displacement > 0) {
171179
displacements[Point(col, row)] = Offset(
172180
cos(angle) * displacement,
@@ -175,48 +183,6 @@ class CircleGridPainter extends CustomPainter {
175183
}
176184
}
177185

178-
// double _getDisplacement(
179-
// double distance, double expansionAmount, double defaultSpacing) {
180-
// if (distance % 1 == 0 && distance >= 1) {
181-
// return expansionAmount;
182-
// } else if (distance <= sqrt(2) ||
183-
// distance <= sqrt(5) ||
184-
// distance <= sqrt(10) ||
185-
// distance <= sqrt(13)) {
186-
// double currentDistance = distance * defaultSpacing;
187-
// double desiredDistance = defaultSpacing + expansionAmount;
188-
// return currentDistance < desiredDistance
189-
// ? desiredDistance - currentDistance
190-
// : 0;
191-
// }
192-
// return 0;
193-
// }
194-
195-
// Suggested fix
196-
// double _getDisplacementFixed(
197-
// double distance, double expansionAmount, double defaultSpacing) {
198-
// if (distance % 1 == 0 && distance >= 1) {
199-
// return expansionAmount;
200-
// } else if (distance <= sqrt(2)) {
201-
// double currentDistance = distance * defaultSpacing;
202-
// double desiredDistance = defaultSpacing + expansionAmount;
203-
// return currentDistance < desiredDistance
204-
// ? desiredDistance - currentDistance
205-
// : 0;
206-
// } else if (distance % 1 == 0 && distance >= 2) {
207-
// return expansionAmount;
208-
// } else {
209-
// return 0;
210-
// }
211-
// }
212-
213-
static const double maxDisplacementDistance =
214-
6.0; // Maximum distance for displacement effect
215-
static const double fullDisplacementDistance =
216-
0.5; // Distance for full displacement
217-
static const double falloffExponent =
218-
1.0; // Controls the steepness of falloff
219-
220186
double _getDisplacementFixed(
221187
double distance, double expansionAmount, double defaultSpacing) {
222188
if (distance <= maxDisplacementDistance) {

0 commit comments

Comments
 (0)