12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- import 'package:fis_measure/interfaces/date_types/point.dart';
- import 'package:fis_measure/interfaces/process/calculators/output.dart';
- import 'package:fis_measure/interfaces/process/items/measure_terms.dart';
- import 'package:fis_measure/process/primitives/ellipse.dart';
- import 'package:vid/us/vid_us_unit.dart';
- import '../primitives/poyline.dart';
- import 'calculator.dart';
- class PolyLinePerimeterCal extends Calculator<PolyLine, double> {
- PolyLinePerimeterCal(PolyLine ref) : super(ref);
- @override
- void calculate() {
- if (ref.feature == null) return;
- // TODO:xxx
- final viewport = ref.feature!.hostVisualArea!.viewport!;
- final points =
- ref.feature!.innerPoints.map((e) => viewport.convert(e)).toList();
- double threshold = 0;
- // if (ref.Threshold.HasValue)
- // {
- // threshold = ref.Threshold.Value;
- // }
- double value = calcPerimeter(points, ref.feature!.isClosed, threshold);
- final outputItem = OutputItem(
- value: value,
- name: MeasureTerms.Perimeter,
- unit: VidUsUnit.cm,
- );
- final description =
- "${ref.description}: ${roundDouble(value)}${VidUsUnit.cm.name}";
- outputItem.updateDescription(description: description);
- output = outputItem;
- }
- static double calcPerimeter(
- List<DPoint> points,
- bool isClosed,
- double threshold,
- ) {
- if (points.length < 2) {
- return 0;
- }
- double sum = 0;
- for (int i = 1, j = 0; j < points.length && i < points.length; i++) {
- var length = (points[i] - points[j]).length;
- if (length.abs() > threshold) {
- sum += length;
- j = i;
- }
- }
- if (isClosed) {
- sum += (points[points.length - 1] - points[0]).length;
- }
- return sum;
- }
- }
|