import 'package:fis_measure/interfaces/date_types/point.dart';
import 'package:fis_measure/interfaces/date_types/skew_transform.dart';
import 'package:fis_measure/interfaces/process/physical_coordinates/physical_coordinate.dart';
import 'package:vid/us/vid_us_visual_area_type.dart';

/// 二维线阵物理坐标系
class LinearTissuePhysicalCoordinate implements ITissuePhysicalCoordinate {
  // ignore: non_constant_identifier_names
  static final DPoint C_INVALID_POINT = DPoint(double.nan, double.nan);

  late final double _depthStart;
  late final double _depthEnd;
  late final double _width;
  late final double _beamPosition;
  late final double _steer;
  late final DSkewTransform _logicalToPhysicalConvert;
  late final DSkewTransform _logicalToPhysicalConvertBack;

  LinearTissuePhysicalCoordinate(
    double depthStart,
    double depthEnd,
    double width,
    double beamPosition,
    double steer,
  ) {
    _depthStart = depthStart;
    _depthEnd = depthEnd;
    _width = width;
    _beamPosition = beamPosition;
    _steer = steer;
    _logicalToPhysicalConvertBack =
        DSkewTransform(steer, 0, 0, (depthEnd - depthStart) / 2);
    _logicalToPhysicalConvert = _logicalToPhysicalConvertBack.inverse;
  }

  @override
  VidUsVisualAreaType get areaType => VidUsVisualAreaType.Tissue;

  @override
  double get depthEnd => _depthEnd;

  @override
  double get depthStart => _depthStart;

  @override
  double get width => _width;

  @override
  double get beamPosition => _beamPosition;

  /// 图像顺时针旋转的y轴旋转角度
  ///
  /// 单位：degrees
  double get steer => _steer;

  @override
  DPoint convert(DPoint pointInLogical) {
    return _logicalToPhysicalConvert.transform(pointInLogical);
  }

  @override
  DPoint convertBack(DPoint pointInPhysical) {
    return _logicalToPhysicalConvertBack.transform(pointInPhysical);
  }
}
