From 5e872804ac0acc1c7363aaa9280675504873b771 Mon Sep 17 00:00:00 2001 From: lnd212 Date: Mon, 8 Nov 2021 19:37:13 +0400 Subject: [PATCH] Position balancing for >3 dots --- flutter/lib/curve_painter.dart | 35 ++++++++++++++++++++--------- flutter/lib/pages/drawing_page.dart | 10 +++++---- flutter/lib/src/graph.dart | 4 ++-- 3 files changed, 33 insertions(+), 16 deletions(-) diff --git a/flutter/lib/curve_painter.dart b/flutter/lib/curve_painter.dart index 42365e6..7ff545c 100644 --- a/flutter/lib/curve_painter.dart +++ b/flutter/lib/curve_painter.dart @@ -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 off = {}; 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); diff --git a/flutter/lib/pages/drawing_page.dart b/flutter/lib/pages/drawing_page.dart index c8d0222..2505808 100644 --- a/flutter/lib/pages/drawing_page.dart +++ b/flutter/lib/pages/drawing_page.dart @@ -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 { 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 { child: ButtonBar( mainAxisSize: MainAxisSize.min, children: [ + createButton("Bfs", () {}), + createButton("Dfs", () {}), createButton(data.getUseLengthStr(), changeLength), createButton(data.getDoubleSidedStr(), changeOriented), /*Text(_textGrNmController.text, diff --git a/flutter/lib/src/graph.dart b/flutter/lib/src/graph.dart index 186bb3d..3f6860c 100644 --- a/flutter/lib/src/graph.dart +++ b/flutter/lib/src/graph.dart @@ -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? bfsPath(int startDot, int goalDot) { //if (!bfsHasPath(startDot, goalDot)) return null;