@@ -73,7 +73,8 @@ private func ScaleClient(rect: inout Rect, for dpi: UINT, _ style: WindowStyle)
73
73
}
74
74
75
75
private func WindowBasedTransform( for view: View ? ) -> AffineTransform {
76
- guard var view = view else { return AffineTransform . identity }
76
+ guard var view = view else { return . identity }
77
+
77
78
var transform = AffineTransform . identity
78
79
while let superview = view. superview {
79
80
// Create a single transform that places this view in the coordinate
@@ -371,9 +372,9 @@ public class View: Responder {
371
372
/// own coordinate system.
372
373
public var bounds : Rect {
373
374
didSet {
374
- #if !ENABLE_TESTING
375
- fatalError ( " \( #function) not yet implemented " )
376
- #endif
375
+ #if !ENABLE_TESTING
376
+ fatalError ( " \( #function) not yet implemented " )
377
+ #endif
377
378
}
378
379
}
379
380
@@ -389,9 +390,9 @@ public class View: Responder {
389
390
/// bounds.
390
391
public var transform : AffineTransform = . identity {
391
392
didSet {
392
- #if !ENABLE_TESTING
393
- fatalError ( " \( #function) not yet implemented " )
394
- #endif
393
+ #if !ENABLE_TESTING
394
+ fatalError ( " \( #function) not yet implemented " )
395
+ #endif
395
396
}
396
397
}
397
398
@@ -800,8 +801,8 @@ public class View: Responder {
800
801
// center offset and transform.
801
802
if let superview = self . superview, superview == view {
802
803
// `p - self.bounds.center` undos any translation done by the bounds of
803
- // `self`. Apply the current transform to the shifted point, and
804
- // then return the point relative to `self.center`.
804
+ // `self`. Apply the current transform to the shifted point, and then
805
+ // return the point relative to `self.center`.
805
806
806
807
// +--- view ---+
807
808
// | +- self -+ |
@@ -811,15 +812,15 @@ public class View: Responder {
811
812
812
813
// `bounds` is in the coordinate space of self and `center` is in the
813
814
// coordinate space of the superview. In this case, the superview is
814
- // `view`, which is the destination coordinate space. We simply map
815
- // the transformed point p from the coordinate space of `self` into
816
- // the destination coordinate space of `view` using `self.center`.
815
+ // `view`, which is the destination coordinate space. We simply map the
816
+ // transformed point p from the coordinate space of `self` into the
817
+ // destination coordinate space of `view` using `self.center`.
817
818
return ( point - self . bounds. center) . applying ( self . transform)
818
819
+ self . center
819
820
} else if let superview = view. superview, superview == self {
820
- // `p - view.center` shifts the point relative to the center of `view`
821
- // as seen by `self`. Invert any transformations performed by `view`
822
- // on the point, and then return the point relative to the center of
821
+ // `p - view.center` shifts the point relative to the center of `view`
822
+ // as seen by `self`. Invert any transformations performed by `view` on
823
+ // the point, and then return the point relative to the center of
823
824
// `view.bounds.`
824
825
825
826
// +--- self ---+
@@ -830,9 +831,9 @@ public class View: Responder {
830
831
831
832
// `center` is in the coordinate space of the superview. Because `self`
832
833
// is the superview of `view`, `view.center` is in the coordinate space
833
- // of `self`. We locate `point` in the coordinate space of `self`,
834
- // undo any local transformation, and then relocate it in the
835
- // coordinate space of the destination view.
834
+ // of `self`. We locate `point` in the coordinate space of `self`, undo
835
+ // any local transformation, and then relocate it in the coordinate
836
+ // space of the destination view.
836
837
return ( point - view. center) . applying ( view. transform. inverted ( ) )
837
838
+ view. bounds. center
838
839
}
@@ -845,7 +846,9 @@ public class View: Responder {
845
846
/// Converts a point from the coordinate system of a given view to that of the
846
847
/// receiver.
847
848
public func convert( _ point: Point , from view: View ? ) -> Point {
848
- return view? . convert ( point, to: self ) ?? self . window? . convert ( point, to: self ) ?? point
849
+ return view? . convert ( point, to: self )
850
+ ?? self . window? . convert ( point, to: self )
851
+ ?? point
849
852
}
850
853
851
854
/// Converts a rectangle from the receiver’s coordinate system to that of
@@ -863,8 +866,8 @@ public class View: Responder {
863
866
if let superview = self . superview, superview == view {
864
867
// `r.offsetBy(dx: self.bounds.center.x, dy: self.bounds.center.y)`
865
868
// undos any translation done by the bounds property of `self`. Apply
866
- // the current transform to the rect, and then return the rect
867
- // relative to the center of `self`.
869
+ // the current transform to the rect, and then return the rect relative
870
+ // to the center of `self`.
868
871
869
872
// +--- view ---+
870
873
// | +- self -+ |
@@ -874,18 +877,18 @@ public class View: Responder {
874
877
875
878
// `bounds` is in the coordinate space of self and `center` is in the
876
879
// coordinate space of the superview. In this case, the superview is
877
- // `view`, which is the destination coordinate space. We simply map
878
- // the transformed rect r from the coordinate space of `self` into
879
- // the destination coordinate space of `view` using `self.center`.
880
+ // `view`, which is the destination coordinate space. We simply map the
881
+ // transformed rect r from the coordinate space of `self` into the
882
+ // destination coordinate space of `view` using `self.center`.
880
883
return rect. offsetBy ( dx: - self . bounds. center. x,
881
884
dy: - self . bounds. center. y)
882
885
. applying ( self . transform)
883
886
. offsetBy ( dx: self . center. x, dy: self . center. y)
884
887
} else if let superview = view. superview, superview == self {
885
888
// `r.offsetBy(dx: -view.center, dy: -view.center.y)` shifts the point
886
889
// relative to the center of `view` as seen by `self`. Invert any
887
- // transformations performed by `view` on the rect, and then return
888
- // the rect relative to the bounds of `view`.
890
+ // transformations performed by `view` on the rect, and then return the
891
+ // rect relative to the bounds of `view`.
889
892
890
893
// +--- self ---+
891
894
// | +- view -+ |
@@ -895,9 +898,9 @@ public class View: Responder {
895
898
896
899
// `center` is in the coordinate space of the superview. Because `self`
897
900
// is the superview of `view`, `view.center` is in the coordinate space
898
- // of `self`. We locate `rect` in the coordinate space of `self`,
899
- // undo any local transformation, and then relocate it in the
900
- // coordinate space of the destination view.
901
+ // of `self`. We locate `rect` in the coordinate space of `self`, undo
902
+ // any local transformation, and then relocate it in the coordinate
903
+ // space of the destination view.
901
904
return rect. offsetBy ( dx: - view. center. x, dy: - view. center. y)
902
905
. applying ( view. transform. inverted ( ) )
903
906
. offsetBy ( dx: view. bounds. center. x, dy: view. bounds. center. y)
@@ -911,7 +914,9 @@ public class View: Responder {
911
914
/// Converts a rectangle from the coordinate system of another view to that of
912
915
/// the receiver.
913
916
public func convert( _ rect: Rect , from view: View ? ) -> Rect {
914
- return view? . convert ( rect, to: self ) ?? self . window? . convert ( rect, to: self ) ?? rect
917
+ return view? . convert ( rect, to: self )
918
+ ?? self . window? . convert ( rect, to: self )
919
+ ?? rect
915
920
}
916
921
917
922
// MARK - Responder Chain
0 commit comments