Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added many missing features to NSGeometry #468

Merged
merged 6 commits into from
Nov 19, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
2024-11-18 Matvii Jarosh <matviijarosh@gmail.com>

* Source/NSGeometry.m: added NSIntegralRectWithOptions function.
* Header/Foundation/NSGeometry.h: Fixed incompatible NSRectEdge,
added enum NSAlignmentOptions, added NSRectFromCGRect,
NSRectToCGRect, NSPointFromCGPoint, NSPointToCGPoint,
NSSizeFromCGSize and NSSizeToCGSizea functions.
* MISSING:

2024-11-19 Richard Frith-Macdonald <rfm@gnu.org>

* GSMime: fixed buffer overrun in rare circumstances when decoding
142 changes: 137 additions & 5 deletions Headers/Foundation/NSGeometry.h
Original file line number Diff line number Diff line change
@@ -97,13 +97,13 @@ typedef NSRect *NSRectArray;
typedef NSRect *NSRectPointer;
#endif

enum
typedef enum
{
NSMinXEdge = 0,
NSMinYEdge = 1,
NSMaxXEdge = 2,
NSMaxYEdge = 3
};
} NSRectEdge;
/** Sides of a rectangle.
<example>
{
@@ -113,8 +113,72 @@ enum
NSMaxYEdge
}
</example>
*/
typedef NSUInteger NSRectEdge;
<p>NSRectEdge</p>*/
// typedef NSUInteger NSRectEdge;
/** A value representing the alignment process
<example>
{
NSAlignMinXInward,
NSAlignMinYInward,
NSAlignMaxXInward,
NSAlignMaxYInward,
NSAlignWidthInward,
NSAlignHeightInward,
NSAlignMinXOutward,
NSAlignMinYOutward,
NSAlignMaxXOutward,
NSAlignMaxYOutward,
NSAlignWidthOutward,
NSAlignHeightOutward,
NSAlignMinXNearest,
NSAlignMinYNearest,
NSAlignMaxXNearest,
NSAlignMaxYNearest,
NSAlignWidthNearest,
NSAlignHeightNearest,
NSAlignRectFlipped,
NSAlignAllEdgesInward,
NSAlignAllEdgesOutward,
NSAlignAllEdgesNearest
}
</example>
<p>NSAlignmentOptions</p>*/
#if OS_API_VERSION(MAC_OS_X_VERSION_10_7, GS_API_LATEST)
typedef enum
{
NSAlignMinXInward = 1ULL << 0,
NSAlignMinYInward = 1ULL << 1,
NSAlignMaxXInward = 1ULL << 2,
NSAlignMaxYInward = 1ULL << 3,
NSAlignWidthInward = 1ULL << 4,
NSAlignHeightInward = 1ULL << 5,
NSAlignMinXOutward = 1ULL << 8,
NSAlignMinYOutward = 1ULL << 9,
NSAlignMaxXOutward = 1ULL << 10,
NSAlignMaxYOutward = 1ULL << 11,
NSAlignWidthOutward = 1ULL << 12,
NSAlignHeightOutward = 1ULL << 13,
NSAlignMinXNearest = 1ULL << 16,
NSAlignMinYNearest = 1ULL << 17,
NSAlignMaxXNearest = 1ULL << 18,
NSAlignMaxYNearest = 1ULL << 19,
NSAlignWidthNearest = 1ULL << 20,
NSAlignHeightNearest = 1ULL << 21,
NSAlignRectFlipped = 1ULL << 63,
NSAlignAllEdgesInward = NSAlignMinXInward
| NSAlignMaxXInward
| NSAlignMinYInward
| NSAlignMaxYInward,
NSAlignAllEdgesOutward = NSAlignMinXOutward
| NSAlignMaxXOutward
| NSAlignMinYOutward
| NSAlignMaxYOutward,
NSAlignAllEdgesNearest = NSAlignMinXNearest
| NSAlignMaxXNearest
| NSAlignMinYNearest
| NSAlignMaxYNearest
} NSAlignmentOptions;
#endif

/**
<example>{
@@ -195,7 +259,7 @@ NSMakeSize(CGFloat w, CGFloat h)

GS_GEOM_SCOPE NSRect
NSMakeRect(CGFloat x, CGFloat y, CGFloat w, CGFloat h) GS_GEOM_ATTR;

/** Returns an NSRect having point of origin (x, y) and size {w, h}. */
GS_GEOM_SCOPE NSRect
NSMakeRect(CGFloat x, CGFloat y, CGFloat w, CGFloat h)
@@ -209,6 +273,68 @@ NSMakeRect(CGFloat x, CGFloat y, CGFloat w, CGFloat h)
return rect;
}

#if OS_API_VERSION(MAC_OS_X_VERSION_10_5, GS_API_LATEST)
GS_GEOM_SCOPE NSRect
NSRectFromCGRect(CGRect rect) GS_GEOM_ATTR;

