The CGGeometry.h file is a file implemented in C that encapsulates many common geometric methods.
A few common structural bodies
struct Cgpoint {
CGFloat x;
CGFloat y;
};
Define a point, set the x-coordinate and the y-coordinate
struct Cgsize {
CGFloat width;
CGFloat height;
};
Define a dimension, set width and height
struct Cgvector {
CGFloat DX;
CGFloat dy;
};
Define a two-dimensional vector
struct CGRect {
Cgpoint origin;
Cgsize size;
};
Define a rectangle
Ii. number of system-defined quantities
Const Cgpoint Cgpointzero
0 o'clock, equivalent to Cgpointmake (0, 0)
Const Cgsize Cgsizezero
0 dimensions, equivalent to Cgsizemake (0, 0)
Const CGRect Cgrectzero
0 rectangle, equivalent to CGRectMake (0, 0, 0, 0)
Const CGRect Cgrectnull
The empty rectangle, which is not the same as the 0 rectangle, returns an empty rectangle when we return the intersection of two disjoint rectangles.
Const CGRect Cgrectinfinite
Infinite Rectangle
Third, some common methods
Cgpoint Cgpointmake (CGFloat x, cgfloat y);
Create a point
Cgsize cgsizemake (cgfloat width, cgfloat height);
Create a dimension
Cgvectormake (cgfloat dx, cgfloat dy);
Create a vector
CGRect CGRectMake (CGFloat x, cgfloat y, cgfloat width,
CGFloat height);
Create a rectangle
CGFloat Cgrectgetminx (CGRect rect);
Get the leftmost x value of the rectangle
CGFloat cgrectgetmidx (CGRect rect);
Gets the x value of the midpoint of the rectangle
CGFloat Cgrectgetmaxx (CGRect rect);
Gets the x value of the right end of the rectangle
CGFloat cgrectgetminy (CGRect rect);
Gets the Y value at the top of the rectangle
CGFloat cgrectgetmidy (CGRect rect);
Gets the Y value of the center point of the rectangle
CGFloat cgrectgetmaxy (CGRect rect);
Gets the Y value at the bottom of the rectangle
CGFloat cgrectgetwidth (CGRect rect);
Get Rectangle width
CGFloat cgrectgetheight (CGRect rect);
Get Rectangle Height
BOOL Cgpointequaltopoint (Cgpoint point1, Cgpoint Point2);
Determine if two points are equal
BOOL Cgsizeequaltosize (cgsize size1, cgsize size2);
Determine if two dimensions are equal
BOOL Cgrectequaltorect (CGRect rect1, CGRect rect2);
Determine if two rectangles are equal
CGRect cgrectstandardize (CGRect rect);
Creates a standard rectangle based on a rectangle
BOOL Cgrectisempty (CGRect rect);
Determines whether the rectangle is zero
Cgrectisnull (CGRect rect);
Determines whether an empty rectangle
BOOL Cgrectisinfinite (CGRect rect);
Determines whether the rectangle is infinite
CGRect Cgrectinset (cgrect rect, cgfloat dx, cgfloat dy);
Creates an inline rectangle that, like the center of the rect parameter, Dx,dy corresponds to the embedded width and height
For example: CGRect rect= cgrectinset (cgrectmake (0, 0, 100, 100), 10, 10);
The rect that will be created is (10,10,80,80), Dx,dy can also be negative, then the rectangle created is larger than the original rectangle range.
CGRect cgrectintegral (CGRect rect)
Returns a rectangle of four parameters that are integers, based on a rectangle
CGRect cgrectunion (cgrect R1, cgrect R2);
Returns a set of two rectangles
CGRect cgrectintersection (cgrect R1, cgrect R2);
Returns the intersection of two rectangles, and returns an empty rectangle if there is no intersection
CGRect Cgrectoffset (cgrect rect, cgfloat dx, cgfloat dy);
Returns a rectangle with an offset relative to the RECT
void Cgrectdivide (CGRect rect, CGRect *slice, CGRect *remainder,
CGFloat amount, Cgrectedge edge);
This function is used to split the rectangle, the parameter rect is the source rectangle, the slice and remainder are the split two-part rectangle, the amount is the split line, the Edge is the split option.
Note: 1, Edge is a macro, defines the way to split the following:
| 12345678910 |
typedef & nbsp cf_enum (uint32_t, cgrectedge) { //vertically split from the smallest of x    CGRECTMINXEDGE,     Split horizontally from the smallest of y    cgrectminyedge,    //vertically split from x Max    cgrectmaxxedge, //horizontally split from Y max.    cgrectmaxyedge }; |
2, slice and remainder are addresses.
3, for example, the following will be divided into two rectangles (40,0,60,100) (0,0,40,100);
| 1234 |
CGRect rect = CGRectMake(0, 0, 100, 100); CGRect slice ; CGRect remainder; CGRectDivide(rect, &slice, &remainder, 60, CGRectMaxXEdge); |
BOOL Cgrectcontainspoint (CGRect rect, Cgpoint point);
Determines whether a point is inside a rectangle
BOOL Cgrectcontainsrect (CGRect rect1, CGRect rect2);
Determines whether the rectangle 1 contains a rectangle 2
BOOL Cgrectintersectsrect (CGRect rect1, CGRect rect2);
Determine if the rectangle 1 and Rectangle 2 intersect
Cfdictionaryref cgpointcreatedictionaryrepresentation (Cgpoint point);
Returns a dictionary that represents a point
BOOL Cgpointmakewithdictionaryrepresentation (Cfdictionaryref dict,
Cgpoint *point);
Convert a dictionary to a point
Cfdictionaryref cgsizecreatedictionaryrepresentation (cgsize size);
Returns a dictionary representing the dimensions
BOOL Cgsizemakewithdictionaryrepresentation (Cfdictionaryref dict,
Cgsize *size);
Convert a dictionary to a dimension
Cfdictionaryref cgrectcreatedictionaryrepresentation (CGRect);
Returns a dictionary that represents a rectangle
BOOL Cgrectmakewithdictionaryrepresentation (Cfdictionaryref dict,
CGRect *rect);
Convert a dictionary to a rectangle
iOS development Geometry class method CGGeometry.h file