GSKQuadrangle

Objective-C

@interface GSKQuadrangle : NSObject

Swift

class GSKQuadrangle : NSObject

Represents a quadrangular area of the photo, generally the document for which to correct the perspective.

A quadrangle should always be expressed in the coordinates of the “up” image

A normalized quadrangle: corners expressed in fraction of the image dimensions. Each coordinate will be a floating point between 0 and 1.

  • Unavailable

    Use one of the static constructors.

    Declaration

    Objective-C

    - (nonnull instancetype)init;
  • Returns an empty quadrangle, where the four points are equal to origin of the coordinates (0, 0).

    This quadrangle has generally no concrete use, but can be used as a marker for an invalid or missing quadrangle.

    Declaration

    Objective-C

    + (nonnull GSKQuadrangle *)emptyQuadrangle;

    Swift

    class func empty() -> GSKQuadrangle
  • Builds a full quadrangle. See isFull.

    Declaration

    Objective-C

    + (nonnull GSKQuadrangle *)fullQuadrangle;

    Swift

    class func full() -> GSKQuadrangle
  • Converts rect into a GSKQuadrangle instance.

    Declaration

    Objective-C

    + (nonnull GSKQuadrangle *)quadrangleFromCGRect:(CGRect)rect;

    Swift

    /*not inherited*/ init(from rect: CGRect)
  • Undocumented

    Declaration

    Objective-C

    + (GSKQuadrangle *)quadrangleWithTopLeft:(CGPoint)topLeft topRight:(CGPoint)topRight bottomLeft:(CGPoint)bottomLeft bottomRight:(CGPoint)bottomRight;

    Swift

    /*not inherited*/ init(topLeft: CGPoint, topRight: CGPoint, bottomLeft: CGPoint, bottomRight: CGPoint)
  • Undocumented

    Declaration

    Objective-C

    - (BOOL)isEmpty;

    Swift

    func isEmpty() -> Bool
  • Returns YES if the quadrangle encompasses the entire image, NO otherwise.

    Note that it’s only valid to call this method on a normalized quadrangle.

    Declaration

    Objective-C

    - (BOOL)isFull;

    Swift

    func isFull() -> Bool
  • Returns YES if the quadrangle is convex, NO if it’s concave. See: https://en.wikipedia.org/wiki/Convex_polygon

    Declaration

    Objective-C

    - (BOOL)isConvex;

    Swift

    func isConvex() -> Bool
  • The top left point of the quadrangle

    Declaration

    Objective-C

    @property (nonatomic, readonly) CGPoint topLeft;

    Swift

    var topLeft: CGPoint { get }
  • The bottom top right point of the quadrangle

    Declaration

    Objective-C

    @property (nonatomic, readonly) CGPoint topRight;

    Swift

    var topRight: CGPoint { get }
  • The bottom left point of the quadrangle

    Declaration

    Objective-C

    @property (nonatomic, readonly) CGPoint bottomLeft;

    Swift

    var bottomLeft: CGPoint { get }
  • The bottom right point of the quadrangle

    Declaration

    Objective-C

    @property (nonatomic, readonly) CGPoint bottomRight;

    Swift

    var bottomRight: CGPoint { get }
  • Given a normalized Quadrangle, returns a new quadrangle expressed in the given size coordinates

    Declaration

    Objective-C

    - (nonnull GSKQuadrangle *)scaleForSize:(CGSize)size;

    Swift

    func scale(for size: CGSize) -> GSKQuadrangle
  • Given a quadrangle expressed in the given size coordinates, returns a new quadrangle with normalized coordinates.

    Declaration

    Objective-C

    - (nonnull GSKQuadrangle *)normalizedWithSize:(CGSize)size;

    Swift

    func normalized(with size: CGSize) -> GSKQuadrangle
  • Given a quadrangle detected on a oriented image, this returns the quadrangle that would have been detected if once the image was rotated according to its orientation.

    IMPORTANT: this should only be applied to a normalized quadrangle

    Declaration

    Objective-C

    - (nonnull GSKQuadrangle *)rotatedForUpOrientation:
        (UIImageOrientation)orientation;

    Swift

    func rotated(forUp orientation: UIImage.Orientation) -> GSKQuadrangle
  • Converts the quadrangle back to not take in account an image orientation

    Declaration

    Objective-C

    - (nonnull GSKQuadrangle *)rotatedWithoutOrientation:
        (UIImageOrientation)orientation;

    Swift

    func rotatedWithoutOrientation(_ orientation: UIImage.Orientation) -> GSKQuadrangle
  • Ensures corners have their coordinates within [0, 1]

    Declaration

    Objective-C

    - (nonnull GSKQuadrangle *)sanitized;

    Swift

    func sanitized() -> GSKQuadrangle