PTPDFRect
@interface PTPDFRect : NSObject
Rect is a utility class used to manipulate PDF rectangle objects (refer to section 3.8.3 of the PDF Reference Manual).
Rect can be associated with a SDF/Cos rectangle array using Rect(Obj*) constructor or later using Rect::Attach(Obj*) or Rect::Update(Obj*) methods.
Rect keeps a local cache for rectangle points so it is necessary to call Rect::Update() method if the changes to the Rect should be saved in the attached Cos/SDF array.
Note
- Although rectangles are conventionally specified by their lower-left and upper-right corners, it is acceptable to specify any two diagonally opposite corners.-
Rect default constructor.
Declaration
Objective-C
- (instancetype)init;
Swift
init!()
-
Undocumented
Declaration
Objective-C
- (instancetype)initWithX1: (double)x1 y1: (double)y1 x2: (double)x2 y2: (double)y2;
Swift
init!(x1: Double, y1: Double, x2: Double, y2: Double)
-
Saves changes made to the Rect object in the attached (or specified) SDF/Cos rectangle.
Parameters
obj
- an optional parameter indicating a SDF array that should be updated and attached to this Rect. If parameter rect is NULL or is omitted, update is performed on previously attached Cos/SDF rectangle.
Return Value
true if the attached Cos/SDF rectangle array was successfully updated, false otherwise.
-
Set the coordinates of the rectangle
Declaration
Objective-C
- (void)Set:(double)x1 y1:(double)y1 x2:(double)x2 y2:(double)y2;
Swift
func set(_ x1: Double, y1: Double, x2: Double, y2: Double)
Parameters
x1
The left-most position of the rect.
y1
The bottom-most position of the rect.
x2
The right-most position of the rect.
y2
The top-most position of the rect. The rect is not attached to any Cos/SDF object.
-
Declaration
Objective-C
- (double)Width;
Swift
func width() -> Double
Return Value
rectangle’s width
-
Declaration
Objective-C
- (double)Height;
Swift
func height() -> Double
Return Value
rectangle’s height
-
Determines if the specified point is contained within the rectangular region defined by this Rectangle
Declaration
Objective-C
- (BOOL)Contains:(double)x y:(double)y;
Swift
func contains(_ x: Double, y: Double) -> Bool
Parameters
x
horizontal x value of the point to check
y
vertical y value of the point to check
Return Value
true is the point is in the rectangle, false otherwise.
-
Makes a Rect equal to the intersection of two existing rectangles.
Note
The intersection is the largest rectangle contained in both existing rectangles.
Declaration
Objective-C
- (BOOL)IntersectRect:(PTPDFRect *)rect1 rect2:(PTPDFRect *)rect2;
Swift
func intersect(_ rect1: PTPDFRect!, rect2: PTPDFRect!) -> Bool
Parameters
rect1
- A Rect object that contains a source rectangle.
rect2
- A Rect object that contains a source rectangle.
Return Value
true if the intersection is not empty; 0 if the intersection is empty.
-
Arrange the points in the rectangle so that the first point is the lower-left corner and the second point is the upper-right corner of the rectangle.
Note
Although rectangles are conventionally specified by their lower-left and upper-right corners, it is acceptable to specify any two diagonally opposite corners.Declaration
Objective-C
- (void)Normalize;
Swift
func normalize()
-
Expands the rectangle by the specified size, in all directions.
Declaration
Objective-C
- (void)InflateWithAmount:(double)amount;
Swift
func inflate(withAmount amount: Double)
Parameters
amount
Specifies the amount to increase the rectangle in all directions.
-
Expands the rectangle by the specified size, in all directions.
Declaration
Objective-C
- (void)InflateWithXY:(double)x y:(double)y;
Swift
func inflate(withXY x: Double, y: Double)
Parameters
x
Specifies the amount to increase the rectangle’s Left (x1) and Right (x2) properties.
y
Specifies the amount to increase the rectangle’s Top (y1) and Bottom (y2) properties.
-
Declaration
Objective-C
- (double)GetX1;
Swift
func getX1() -> Double
Return Value
The horizontal value of lower-left point.
-
Declaration
Objective-C
- (double)GetY1;
Swift
func getY1() -> Double
Return Value
The vertical value of lower-left point.
-
Declaration
Objective-C
- (double)GetX2;
Swift
func getX2() -> Double
Return Value
The horizontal value of upper-right point.
-
Declaration
Objective-C
- (double)GetY2;
Swift
func getY2() -> Double
Return Value
The vertical value of upper-right point.
-
Set the horizontal value of lower-left point.
Declaration
Objective-C
- (void)SetX1:(double)x1;
Swift
func setX1(_ x1: Double)
Parameters
x1
The left-most position of the rect.
-
Set the vertical value of lower-left point.
Declaration
Objective-C
- (void)SetY1:(double)y1;
Swift
func setY1(_ y1: Double)
Parameters
y1
The bottom-most position of the rect.
-
Set the horizontal value of upper-right point.
Declaration
Objective-C
- (void)SetX2:(double)x2;
Swift
func setX2(_ x2: Double)
Parameters
x2
The right-most position of the rect.
-
Set the vertical value of upper-right point.
Declaration
Objective-C
- (void)SetY2:(double)y2;
Swift
func setY2(_ y2: Double)
Parameters
y2
The top-most position of the rect.
-
The x-coordinate of the rect’s first point (bottom-left in a normalized rect).
Declaration
Objective-C
@property (nonatomic, assign, unsafe_unretained, readwrite, getter=PT_x1, setter=PT_setX1:) double x1;
Swift
var x1: Double { get set }
-
The y-coordinate of the rect’s first point (bottom-left in a normalized rect).
Declaration
Objective-C
@property (nonatomic, assign, unsafe_unretained, readwrite, getter=PT_y1, setter=PT_setY1:) double y1;
Swift
var y1: Double { get set }
-
The x-coordinate of the rect’s second point (top-right in a normalized rect).
Declaration
Objective-C
@property (nonatomic, assign, unsafe_unretained, readwrite, getter=PT_x2, setter=PT_setX2:) double x2;
Swift
var x2: Double { get set }
-
The y-coordinate of the rect’s second point (top-right in a normalized rect).
Declaration
Objective-C
@property (nonatomic, assign, unsafe_unretained, readwrite, getter=PT_y2, setter=PT_setY2:) double y2;
Swift
var y2: Double { get set }
-
The width of the rect.
Declaration
Objective-C
@property (nonatomic, readonly, getter=PT_width) double width;
-
The height of the rect.
Declaration
Objective-C
@property (nonatomic, readonly, getter=PT_height) double height;
-
The rect’s first point (bottom-left in a normalized rect).
Declaration
Objective-C
@property (nonatomic, strong, getter=PT_p1, setter=PT_setP1:) PTPDFPoint *_Nonnull p1;
Swift
var p1: PTPDFPoint { get set }
-
The rect’s second point (top-right in a normalized rect).
Declaration
Objective-C
@property (nonatomic, strong, getter=PT_p2, setter=PT_setP2:) PTPDFPoint *_Nonnull p2;
Swift
var p2: PTPDFPoint { get set }
-
Initializes a newly created
PTPDFRect
instance with the specified points.Declaration
Objective-C
- (nonnull instancetype)initWithP1:(nonnull PTPDFPoint *)p1 p2:(nonnull PTPDFPoint *)p2;
Swift
init(p1: PTPDFPoint, p2: PTPDFPoint)
Parameters
p1
The first point of the rect.
p2
The second point of the rect.
Return Value
an initialized
PTPDFRect
instance
-
Returns a normalized copy of this rect.
Declaration
Objective-C
- (nonnull PTPDFRect *)NormalizedRect;
Swift
func normalized() -> PTPDFRect
Return Value
a normalized copy of this rect
-
Returns a copy of this rect.
Declaration
Objective-C
- (nonnull instancetype)copy;
Swift
func copy() -> Self
Return Value
a copy of this rect
-
The value of this rect represented as a
CGRect
.Declaration
Objective-C
@property (nonatomic, readonly) CGRect CGRectValue;
Swift
var cgRectValue: CGRect { get }
-
Creates a new
PTPDFRect
instance from the specifiedCGRect
value.Declaration
Objective-C
+ (nonnull instancetype)rectFromCGRect:(CGRect)cgRect;
Swift
convenience init(from cgRect: CGRect)
Parameters
cgRect
The
CGRect
valueReturn Value
a new
PTPDFRect
instance -
Initializes a newly create
PTPDFRect
instance with the specifiedCGRect
value.Declaration
Objective-C
- (nonnull instancetype)initWithCGRect:(CGRect)cgRect;
Swift
init(cgRect: CGRect)
Parameters
cgRect
The
CGRect
value.Return Value
an initialized
PTPDFRect
instance -
Returns a new
PTPDFRect
instance that encompasses the specifiedpoints
.Declaration
Objective-C
+ (nullable PTPDFRect *)boundingBoxForPoints: (nonnull NSArray<PTPDFPoint *> *)points;
Swift
class func boundingBox(for points: [PTPDFPoint]) -> PTPDFRect?
Parameters
points
The points for which to calculate a bounding box
Return Value
a new
PTPDFRect
bounding box, ornil
if an error occurred -
The four vertices of this rect, in counter-clockwise order starting with the bottom-left vertex.
Note
The points are created from a normalized copy of this rect.Declaration
Objective-C
@property (nonatomic, readonly) NSArray<PTPDFPoint *> *_Nonnull points;
Swift
var points: [PTPDFPoint] { get }
-
The center point of this rect.
Declaration
Objective-C
@property (nonatomic, strong, readonly) PTPDFPoint *_Nonnull center;
Swift
var center: PTPDFPoint { get }