From 9ff6dd2745180237debdb0dbe7c0f57add4a612e Mon Sep 17 00:00:00 2001 From: lnd212 Date: Sat, 6 Nov 2021 02:20:18 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=BE=D0=BF=D1=8B=D1=82=D0=BA=D0=B8=20?= =?UTF-8?q?=D0=B2=20=D1=81=D1=82=D1=80=D0=B5=D0=BB=D0=BE=D1=87=D0=BA=D0=B8?= =?UTF-8?q?=20=D1=852=20=D0=BD=D0=B5=D1=83=D0=B4=D0=B0=D1=87=D0=BD=D1=8B?= =?UTF-8?q?=D0=B5,=20=D0=BD=D0=BE=20=D1=87=D1=83=D1=82=D1=8C=20=D0=B1?= =?UTF-8?q?=D0=BE=D0=BB=D0=B5=20=D1=83=D0=B4=D0=B0=D1=87=D0=BD=D1=8B=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- flutter/lib/curve_painter.dart | 74 +++++++++++++++++++---------- flutter/lib/pages/drawing_page.dart | 2 +- flutter/outTest.txt | 11 +++++ 3 files changed, 62 insertions(+), 25 deletions(-) create mode 100644 flutter/outTest.txt diff --git a/flutter/lib/curve_painter.dart b/flutter/lib/curve_painter.dart index 6461e52..ffcda88 100644 --- a/flutter/lib/curve_painter.dart +++ b/flutter/lib/curve_painter.dart @@ -76,15 +76,30 @@ class CurvePainter extends CustomPainter { return Graphs.fromList("1", d, false, false); } - Map getDotPos(int dotsAm, Size size) { + int getHighConnections() { + int higest = -1; + gr.getDots().forEach((element) { + if (element.getL().length > higest) { + higest = element.num; + } + }); + return higest; + } + + Map getDotPos(int dotsAm, Size size, int exclude) { + dotsAm--; Map off = {}; var width = size.width / 2; var height = size.height / 2; + int add = 1; 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; - off[i + 1] = Offset(x, y); + + if (i == exclude - 1) add++; + off[i + add] = Offset(x, y); } + //print(off); return off; } @@ -101,11 +116,14 @@ class CurvePainter extends CustomPainter { ..strokeJoin = StrokeJoin.round ..strokeWidth = width - 1; + var length = sqrt((to.dx - from.dx) * (to.dx - from.dx) + + (to.dy - from.dy) * (to.dy - from.dy)); + /// Draw a single arrow. path = Path(); path.moveTo(from.dx, from.dy); - path.relativeCubicTo( - 0, 0, size.width / 20, 50, to.dx - from.dx, to.dy - 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 = ArrowPath.make(path: path, isDoubleSided: doubleSided, tipLength: 13); canvas.drawPath(path, paint); @@ -123,11 +141,14 @@ class CurvePainter extends CustomPainter { ..strokeJoin = StrokeJoin.round ..strokeWidth = width - 1; + var length = sqrt((to.dx - from.dx) * (to.dx - from.dx) + + (to.dy - from.dy) * (to.dy - from.dy)); + /// Draw a single arrow. path = Path(); path.moveTo(from.dx, from.dy); - path.relativeCubicTo( - 0, 0, -size.width / 25, -50, to.dx - from.dx, to.dy - from.dy); + path.relativeCubicTo(0, 0, (from.dx + to.dx) / length + 60, + (from.dy + to.dy) / length + 0, to.dx - from.dx, to.dy - from.dy); path = ArrowPath.make( path: path, isDoubleSided: doubleSided, @@ -151,8 +172,8 @@ class CurvePainter extends CustomPainter { if (gr.getUseLengthBool()) { drawDotNames( canvas, - Offset((off[d]!.dx + beg.dx) / 2 - 20, - (off[d]!.dy + beg.dy) / 2 - 20), + Offset((off[d]!.dx + beg.dx) / 2 - 18, + (off[d]!.dy + beg.dy) / 2 - 18), i.getL()[d].toString()); } } else { @@ -160,8 +181,8 @@ class CurvePainter extends CustomPainter { if (gr.getUseLengthBool()) { drawDotNames( canvas, - Offset((off[d]!.dx + beg.dx) / 2 + 25, - (off[d]!.dy + beg.dy) / 2 + 25), + Offset((off[d]!.dx + beg.dx) / 2 + 30, + (off[d]!.dy + beg.dy) / 2 + 30), i.getL()[d].toString()); } } @@ -191,18 +212,23 @@ class CurvePainter extends CustomPainter { //Offset(size.width, size.height / 2)); //gr = getGraph(); - var off = getDotPos(gr.getDotAmount(), size); - for (int i in off.keys) { - drawDot(canvas, off[i]!); - drawDotNames(canvas, off[i]!, "${gr.getDots()[i - 1].getName()}:[${i}]"); + int higest = getHighConnections(); + if (higest > -1) { + var off = getDotPos(gr.getDotAmount(), size, higest); + off[higest] = Offset(size.width / 2, size.height / 2); + for (int i in off.keys) { + drawDot(canvas, off[i]!); + drawDotNames( + canvas, off[i]!, "${gr.getDots()[i - 1].getName()}:[${i}]"); + } + //var g = gr.getNoRepeatDots(); + //print(g); + var g = gr.getDots(); + drawConnections(canvas, size, g, off); + //pringArr(canvas, size); + //drawArrow(canvas, Offset(size.width / 2, size.height / 2), + // Offset(size.width / 2 + 50, size.height / 2 + 200)); } - //var g = gr.getNoRepeatDots(); - //print(g); - var g = gr.getDots(); - drawConnections(canvas, size, g, off); - //pringArr(canvas, size); - //drawArrow(canvas, Offset(size.width / 2, size.height / 2), - // Offset(size.width / 2 + 50, size.height / 2 + 200)); } @override @@ -273,9 +299,9 @@ void pringArr(Canvas canvas, Size size) { /// Use complex path. path = Path(); path.moveTo(size.width * 0.25, size.height * 0.3); - path.relativeCubicTo(0, 0, size.width * 0.25, 50, size.width * 0.5, 50); - path.relativeCubicTo(0, 0, -size.width * 0.25, 0, -size.width * 0.5, 50); - path.relativeCubicTo(0, 0, size.width * 0.125, 10, size.width * 0.25, -10); + path.relativeCubicTo(0, 0, size.width * 0.25, 0, size.width * 0.5, 50); + path.relativeCubicTo(0, 0, -size.width * 0.25, 50, -size.width * 0.5, 50); + //path.relativeCubicTo(0, 0, size.width * 0.125, 10, size.width * 0.25, -10); path = ArrowPath.make(path: path, isDoubleSided: true); canvas.drawPath(path, paint..color = Colors.blue); diff --git a/flutter/lib/pages/drawing_page.dart b/flutter/lib/pages/drawing_page.dart index 91810ea..c8d0222 100644 --- a/flutter/lib/pages/drawing_page.dart +++ b/flutter/lib/pages/drawing_page.dart @@ -11,7 +11,7 @@ Graphs getGraph() { 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, false); + return Graphs.fromList("1", d, true, true); } class DrawingPage extends StatefulWidget { diff --git a/flutter/outTest.txt b/flutter/outTest.txt new file mode 100644 index 0000000..ec9e705 --- /dev/null +++ b/flutter/outTest.txt @@ -0,0 +1,11 @@ +1 +Ориентированный +Взвешенный +1: 2|5 5|4 +2: +3: 5|4 +4: 6|5 +5: 2|4 +6: 5|4 2|5 1|5 +7: 2|5 +END \ No newline at end of file