diff --git a/Headers/Foundation/NSGeometry.h b/Headers/Foundation/NSGeometry.h index 7173c91a7..5c577e5d3 100644 --- a/Headers/Foundation/NSGeometry.h +++ b/Headers/Foundation/NSGeometry.h @@ -130,6 +130,24 @@ enum */ typedef NSUInteger NSRectEdge; +/** +{ + CGFloat top; + CGFloat left; + CGFloat bottom; + CGFloat right; +} + +

A description of the distance between the edges of two rectangles.

*/ +#if OS_API_VERSION(MAC_OS_X_VERSION_10_7, GS_API_LATEST) +typedef struct NSEdgeInsets { + CGFloat top; + CGFloat left; + CGFloat bottom; + CGFloat right; +} NSEdgeInsets; +#endif + /** Point at 0,0 */ static const NSPoint NSZeroPoint __attribute__((unused)) = {0.0,0.0}; /** Zero-size rectangle at 0,0 */ @@ -137,6 +155,11 @@ static const NSRect NSZeroRect __attribute__((unused)) = {{0.0,0.0},{0.0,0.0}}; /** Zero size */ static const NSSize NSZeroSize __attribute__((unused)) = {0.0,0.0}; +#if OS_API_VERSION(MAC_OS_X_VERSION_10_7, GS_API_LATEST) +/** Zero edge insets **/ +static const NSEdgeInsets NSEdgeInsetsZero __attribute__((unused)) = {0.0,0.0,0.0,0.0}; +#endif + /**** Function Prototypes ****************************************************/ /* @@ -200,6 +223,33 @@ NSMakeRect(CGFloat x, CGFloat y, CGFloat w, CGFloat h) return rect; } +/** Constructs NSEdgeInsets. **/ +#if OS_API_VERSION(MAC_OS_X_VERSION_10_7, GS_API_LATEST) +GS_GEOM_SCOPE NSEdgeInsets +NSEdgeInsetsMake(CGFloat top, CGFloat left, + CGFloat bottom, CGFloat right) GS_GEOM_ATTR; + +GS_GEOM_SCOPE NSEdgeInsets +NSEdgeInsetsMake(CGFloat top, CGFloat left, CGFloat bottom, CGFloat right) +{ + NSEdgeInsets edgeInsets; + + edgeInsets.top = top; + edgeInsets.left = left; + edgeInsets.bottom = bottom; + edgeInsets.right = right; + + return edgeInsets; +} + +#if OS_API_VERSION(MAC_OS_X_VERSION_10_10, GS_API_LATEST) +/** Compares two edge insets for equality. **/ +GS_EXPORT BOOL +NSEdgeInsetsEqual(NSEdgeInsets e1, NSEdgeInsets e2); +#endif + +#endif + /** Get a Rectangle's Coordinates... **/ GS_GEOM_SCOPE CGFloat diff --git a/Source/NSGeometry.m b/Source/NSGeometry.m index 267bc6d7d..9c86ce1d7 100644 --- a/Source/NSGeometry.m +++ b/Source/NSGeometry.m @@ -499,3 +499,14 @@ NSEqualPoints(NSPoint aPoint, NSPoint bPoint) && almostEqual(aPoint.y, bPoint.y)) ? YES : NO; } +BOOL +NSEdgeInsetsEqual(NSEdgeInsets e1, NSEdgeInsets e2) +{ + return ( + almostEqual(e1.top, e2.top) + && almostEqual(e1.left, e2.left) + && almostEqual(e1.bottom, e2.bottom) + && almostEqual(e1.right, e2.right) + ); +} + diff --git a/Tests/base/Functions/NSGeometry1.m b/Tests/base/Functions/NSGeometry1.m index e7d7f17c7..b474b5baf 100644 --- a/Tests/base/Functions/NSGeometry1.m +++ b/Tests/base/Functions/NSGeometry1.m @@ -21,11 +21,13 @@ geom_string() NSPoint p, p2; NSRect r, r2; NSSize s, s2; + NSEdgeInsets ei; NSString *sp, *sr, *ss; p = NSMakePoint(23.45, -3.45); r = NSMakeRect(23.45, -3.45, 2044.3, 2033); s = NSMakeSize(0.5, 0.22); + ei = NSEdgeInsetsMake(23.45, -3.45, 2044.3, 2033); PASS(NSEqualPoints(p, NSMakePoint(23.45, -3.45)), "identical points are equal"); @@ -79,6 +81,21 @@ geom_string() "an empty rect does not intersect with one touching it"); PASS(!NSIntersectsRect(NSMakeRect(1,1,0,0), NSMakeRect(1,1,0,0)), "identical empty rects do not intersec"); + + PASS(NSEdgeInsetsEqual(ei, NSEdgeInsetsMake(23.45, -3.45, 2044.3, 2033)), + "identical rects are equal"); + if (sizeof(CGFloat) == sizeof(float)) + { + PASS(NSEdgeInsetsEqual(ei, NSEdgeInsetsMake(23.45, -3.45, 2044.3, 2033.00001)), + "near identical rects are equal"); + } + else + { + PASS(NSEdgeInsetsEqual(ei, NSEdgeInsetsMake(23.45, -3.45, 2044.3, 2033.0000000000001)), + "near identical rects are equal"); + } + PASS(!NSEdgeInsetsEqual(ei, NSEdgeInsetsMake(23.45, -3.45, 2044.3, 2033.0001)), + "moderately similar rects are not equal"); #if defined(GNUSTEP_BASE_LIBRARY) if (compat_mode == YES)