|
@@ -22,7 +22,7 @@ class Polyline extends AreaItemAbstract with AutoSnapMixin {
|
|
|
|
|
|
static Polyline createAreaPerimeter(ItemMeta meta, [IMeasureItem? parent]) {
|
|
|
Polyline polygon = Polyline(meta, parent);
|
|
|
- polygon.calculator = _AreaPerimeterCalc(polygon);
|
|
|
+ polygon.calculator = AreaPerimeterCal(polygon);
|
|
|
return polygon;
|
|
|
}
|
|
|
|
|
@@ -125,83 +125,3 @@ class PolylineFeature extends AreaItemFeatureAbstract {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
-class _AreaPerimeterCalc extends Calculator<Polyline, double> {
|
|
|
- _AreaPerimeterCalc(Polyline ref) : super(ref);
|
|
|
-
|
|
|
- @override
|
|
|
- void calculate() {
|
|
|
- if (ref.feature == null) return;
|
|
|
-
|
|
|
- final feature = ref.feature!;
|
|
|
- final viewport = feature.hostVisualArea!.viewport!;
|
|
|
- final points = feature.innerPoints.map((e) => viewport.convert(e)).toList();
|
|
|
-
|
|
|
- feature.values.clear();
|
|
|
-
|
|
|
- double area;
|
|
|
- double perimeter;
|
|
|
- if ((feature.splineTension - 0).abs() > 0) {
|
|
|
-
|
|
|
- perimeter = 0;
|
|
|
- area = 0;
|
|
|
- } else {
|
|
|
- double threshold = 0.0;
|
|
|
- area = calcArea(points);
|
|
|
- perimeter = calcPerimeter(points, feature.isClosed, threshold);
|
|
|
- }
|
|
|
- for (var output in ref.meta.outputs) {
|
|
|
- if (output.name == MeasureTerms.Perimeter) {
|
|
|
- var value = roundDouble(perimeter, output.fractionalDigits);
|
|
|
- feature.updateFloatValue(output, value, output.unit);
|
|
|
- } else if (output.name == MeasureTerms.Area) {
|
|
|
- var value = roundDouble(area, output.fractionalDigits);
|
|
|
- feature.updateFloatValue(output, value, output.unit);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- static double calcArea(List<DPoint> points) {
|
|
|
- if (points.isEmpty) {
|
|
|
- return 0;
|
|
|
- }
|
|
|
-
|
|
|
- double sum = 0;
|
|
|
- var ax = points[0].x;
|
|
|
- var ay = points[0].y;
|
|
|
- for (var i = 1; i < points.length - 1; i++) {
|
|
|
- var bx = points[i].x;
|
|
|
- var by = points[i].y;
|
|
|
- var cx = points[i + 1].x;
|
|
|
- var cy = points[i + 1].y;
|
|
|
- sum += ax * by - ay * bx + ay * cx - ax * cy + bx * cy - cx * by;
|
|
|
- }
|
|
|
- return (-sum / 2).abs();
|
|
|
- }
|
|
|
-
|
|
|
- static double calcPerimeter(
|
|
|
- List<DPoint> points,
|
|
|
- bool isClosed,
|
|
|
- double threshold,
|
|
|
- ) {
|
|
|
- final len = points.length;
|
|
|
- if (points.length < 2) {
|
|
|
- return 0;
|
|
|
- }
|
|
|
-
|
|
|
- double sum = 0;
|
|
|
- for (int i = 1, j = 0; j < len && i < len; i++) {
|
|
|
- var length = (points[i] - points[j]).length;
|
|
|
- if ((length).abs() > threshold) {
|
|
|
- sum += length;
|
|
|
- j = i;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if (isClosed) {
|
|
|
- sum += (points[len - 1] - points[0]).length;
|
|
|
- }
|
|
|
-
|
|
|
- return sum;
|
|
|
- }
|
|
|
-}
|