Position balancing for >3 dots
This commit is contained in:
parent
f82cdf0814
commit
5e872804ac
|
@ -29,7 +29,7 @@ class CurvePainter extends CustomPainter {
|
|||
|
||||
void drawDot(Canvas canvas, Offset p1) {
|
||||
var p = Paint();
|
||||
p.color = col;
|
||||
p.color = Colors.yellow.shade900;
|
||||
p.strokeWidth = width;
|
||||
canvas.drawCircle(p1, rad, p);
|
||||
}
|
||||
|
@ -76,13 +76,17 @@ class CurvePainter extends CustomPainter {
|
|||
return Graphs.fromList("1", d, false, false);
|
||||
}
|
||||
|
||||
int getHighConnections() {
|
||||
int getHighInputConnections() {
|
||||
if (gr.getDots().length <= 3) return -1;
|
||||
int higest = -1;
|
||||
gr.getDots().forEach((element) {
|
||||
for (var i in gr.getDots()) {
|
||||
if (i.getL().length > higest) higest = i.num;
|
||||
}
|
||||
/*gr.getDots().forEach((element) {
|
||||
if (element.getL().length > higest) {
|
||||
higest = element.num;
|
||||
}
|
||||
});
|
||||
});*/
|
||||
return higest;
|
||||
}
|
||||
|
||||
|
@ -90,12 +94,23 @@ class CurvePainter extends CustomPainter {
|
|||
Map<int, Offset> off = <int, Offset>{};
|
||||
var width = size.width / 2;
|
||||
var height = size.height / 2;
|
||||
int add = 1;
|
||||
int add = 0;
|
||||
int h = getHighInputConnections();
|
||||
for (int i = 0; i < dotsAm; i++) {
|
||||
double x = cos(2 * pi * i / dotsAm) * circleRad + width;
|
||||
double y = sin(2 * pi * i / dotsAm) * circleRad + height;
|
||||
if ((i + 1) != h) {
|
||||
double x = cos(2 * pi * (i - add) / (dotsAm - add)) * circleRad + width;
|
||||
double y =
|
||||
sin(2 * pi * (i - add) / (dotsAm - add)) * circleRad + height;
|
||||
|
||||
off[i + add] = Offset(x, y);
|
||||
off[i + 1] = Offset(x, y);
|
||||
} else if ((i + 1) == h) {
|
||||
off[i + 1] = Offset(width + 2, height - 2);
|
||||
add = 1;
|
||||
h = 0;
|
||||
} else {
|
||||
print("GetDotPos error");
|
||||
}
|
||||
print(off.length);
|
||||
}
|
||||
|
||||
//print(off);
|
||||
|
@ -120,8 +135,8 @@ class CurvePainter extends CustomPainter {
|
|||
/// Draw a single arrow.
|
||||
path = Path();
|
||||
path.moveTo(from.dx, from.dy);
|
||||
path.relativeCubicTo(0, 0, -(from.dx + to.dx) / length - 40,
|
||||
-(from.dy + to.dy) / length - 40, to.dx - from.dx, to.dy - from.dy);
|
||||
path.relativeCubicTo(0, 0, -(from.dx + to.dx) / length * 2 - 40,
|
||||
-(from.dy + to.dy) / length * 2 - 40, to.dx - from.dx, to.dy - from.dy);
|
||||
path =
|
||||
ArrowPath.make(path: path, isDoubleSided: doubleSided, tipLength: 16);
|
||||
canvas.drawPath(path, paint);
|
||||
|
|
|
@ -9,9 +9,9 @@ Graphs getGraph() {
|
|||
d.add(Dot.fromTwoLists("1", [2, 3], [5, 1]));
|
||||
d.add(Dot.fromTwoLists("2", [1, 3], [1, 1]));
|
||||
d.add(Dot.fromTwoLists("3", [1, 2], [1, 2]));
|
||||
d.add(Dot.fromTwoLists("Name1", [], []));
|
||||
d.add(Dot.fromTwoLists("Name2", [], []));
|
||||
return Graphs.fromList("1", d, true, true);
|
||||
//d.add(Dot.fromTwoLists("Name1", [], []));
|
||||
//d.add(Dot.fromTwoLists("Name2", [], []));
|
||||
return Graphs.fromList("UMYA", d, true, true);
|
||||
}
|
||||
|
||||
class DrawingPage extends StatefulWidget {
|
||||
|
@ -47,7 +47,7 @@ class _DrawingPageState extends State<DrawingPage> {
|
|||
appBar: AppBar(
|
||||
title: const Align(
|
||||
alignment: Alignment.topLeft,
|
||||
child: Text("Graph\n\n",
|
||||
child: Text("Graph name:\n",
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
color: Colors.white,
|
||||
|
@ -96,6 +96,8 @@ class _DrawingPageState extends State<DrawingPage> {
|
|||
child: ButtonBar(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: <Widget>[
|
||||
createButton("Bfs", () {}),
|
||||
createButton("Dfs", () {}),
|
||||
createButton(data.getUseLengthStr(), changeLength),
|
||||
createButton(data.getDoubleSidedStr(), changeOriented),
|
||||
/*Text(_textGrNmController.text,
|
||||
|
|
|
@ -537,7 +537,7 @@ class Graphs {
|
|||
}
|
||||
|
||||
//************Алгоритмы************
|
||||
bool bfsHasPath(int startDot, int goalDot) {
|
||||
/* bool bfsHasPath(int startDot, int goalDot) {
|
||||
// обход в ширину
|
||||
startDot--;
|
||||
goalDot--;
|
||||
|
@ -564,7 +564,7 @@ class Graphs {
|
|||
}
|
||||
}
|
||||
return false; // Целевой узел недостижим
|
||||
}
|
||||
}*/
|
||||
|
||||
List<int>? bfsPath(int startDot, int goalDot) {
|
||||
//if (!bfsHasPath(startDot, goalDot)) return null;
|
||||
|
|
Loading…
Reference in New Issue