diff --git a/AppKit/AppKit.j b/AppKit/AppKit.j index 39204cc56..27f3a3001 100644 --- a/AppKit/AppKit.j +++ b/AppKit/AppKit.j @@ -22,6 +22,7 @@ @import "_CPToolTip.j" @import "CALayer.j" +@import "CGGeometry.j" @import "CPAccordionView.j" @import "CPAlert.j" @import "CPAnimation.j" diff --git a/AppKit/CoreGraphics/CGAffineTransform.h b/AppKit/CoreGraphics/CGAffineTransform.h index 1b3fc9266..4eea12e67 100644 --- a/AppKit/CoreGraphics/CGAffineTransform.h +++ b/AppKit/CoreGraphics/CGAffineTransform.h @@ -20,7 +20,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "CGGeometry.h" +#include "../../Foundation/_CGGeometry.h" #define _CGAffineTransformMake(a_, b_, c_, d_, tx_, ty_) { a:a_, b:b_, c:c_, d:d_, tx:tx_, ty:ty_ } #define _CGAffineTransformMakeIdentity() _CGAffineTransformMake(1.0, 0.0, 0.0, 1.0, 0.0, 0.0) diff --git a/AppKit/CoreGraphics/CGGeometry.j b/AppKit/CoreGraphics/CGGeometry.j index 957662a00..bdefc9bd6 100644 --- a/AppKit/CoreGraphics/CGGeometry.j +++ b/AppKit/CoreGraphics/CGGeometry.j @@ -2,8 +2,8 @@ * CGGeometry.j * AppKit * - * Created by Francisco Tolmasky. - * Copyright 2008, 280 North, Inc. + * Created by Alexander Ljungberg. + * Copyright 2012, SlevenBits Ltd. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -20,301 +20,4 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#define _function(inline) function inline { return _##inline; } - -_function(CGPointMake(x, y)) -_function(CGPointMakeZero()) -_function(CGPointMakeCopy(aPoint)) -_function(CGPointCreateCopy(aPoint)) - -_function(CGPointEqualToPoint(lhsPoint, rhsPoint)) -_function(CGStringFromPoint(aPoint)) - -_function(CGSizeMake(width, height)) -_function(CGSizeMakeZero()) -_function(CGSizeMakeCopy(aSize)) -_function(CGSizeCreateCopy(aSize)) - -_function(CGSizeEqualToSize(lhsSize, rhsSize)) -_function(CGStringFromSize(aSize)) - -_function(CGRectMake(x, y, width, height)) -_function(CGRectMakeZero()) -_function(CGRectMakeCopy(aRect)) -_function(CGRectCreateCopy(aRect)) - -_function(CGRectEqualToRect(lhsRect, rhsRect)) -_function(CGStringFromRect(aRect)) - -_function(CGRectOffset(aRect, dX, dY)) -_function(CGRectInset(aRect, dX, dY)) - -_function(CGRectGetHeight(aRect)) -_function(CGRectGetMaxX(aRect)) -_function(CGRectGetMaxY(aRect)) -_function(CGRectGetMidX(aRect)) -_function(CGRectGetMidY(aRect)) -_function(CGRectGetMinX(aRect)) -_function(CGRectGetMinY(aRect)) -_function(CGRectGetWidth(aRect)) - -_function(CGRectIsEmpty(aRect)) -_function(CGRectIsNull(aRect)) - -_function(CGRectContainsPoint(aRect, aPoint)) - -_function(CGInsetMake(top, right, bottom, left)) -_function(CGInsetMakeZero()) -_function(CGInsetMakeCopy(anInset)) -_function(CGInsetIsEmpty(anInset)) -_function(CGInsetEqualToInset(lhsInset, rhsInset)) - -CGMinXEdge = 0; -CGMinYEdge = 1; -CGMaxXEdge = 2; -CGMaxYEdge = 3; - -CGRectNull = _CGRectMake(Infinity, Infinity, 0.0, 0.0); - -/*! - @addtogroup appkit - @{ -*/ - -/*! - Creates two rectangles -- slice and rem -- from inRect, by dividing inRect - with a line that's parallel to the side of inRect specified by edge. - The size of slice is determined by amount, which specifies the distance from edge. - - slice and rem must not be NULL, must not be the same object, and must not be the - same object as inRect. - - @group CGRect -*/ -function CGRectDivide(inRect, slice, rem, amount, edge) -{ - slice.origin = _CGPointMakeCopy(inRect.origin); - slice.size = _CGSizeMakeCopy(inRect.size); - rem.origin = _CGPointMakeCopy(inRect.origin); - rem.size = _CGSizeMakeCopy(inRect.size); - - switch (edge) - { - case CGMinXEdge: - slice.size.width = amount; - rem.origin.x += amount; - rem.size.width -= amount; - break; - - case CGMaxXEdge: - slice.origin.x = _CGRectGetMaxX(slice) - amount; - slice.size.width = amount; - rem.size.width -= amount; - break; - - case CGMinYEdge: - slice.size.height = amount; - rem.origin.y += amount; - rem.size.height -= amount; - break; - - case CGMaxYEdge: - slice.origin.y = _CGRectGetMaxY(slice) - amount; - slice.size.height = amount; - rem.size.height -= amount; - } -} - -/*! - Returns a \c BOOL indicating whether CGRect \c lhsRect - contains CGRect \c rhsRect. - @group CGRect - @param lhsRect the CGRect to test if \c rhsRect is inside of - @param rhsRect the CGRect to test if it fits inside \c lhsRect. - @return BOOL \c YES if \c rhsRect fits inside \c lhsRect. -*/ -function CGRectContainsRect(lhsRect, rhsRect) -{ - var union = CGRectUnion(lhsRect, rhsRect); - - return _CGRectEqualToRect(union, lhsRect); -} - -/*! - Returns \c YES if the two rectangles intersect - @group CGRect - @param lhsRect the first CGRect - @param rhsRect the second CGRect - @return BOOL \c YES if the two rectangles have any common spaces, and \c NO, otherwise. -*/ -function CGRectIntersectsRect(lhsRect, rhsRect) -{ - var intersection = CGRectIntersection(lhsRect, rhsRect); - - return !_CGRectIsEmpty(intersection); -} - -/*! - Makes the origin and size of a CGRect all integers. Specifically, by making - the southwest corner the origin (rounded down), and the northeast corner a CGSize (rounded up). - @param aRect the rectangle to operate on - @return CGRect the modified rectangle (same as the input) - @group CGRect -*/ -function CGRectIntegral(aRect) -{ - aRect = CGRectStandardize(aRect); - - // Store these out separately, if not the GetMaxes will return incorrect values. - var x = FLOOR(_CGRectGetMinX(aRect)), - y = FLOOR(_CGRectGetMinY(aRect)); - - aRect.size.width = CEIL(_CGRectGetMaxX(aRect)) - x; - aRect.size.height = CEIL(_CGRectGetMaxY(aRect)) - y; - - aRect.origin.x = x; - aRect.origin.y = y; - - return aRect; -} - -/*! - Returns the intersection of the two provided rectangles as a new rectangle. - @param lhsRect the first rectangle used for calculation - @param rhsRect the second rectangle used for calculation - @return CGRect the intersection of the two rectangles - @group CGRect -*/ -function CGRectIntersection(lhsRect, rhsRect) -{ - var intersection = _CGRectMake( - MAX(_CGRectGetMinX(lhsRect), _CGRectGetMinX(rhsRect)), - MAX(_CGRectGetMinY(lhsRect), _CGRectGetMinY(rhsRect)), - 0, 0); - - intersection.size.width = MIN(_CGRectGetMaxX(lhsRect), _CGRectGetMaxX(rhsRect)) - _CGRectGetMinX(intersection); - intersection.size.height = MIN(_CGRectGetMaxY(lhsRect), _CGRectGetMaxY(rhsRect)) - _CGRectGetMinY(intersection); - - return _CGRectIsEmpty(intersection) ? _CGRectMakeZero() : intersection; -} - -/* - -*/ -function CGRectStandardize(aRect) -{ - var width = _CGRectGetWidth(aRect), - height = _CGRectGetHeight(aRect), - standardized = _CGRectMakeCopy(aRect); - - if (width < 0.0) - { - standardized.origin.x += width; - standardized.size.width = -width; - } - - if (height < 0.0) - { - standardized.origin.y += height; - standardized.size.height = -height; - } - - return standardized; -} - -function CGRectUnion(lhsRect, rhsRect) -{ - var lhsRectIsNull = !lhsRect || lhsRect === CGRectNull, - rhsRectIsNull = !rhsRect || rhsRect === CGRectNull; - - if (lhsRectIsNull) - return rhsRectIsNull ? CGRectNull : rhsRect; - - if (rhsRectIsNull) - return lhsRectIsNull ? CGRectNull : lhsRect; - - var minX = MIN(_CGRectGetMinX(lhsRect), _CGRectGetMinX(rhsRect)), - minY = MIN(_CGRectGetMinY(lhsRect), _CGRectGetMinY(rhsRect)), - maxX = MAX(_CGRectGetMaxX(lhsRect), _CGRectGetMaxX(rhsRect)), - maxY = MAX(_CGRectGetMaxY(lhsRect), _CGRectGetMaxY(rhsRect)); - - return _CGRectMake(minX, minY, maxX - minX, maxY - minY); -} - -/*! - Returns the specified rectangle inset by the given CGInset as a new rectangle. - @param aRect the rect to inset - @param anInset a CGInset to inset by - @return CGRect aRect inset by anInset -*/ -_function(CGRectInsetByInset(aRect, anInset)); - -function CGPointFromString(aString) -{ - var comma = aString.indexOf(','); - - return { x:parseFloat(aString.substr(1, comma - 1)), y:parseFloat(aString.substring(comma + 1, aString.length)) }; -} - -function CGSizeFromString(aString) -{ - var comma = aString.indexOf(','); - - return { width:parseFloat(aString.substr(1, comma - 1)), height:parseFloat(aString.substring(comma + 1, aString.length)) }; -} - -function CGRectFromString(aString) -{ - var comma = aString.indexOf(',', aString.indexOf(',') + 1); - - return { origin:CGPointFromString(aString.substr(1, comma - 1)), size:CGSizeFromString(aString.substring(comma + 2, aString.length)) }; -} - -function CGPointFromEvent(anEvent) -{ - return _CGPointMake(anEvent.clientX, anEvent.clientY); -} - -/*! - Combines two insets by adding their individual elements and returns the result. - - @group CGInset -*/ -function CGInsetUnion(lhsInset, rhsInset) -{ - return _CGInsetMake(lhsInset.top + rhsInset.top, - lhsInset.right + rhsInset.right, - lhsInset.bottom + rhsInset.bottom, - lhsInset.left + rhsInset.left); -} - -/*! - Subtract one inset from another by subtracting their individual elements and returns the result. - - @group CGInset -*/ -function CGInsetDifference(lhsInset, rhsInset) -{ - return _CGInsetMake(lhsInset.top - rhsInset.top, - lhsInset.right - rhsInset.right, - lhsInset.bottom - rhsInset.bottom, - lhsInset.left - rhsInset.left); -} - -function CGInsetFromString(aString) -{ - var numbers = aString.substr(1, aString.length - 2).split(','); - - return _CGInsetMake(parseFloat(numbers[0]), parseFloat(numbers[1]), parseFloat(numbers[2]), parseFloat(numbers[3])); -} - -CGInsetFromCPString = CGInsetFromString; - -function CPStringFromCGInset(anInset) -{ - return '{' + anInset.top + ", " + anInset.left + ", " + anInset.bottom + ", " + anInset.right + '}'; -} - -/*! - @} -*/ +@import diff --git a/Foundation/CPGeometry.j b/Foundation/CPGeometry.j index fc05cbe75..ba3c249f4 100644 --- a/Foundation/CPGeometry.j +++ b/Foundation/CPGeometry.j @@ -1,6 +1,6 @@ /* * CPGeometry.j - * AppKit + * Foundation * * Created by Francisco Tolmasky. * Copyright 2008, 280 North, Inc. @@ -20,7 +20,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -@import +@import "_CGGeometry.j"         CPMinXEdge = 0; CPMinYEdge = 1; diff --git a/Foundation/Jakefile b/Foundation/Jakefile index 90a5bdba9..20d218c9e 100644 --- a/Foundation/Jakefile +++ b/Foundation/Jakefile @@ -42,7 +42,13 @@ foundationTask = framework ("Foundation", function(foundationTask) foundationTask.setInfoPlistPath("Info.plist"); foundationTask.setEnvironments(require("objective-j/jake/environment").ObjJ); - var INCLUDES = "--include \"../AppKit/Platform/Platform.h\" --include \"Ref.h\""; + // Grab all the .h's and just include them in each file. + var INCLUDES = new FileList("**/*.h").map(function(aFilename) + { + return "--include \"" + aFilename + "\""; + }).join(" "); + + INCLUDES = "--include \"../AppKit/Platform/Platform.h\" " + INCLUDES; if ($CONFIGURATION === "Release") foundationTask.setCompilerFlags("-O " + INCLUDES); diff --git a/AppKit/CoreGraphics/CGGeometry.h b/Foundation/_CGGeometry.h similarity index 91% rename from AppKit/CoreGraphics/CGGeometry.h rename to Foundation/_CGGeometry.h index f66a82d32..5ea60e41c 100644 --- a/AppKit/CoreGraphics/CGGeometry.h +++ b/Foundation/_CGGeometry.h @@ -1,6 +1,6 @@ /* * CGGeometry.h - * AppKit + * Foundation * * Created by Francisco Tolmasky. * Copyright 2008, 280 North, Inc. @@ -20,6 +20,12 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +/* + +CGGeometry is not a part of Foundation. The reason _CGGeometry.h exists, and is in Foundation, is that CPGeometry and CGGeometry both use the same code so the shared basis needs to be in the lowest layer. If for some reason Cappuccino was ever reimplemented such that CPRect !== CGRect etc, this class could be removed and CPGeometry.j and CGGeometry.j updated with relevant functions without breaking any client code. + +*/ + #define _CGPointMake(x_, y_) { x:x_, y:y_ } #define _CGPointMakeCopy(aPoint) _CGPointMake(aPoint.x, aPoint.y) #define _CGPointMakeZero() _CGPointMake(0.0, 0.0) diff --git a/Foundation/_CGGeometry.j b/Foundation/_CGGeometry.j new file mode 100644 index 000000000..bbb116d9b --- /dev/null +++ b/Foundation/_CGGeometry.j @@ -0,0 +1,326 @@ +/* + * _CGGeometry.j + * Foundation + * + * Created by Francisco Tolmasky. + * Copyright 2008, 280 North, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/* + +CGGeometry is not a part of Foundation. The reason _CGGeometry.j exists, and is in Foundation, is that CPGeometry and CGGeometry both use the same code so the shared basis needs to be in the lowest layer. If for some reason Cappuccino was ever reimplemented such that CPRect !== CGRect etc, this class could be removed and CPGeometry.j and CGGeometry.j updated with relevant functions without breaking any client code. + +*/ + +#define _function(inline) function inline { return _##inline; } + +_function(CGPointMake(x, y)) +_function(CGPointMakeZero()) +_function(CGPointMakeCopy(aPoint)) +_function(CGPointCreateCopy(aPoint)) + +_function(CGPointEqualToPoint(lhsPoint, rhsPoint)) +_function(CGStringFromPoint(aPoint)) + +_function(CGSizeMake(width, height)) +_function(CGSizeMakeZero()) +_function(CGSizeMakeCopy(aSize)) +_function(CGSizeCreateCopy(aSize)) + +_function(CGSizeEqualToSize(lhsSize, rhsSize)) +_function(CGStringFromSize(aSize)) + +_function(CGRectMake(x, y, width, height)) +_function(CGRectMakeZero()) +_function(CGRectMakeCopy(aRect)) +_function(CGRectCreateCopy(aRect)) + +_function(CGRectEqualToRect(lhsRect, rhsRect)) +_function(CGStringFromRect(aRect)) + +_function(CGRectOffset(aRect, dX, dY)) +_function(CGRectInset(aRect, dX, dY)) + +_function(CGRectGetHeight(aRect)) +_function(CGRectGetMaxX(aRect)) +_function(CGRectGetMaxY(aRect)) +_function(CGRectGetMidX(aRect)) +_function(CGRectGetMidY(aRect)) +_function(CGRectGetMinX(aRect)) +_function(CGRectGetMinY(aRect)) +_function(CGRectGetWidth(aRect)) + +_function(CGRectIsEmpty(aRect)) +_function(CGRectIsNull(aRect)) + +_function(CGRectContainsPoint(aRect, aPoint)) + +_function(CGInsetMake(top, right, bottom, left)) +_function(CGInsetMakeZero()) +_function(CGInsetMakeCopy(anInset)) +_function(CGInsetIsEmpty(anInset)) +_function(CGInsetEqualToInset(lhsInset, rhsInset)) + +CGMinXEdge = 0; +CGMinYEdge = 1; +CGMaxXEdge = 2; +CGMaxYEdge = 3; + +CGRectNull = _CGRectMake(Infinity, Infinity, 0.0, 0.0); + +/*! + @addtogroup appkit + @{ +*/ + +/*! + Creates two rectangles -- slice and rem -- from inRect, by dividing inRect + with a line that's parallel to the side of inRect specified by edge. + The size of slice is determined by amount, which specifies the distance from edge. + + slice and rem must not be NULL, must not be the same object, and must not be the + same object as inRect. + + @group CGRect +*/ +function CGRectDivide(inRect, slice, rem, amount, edge) +{ + slice.origin = _CGPointMakeCopy(inRect.origin); + slice.size = _CGSizeMakeCopy(inRect.size); + rem.origin = _CGPointMakeCopy(inRect.origin); + rem.size = _CGSizeMakeCopy(inRect.size); + + switch (edge) + { + case CGMinXEdge: + slice.size.width = amount; + rem.origin.x += amount; + rem.size.width -= amount; + break; + + case CGMaxXEdge: + slice.origin.x = _CGRectGetMaxX(slice) - amount; + slice.size.width = amount; + rem.size.width -= amount; + break; + + case CGMinYEdge: + slice.size.height = amount; + rem.origin.y += amount; + rem.size.height -= amount; + break; + + case CGMaxYEdge: + slice.origin.y = _CGRectGetMaxY(slice) - amount; + slice.size.height = amount; + rem.size.height -= amount; + } +} + +/*! + Returns a \c BOOL indicating whether CGRect \c lhsRect + contains CGRect \c rhsRect. + @group CGRect + @param lhsRect the CGRect to test if \c rhsRect is inside of + @param rhsRect the CGRect to test if it fits inside \c lhsRect. + @return BOOL \c YES if \c rhsRect fits inside \c lhsRect. +*/ +function CGRectContainsRect(lhsRect, rhsRect) +{ + var union = CGRectUnion(lhsRect, rhsRect); + + return _CGRectEqualToRect(union, lhsRect); +} + +/*! + Returns \c YES if the two rectangles intersect + @group CGRect + @param lhsRect the first CGRect + @param rhsRect the second CGRect + @return BOOL \c YES if the two rectangles have any common spaces, and \c NO, otherwise. +*/ +function CGRectIntersectsRect(lhsRect, rhsRect) +{ + var intersection = CGRectIntersection(lhsRect, rhsRect); + + return !_CGRectIsEmpty(intersection); +} + +/*! + Makes the origin and size of a CGRect all integers. Specifically, by making + the southwest corner the origin (rounded down), and the northeast corner a CGSize (rounded up). + @param aRect the rectangle to operate on + @return CGRect the modified rectangle (same as the input) + @group CGRect +*/ +function CGRectIntegral(aRect) +{ + aRect = CGRectStandardize(aRect); + + // Store these out separately, if not the GetMaxes will return incorrect values. + var x = FLOOR(_CGRectGetMinX(aRect)), + y = FLOOR(_CGRectGetMinY(aRect)); + + aRect.size.width = CEIL(_CGRectGetMaxX(aRect)) - x; + aRect.size.height = CEIL(_CGRectGetMaxY(aRect)) - y; + + aRect.origin.x = x; + aRect.origin.y = y; + + return aRect; +} + +/*! + Returns the intersection of the two provided rectangles as a new rectangle. + @param lhsRect the first rectangle used for calculation + @param rhsRect the second rectangle used for calculation + @return CGRect the intersection of the two rectangles + @group CGRect +*/ +function CGRectIntersection(lhsRect, rhsRect) +{ + var intersection = _CGRectMake( + MAX(_CGRectGetMinX(lhsRect), _CGRectGetMinX(rhsRect)), + MAX(_CGRectGetMinY(lhsRect), _CGRectGetMinY(rhsRect)), + 0, 0); + + intersection.size.width = MIN(_CGRectGetMaxX(lhsRect), _CGRectGetMaxX(rhsRect)) - _CGRectGetMinX(intersection); + intersection.size.height = MIN(_CGRectGetMaxY(lhsRect), _CGRectGetMaxY(rhsRect)) - _CGRectGetMinY(intersection); + + return _CGRectIsEmpty(intersection) ? _CGRectMakeZero() : intersection; +} + +/* + +*/ +function CGRectStandardize(aRect) +{ + var width = _CGRectGetWidth(aRect), + height = _CGRectGetHeight(aRect), + standardized = _CGRectMakeCopy(aRect); + + if (width < 0.0) + { + standardized.origin.x += width; + standardized.size.width = -width; + } + + if (height < 0.0) + { + standardized.origin.y += height; + standardized.size.height = -height; + } + + return standardized; +} + +function CGRectUnion(lhsRect, rhsRect) +{ + var lhsRectIsNull = !lhsRect || lhsRect === CGRectNull, + rhsRectIsNull = !rhsRect || rhsRect === CGRectNull; + + if (lhsRectIsNull) + return rhsRectIsNull ? CGRectNull : rhsRect; + + if (rhsRectIsNull) + return lhsRectIsNull ? CGRectNull : lhsRect; + + var minX = MIN(_CGRectGetMinX(lhsRect), _CGRectGetMinX(rhsRect)), + minY = MIN(_CGRectGetMinY(lhsRect), _CGRectGetMinY(rhsRect)), + maxX = MAX(_CGRectGetMaxX(lhsRect), _CGRectGetMaxX(rhsRect)), + maxY = MAX(_CGRectGetMaxY(lhsRect), _CGRectGetMaxY(rhsRect)); + + return _CGRectMake(minX, minY, maxX - minX, maxY - minY); +} + +/*! + Returns the specified rectangle inset by the given CGInset as a new rectangle. + @param aRect the rect to inset + @param anInset a CGInset to inset by + @return CGRect aRect inset by anInset +*/ +_function(CGRectInsetByInset(aRect, anInset)); + +function CGPointFromString(aString) +{ + var comma = aString.indexOf(','); + + return { x:parseFloat(aString.substr(1, comma - 1)), y:parseFloat(aString.substring(comma + 1, aString.length)) }; +} + +function CGSizeFromString(aString) +{ + var comma = aString.indexOf(','); + + return { width:parseFloat(aString.substr(1, comma - 1)), height:parseFloat(aString.substring(comma + 1, aString.length)) }; +} + +function CGRectFromString(aString) +{ + var comma = aString.indexOf(',', aString.indexOf(',') + 1); + + return { origin:CGPointFromString(aString.substr(1, comma - 1)), size:CGSizeFromString(aString.substring(comma + 2, aString.length)) }; +} + +function CGPointFromEvent(anEvent) +{ + return _CGPointMake(anEvent.clientX, anEvent.clientY); +} + +/*! + Combines two insets by adding their individual elements and returns the result. + + @group CGInset +*/ +function CGInsetUnion(lhsInset, rhsInset) +{ + return _CGInsetMake(lhsInset.top + rhsInset.top, + lhsInset.right + rhsInset.right, + lhsInset.bottom + rhsInset.bottom, + lhsInset.left + rhsInset.left); +} + +/*! + Subtract one inset from another by subtracting their individual elements and returns the result. + + @group CGInset +*/ +function CGInsetDifference(lhsInset, rhsInset) +{ + return _CGInsetMake(lhsInset.top - rhsInset.top, + lhsInset.right - rhsInset.right, + lhsInset.bottom - rhsInset.bottom, + lhsInset.left - rhsInset.left); +} + +function CGInsetFromString(aString) +{ + var numbers = aString.substr(1, aString.length - 2).split(','); + + return _CGInsetMake(parseFloat(numbers[0]), parseFloat(numbers[1]), parseFloat(numbers[2]), parseFloat(numbers[3])); +} + +CGInsetFromCPString = CGInsetFromString; + +function CPStringFromCGInset(anInset) +{ + return '{' + anInset.top + ", " + anInset.left + ", " + anInset.bottom + ", " + anInset.right + '}'; +} + +/*! + @} +*/