Skip to content

Commit

Permalink
Use different logic for split trim paths #95
Browse files Browse the repository at this point in the history
  • Loading branch information
umberto-sonnino committed Jun 13, 2019
1 parent 153dd55 commit 865e090
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
1 change: 0 additions & 1 deletion flare_flutter/lib/flare.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import 'dart:ui' as ui;
import 'package:flare_dart/actor_flags.dart';
import 'package:flare_dart/actor_image.dart';
import 'package:flare_dart/math/aabb.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';

import 'package:flutter/material.dart';
Expand Down
19 changes: 11 additions & 8 deletions flare_flutter/lib/trim_path.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ library flare_flutter;

import 'dart:ui';

double _appendPathSegmentSequential(
PathMetrics metrics, Path to, double offset, double start, double stop) {
double _appendPathSegmentSequential(Iterator<PathMetric> metricsIterator,
Path to, double offset, double start, double stop) {
double nextOffset = offset;
for (final PathMetric metric in metrics) {
do {
PathMetric metric = metricsIterator.current;
nextOffset = offset + metric.length;
if (start < nextOffset) {
Path extracted = metric.extractPath(start - offset, stop - offset);
Expand All @@ -17,7 +18,7 @@ double _appendPathSegmentSequential(
}
}
offset = nextOffset;
}
} while (metricsIterator.moveNext());
return offset;
}

Expand Down Expand Up @@ -49,19 +50,21 @@ Path _trimPathSequential(
double trimStop = totalLength * stopT;
double offset = 0.0;

Iterator<PathMetric> metricsIterator = metrics.iterator;
metricsIterator.moveNext();
if (complement) {
if (trimStart > 0.0) {
offset =
_appendPathSegmentSequential(metrics, result, offset, 0.0, trimStart);
offset = _appendPathSegmentSequential(
metricsIterator, result, offset, 0.0, trimStart);
}
if (trimStop < totalLength) {
offset = _appendPathSegmentSequential(
metrics, result, offset, trimStop, totalLength);
metricsIterator, result, offset, trimStop, totalLength);
}
} else {
if (trimStart < trimStop) {
offset = _appendPathSegmentSequential(
metrics, result, offset, trimStart, trimStop);
metricsIterator, result, offset, trimStart, trimStop);
}
}

Expand Down

0 comments on commit 865e090

Please sign in to comment.