image_boundaries.dart 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. import 'package:fis_measure/interfaces/date_types/point.dart';
  2. import 'package:fis_measure/interfaces/process/viewports/image_boundary.dart';
  3. import 'package:flutter/foundation.dart';
  4. class BoundaryBase implements IImageBoundary {
  5. late final List<DPoint> _pointList;
  6. factory BoundaryBase.fromCorners(
  7. DPoint topLeft,
  8. DPoint bottomLeft,
  9. DPoint bottomRight,
  10. DPoint topRight,
  11. ) {
  12. final boundary = BoundaryBase()
  13. ..topLeft = topLeft
  14. ..bottomLeft = bottomLeft
  15. ..bottomRight = bottomRight
  16. ..topRight = topRight;
  17. return boundary;
  18. }
  19. BoundaryBase() {
  20. _pointList = List.generate(4, (index) => DPoint.zero);
  21. }
  22. @override
  23. List<DPoint> get points => _pointList;
  24. @override
  25. DPoint get bottomLeft => _pointList[1];
  26. set bottomLeft(DPoint value) => _pointList[1] = value;
  27. @override
  28. DPoint get bottomRight => _pointList[2];
  29. set bottomRight(DPoint value) => _pointList[2] = value;
  30. @override
  31. DPoint get topLeft => _pointList[0];
  32. set topLeft(DPoint value) => _pointList[0] = value;
  33. @override
  34. DPoint get topRight => _pointList[3];
  35. set topRight(DPoint value) => _pointList[3] = value;
  36. @override
  37. double get width => topRight.x - topLeft.x;
  38. @override
  39. double get height => bottomLeft.y - topLeft.y;
  40. @protected
  41. bool equalTo(BoundaryBase other) {
  42. return topLeft == other.topLeft &&
  43. bottomLeft == other.bottomLeft &&
  44. bottomRight == other.bottomRight &&
  45. topRight == other.topRight;
  46. }
  47. @override
  48. bool operator ==(Object other) {
  49. return other is BoundaryBase && equalTo(other);
  50. }
  51. @override
  52. int get hashCode {
  53. return topLeft.hashCode ^
  54. bottomLeft.hashCode ^
  55. bottomRight.hashCode ^
  56. topRight.hashCode;
  57. }
  58. }
  59. /// 线阵边界
  60. class LinearBoundary extends BoundaryBase {
  61. @protected
  62. @override
  63. bool equalTo(BoundaryBase other) {
  64. return other is LinearBoundary && super.equalTo(other);
  65. }
  66. }
  67. /// 扇阵边界
  68. class ConvexBoundary extends BoundaryBase {
  69. ConvexBoundary() : super() {
  70. points.add(DPoint.zero);
  71. }
  72. /// 扇阵顶点
  73. DPoint get vertex => points[4];
  74. @override
  75. bool operator ==(Object other) {
  76. return other is ConvexBoundary && super.equalTo(other);
  77. }
  78. @override
  79. int get hashCode {
  80. return super.hashCode ^ vertex.hashCode;
  81. }
  82. }