/** Return an NSRect from CGRect. **/
GS_GEOM_SCOPE NSRect
NSRectFromCGRect(CGRect rect)
{
return (NSRect)rect;
}

GS_GEOM_SCOPE CGRect
NSRectToCGRect(NSRect rect) GS_GEOM_ATTR;

/** Return an CGRect from NSRect. **/
GS_GEOM_SCOPE CGRect
NSRectToCGRect(NSRect rect)
{
return (CGRect)rect;
}

GS_GEOM_SCOPE NSPoint
NSPointFromCGPoint(CGPoint point) GS_GEOM_ATTR;

/** Return an NSPoint from CGPoint **/
GS_GEOM_SCOPE NSPoint
NSPointFromCGPoint(CGPoint point)
{
return (NSPoint)point;
}

GS_GEOM_SCOPE CGPoint
NSPointToCGPoint(NSPoint point) GS_GEOM_ATTR;

/** Return an CGPoint from NSPoint **/
GS_GEOM_SCOPE CGPoint
NSPointToCGPoint(NSPoint point)
{
return (CGPoint)point;
}

GS_GEOM_SCOPE NSSize
NSSizeFromCGSize(CGSize size) GS_GEOM_ATTR;

/** Return an NSSize from CGSize **/
GS_GEOM_SCOPE NSSize
NSSizeFromCGSize(CGSize size)
{
return (NSSize)size;
}

GS_GEOM_SCOPE CGSize
NSSizeToCGSize(NSSize size) GS_GEOM_ATTR;

/** Return an CGSize from NSSize **/
GS_GEOM_SCOPE CGSize
NSSizeToCGSize(NSSize size)
{
return (CGSize)size;
}
#endif

/** Constructs NSEdgeInsets. **/
#if OS_API_VERSION(MAC_OS_X_VERSION_10_7, GS_API_LATEST)
GS_GEOM_SCOPE NSEdgeInsets
@@ -382,6 +508,12 @@ NSDivideRect(NSRect aRect,
GS_EXPORT NSRect
NSIntegralRect(NSRect aRect);

/** Returns a rectangle obtained by expanding aRect minimally
* so that all four of its defining components are integers,
* using the specified alignment options to control rounding behavior. */
GS_EXPORT NSRect
NSIntegralRectWithOptions(NSRect aRect, NSAlignmentOptions options);

/** Compute a Third Rectangle from Two Rectangles... **/

GS_GEOM_SCOPE NSRect
11 changes: 0 additions & 11 deletions MISSING
Original file line number Diff line number Diff line change
@@ -221,19 +221,8 @@ NSGeometry:
<Foundation/NSValue.h>
<Foundation/NSCoder.h>

incompatible NSRectEdge
NSAlignmentOptions

@class NSString

NSRectFromCGRect()
NSRectToCGRect()
NSPointFromCGPoint()
NSPointToCGPoint()
NSSizeFromCGSize()
NSSizeToCGSize()
NSIntegralRectWithOptions()

@interface NSValue (NSValueGeometryExtensions)
@interface NSCoder (NSGeometryCoding)
@interface NSCoder (NSGeometryKeyedCoding)
45 changes: 44 additions & 1 deletion Source/NSGeometry.m
Original file line number Diff line number Diff line change
@@ -100,6 +100,50 @@ static BOOL GSMacOSXCompatibleGeometry(void)
return rect;
}

NSRect
NSIntegralRectWithOptions(NSRect aRect, NSAlignmentOptions options)
{
NSRect rect;
CGFloat maxX, maxY;

if (NSIsEmptyRect(aRect))
return NSMakeRect(0, 0, 0, 0);

if (options & NSAlignMinXInward)
rect.origin.x = ceil(NSMinX(aRect));
else if (options & NSAlignMinXOutward)
rect.origin.x = floor(NSMinX(aRect));
else
rect.origin.x = round(NSMinX(aRect));

if (options & NSAlignMinYInward)
rect.origin.y = ceil(NSMinY(aRect));
else if (options & NSAlignMinYOutward)
rect.origin.y = floor(NSMinY(aRect));
else
rect.origin.y = round(NSMinY(aRect));

if (options & NSAlignMaxXInward)
maxX = floor(NSMaxX(aRect));
else if (options & NSAlignMaxXOutward)
maxX = ceil(NSMaxX(aRect));
else
maxX = round(NSMaxX(aRect));

if (options & NSAlignMaxYInward)
maxY = floor(NSMaxY(aRect));
else if (options & NSAlignMaxYOutward)
maxY = ceil(NSMaxY(aRect));
else
maxY = round(NSMaxY(aRect));

rect.size.width = maxX - rect.origin.x;
rect.size.height = maxY - rect.origin.y;

return rect;
}


void
NSDivideRect(NSRect aRect,
NSRect *slice,
@@ -508,4 +552,3 @@ read our strings (Both GNUstep and Mac OS X can read these as well). */
&& almostEqual(e1.right, e2.right)
);
}