From 51b03c680ce20c7a10066936c35cafd9297ef945 Mon Sep 17 00:00:00 2001 From: Anton Lempiy Date: Thu, 27 Apr 2023 11:27:02 +0300 Subject: [PATCH] Remove max iterations limit --- CHANGELOG.md | 3 ++- lib/core/graph.dart | 14 ++++---------- lib/core/graph_matrix.dart | 2 ++ pubspec.yaml | 2 +- 4 files changed, 9 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 35734fe..6189428 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -56,5 +56,6 @@ * Removed `contentWrapperBuilder` since `InteractiveViewer` is no longer used. * Changed `onCanvasTap` callback to provide tap details and trigger only if tapped out of other widgets and figures. +## [1.1.1] - April 27, 2023 - +* Removed max iterations limitation for graph. diff --git a/lib/core/graph.dart b/lib/core/graph.dart index 7df8a14..2b3d774 100644 --- a/lib/core/graph.dart +++ b/lib/core/graph.dart @@ -3,8 +3,6 @@ import 'package:graphite/core/matrix.dart'; import 'package:graphite/core/traverse_queue.dart'; import 'package:graphite/core/typings.dart'; -const MaxIterations = 1000; - class Graph extends GraphMatrix { Graph({required List list, required bool centred}) : super(list: list, centred: centred); @@ -86,24 +84,20 @@ class Graph extends GraphMatrix { } } - int traverseLevel(int iterations, State state) { + void traverseLevel(State state) { var queue = state.queue; var levelQueue = queue.drain(); while (levelQueue.length() != 0) { - iterations++; + state.iterations++; NodeOutput item = levelQueue.shift(); traverseItem(item, state, levelQueue); - if (iterations > MaxIterations) { - throw "max iterations reached"; - } } - return iterations; } Matrix traverseList(State state) { - var safe = 0, mtx = state.mtx, queue = state.queue; + var mtx = state.mtx, queue = state.queue; while (queue.length() != 0) { - safe = traverseLevel(safe, state); + traverseLevel(state); state.x++; } return mtx; diff --git a/lib/core/graph_matrix.dart b/lib/core/graph_matrix.dart index c555dc2..f08f0dc 100644 --- a/lib/core/graph_matrix.dart +++ b/lib/core/graph_matrix.dart @@ -10,11 +10,13 @@ class State { TraverseQueue queue; int x; int y; + int iterations; State({ required this.mtx, required this.queue, this.x = 0, this.y = 0, + this.iterations = 0, }); } diff --git a/pubspec.yaml b/pubspec.yaml index 151df93..48b13c9 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: graphite description: Flutter widget to easily draw direct graphs, trees, flowcharts. Includes gesture API to create graphs interactions. -version: 1.1.0 +version: 1.1.1 homepage: https://github.com/lempiy/flutter_graphite environment: