diff --git a/AsyncDisplayKit/ASEditableTextNode.mm b/AsyncDisplayKit/ASEditableTextNode.mm index 573323fda6..b47dc7ca14 100644 --- a/AsyncDisplayKit/ASEditableTextNode.mm +++ b/AsyncDisplayKit/ASEditableTextNode.mm @@ -11,6 +11,7 @@ #import "ASEditableTextNode.h" #import +#import #import "ASDisplayNode+Subclasses.h" #import "ASEqualityHelpers.h" @@ -238,9 +239,9 @@ { ASTextKitComponents *displayedComponents = [self isDisplayingPlaceholder] ? _placeholderTextKitComponents : _textKitComponents; CGSize textSize = [displayedComponents sizeForConstrainedWidth:constrainedSize.width]; - CGFloat width = ceilf(textSize.width + _textContainerInset.left + _textContainerInset.right); - CGFloat height = ceilf(textSize.height + _textContainerInset.top + _textContainerInset.bottom); - return CGSizeMake(fminf(width, constrainedSize.width), fminf(height, constrainedSize.height)); + CGFloat width = std::ceil(textSize.width + _textContainerInset.left + _textContainerInset.right); + CGFloat height = std::ceil(textSize.height + _textContainerInset.top + _textContainerInset.bottom); + return CGSizeMake(std::fmin(width, constrainedSize.width), std::fmin(height, constrainedSize.height)); } - (void)layout diff --git a/AsyncDisplayKit/ASImageNode+tvOS.m b/AsyncDisplayKit/ASImageNode+tvOS.m index 26b7dd49b4..cc0af5de01 100644 --- a/AsyncDisplayKit/ASImageNode+tvOS.m +++ b/AsyncDisplayKit/ASImageNode+tvOS.m @@ -12,7 +12,10 @@ #if TARGET_OS_TV #import "ASImageNode+tvOS.h" + #import +#import + #import "ASDisplayNodeExtras.h" @implementation ASImageNode (tvOS) @@ -75,8 +78,8 @@ // BUT we apply our transforms to *view since we want to apply // the transforms to the root view (L: 107) CGPoint point = [touch locationInView:self.view]; - float pitch = 0; - float yaw = 0; + CGFloat pitch = 0; + CGFloat yaw = 0; BOOL topHalf = NO; if (point.y > CGRectGetHeight(self.view.frame)) { pitch = 15; @@ -100,7 +103,7 @@ if (yaw > 0) { yaw = -yaw; } else { - yaw = fabsf(yaw); + yaw = fabs(yaw); } } diff --git a/AsyncDisplayKit/ASImageNode.mm b/AsyncDisplayKit/ASImageNode.mm index 8a6304f024..fa73b6a38f 100644 --- a/AsyncDisplayKit/ASImageNode.mm +++ b/AsyncDisplayKit/ASImageNode.mm @@ -10,6 +10,8 @@ #import "ASImageNode.h" +#import + #import "_ASDisplayLayer.h" #import "ASAssert.h" #import "ASDisplayNode+Subclasses.h" @@ -313,7 +315,7 @@ struct ASImageNodeDrawParameters { CGSize imageSize = image.size; CGSize imageSizeInPixels = CGSizeMake(imageSize.width * image.scale, imageSize.height * image.scale); - CGSize boundsSizeInPixels = CGSizeMake(floorf(bounds.size.width * contentsScale), floorf(bounds.size.height * contentsScale)); + CGSize boundsSizeInPixels = CGSizeMake(std::floor(bounds.size.width * contentsScale), std::floor(bounds.size.height * contentsScale)); if (_debugLabelNode) { CGFloat pixelCountRatio = (imageSizeInPixels.width * imageSizeInPixels.height) / (boundsSizeInPixels.width * boundsSizeInPixels.height); diff --git a/AsyncDisplayKit/ASMapNode.mm b/AsyncDisplayKit/ASMapNode.mm index c0d7fb9a25..e334ab633a 100644 --- a/AsyncDisplayKit/ASMapNode.mm +++ b/AsyncDisplayKit/ASMapNode.mm @@ -10,6 +10,9 @@ #if TARGET_OS_IOS #import "ASMapNode.h" + +#import + #import "ASDisplayNodeInternal.h" #import "ASDisplayNode+Subclasses.h" #import "ASDisplayNodeExtras.h" @@ -320,16 +323,16 @@ CLLocationCoordinate2D bottomRightCoord = CLLocationCoordinate2DMake(90, -180); for (id annotation in annotations) { - topLeftCoord = CLLocationCoordinate2DMake(fmax(topLeftCoord.latitude, annotation.coordinate.latitude), - fmin(topLeftCoord.longitude, annotation.coordinate.longitude)); - bottomRightCoord = CLLocationCoordinate2DMake(fmin(bottomRightCoord.latitude, annotation.coordinate.latitude), - fmax(bottomRightCoord.longitude, annotation.coordinate.longitude)); + topLeftCoord = CLLocationCoordinate2DMake(std::fmax(topLeftCoord.latitude, annotation.coordinate.latitude), + std::fmin(topLeftCoord.longitude, annotation.coordinate.longitude)); + bottomRightCoord = CLLocationCoordinate2DMake(std::fmin(bottomRightCoord.latitude, annotation.coordinate.latitude), + std::fmax(bottomRightCoord.longitude, annotation.coordinate.longitude)); } MKCoordinateRegion region = MKCoordinateRegionMake(CLLocationCoordinate2DMake(topLeftCoord.latitude - (topLeftCoord.latitude - bottomRightCoord.latitude) * 0.5, topLeftCoord.longitude + (bottomRightCoord.longitude - topLeftCoord.longitude) * 0.5), - MKCoordinateSpanMake(fabs(topLeftCoord.latitude - bottomRightCoord.latitude) * 2, - fabs(bottomRightCoord.longitude - topLeftCoord.longitude) * 2)); + MKCoordinateSpanMake(std::fabs(topLeftCoord.latitude - bottomRightCoord.latitude) * 2, + std::fabs(bottomRightCoord.longitude - topLeftCoord.longitude) * 2)); return region; } diff --git a/AsyncDisplayKit/ASTextNode.mm b/AsyncDisplayKit/ASTextNode.mm index 150644e52e..e4edbbd99d 100644 --- a/AsyncDisplayKit/ASTextNode.mm +++ b/AsyncDisplayKit/ASTextNode.mm @@ -12,6 +12,7 @@ #import "ASTextNode+Beta.h" #include +#import #import "_ASDisplayLayer.h" #import "ASDisplayNode+Subclasses.h" @@ -524,7 +525,7 @@ static NSArray *DefaultLinkAttributeNames = @[ NSLinkAttributeName ]; [renderer enumerateTextIndexesAtPosition:point usingBlock:^(NSUInteger characterIndex, CGRect glyphBoundingRect, BOOL *stop) { CGPoint glyphLocation = CGPointMake(CGRectGetMidX(glyphBoundingRect), CGRectGetMidY(glyphBoundingRect)); - CGFloat currentDistance = sqrtf(powf(point.x - glyphLocation.x, 2.f) + powf(point.y - glyphLocation.y, 2.f)); + CGFloat currentDistance = std::sqrt(std::pow(point.x - glyphLocation.x, 2.f) + std::pow(point.y - glyphLocation.y, 2.f)); if (currentDistance >= minimumGlyphDistance) { // If the distance computed from the touch to the glyph location is // not the minimum among the located link attributes, we can just skip diff --git a/AsyncDisplayKit/Details/ASHighlightOverlayLayer.mm b/AsyncDisplayKit/Details/ASHighlightOverlayLayer.mm index 8398207d2f..0d4032a318 100644 --- a/AsyncDisplayKit/Details/ASHighlightOverlayLayer.mm +++ b/AsyncDisplayKit/Details/ASHighlightOverlayLayer.mm @@ -11,6 +11,7 @@ #import "ASHighlightOverlayLayer.h" #import +#import #import "ASInternalHelpers.h" @@ -86,7 +87,7 @@ static const UIEdgeInsets padding = {2, 4, 1.5, 4}; if (targetLayer != nil) { rect = [self convertRect:rect fromLayer:targetLayer]; } - rect = CGRectMake(roundf(rect.origin.x), roundf(rect.origin.y), roundf(rect.size.width), roundf(rect.size.height)); + rect = CGRectMake(std::round(rect.origin.x), std::round(rect.origin.y), std::round(rect.size.width), std::round(rect.size.height)); CGFloat minX = rect.origin.x - padding.left; CGFloat maxX = CGRectGetMaxX(rect) + padding.right; diff --git a/AsyncDisplayKit/Layout/ASAsciiArtBoxCreator.m b/AsyncDisplayKit/Layout/ASAsciiArtBoxCreator.m index e39f836aad..98f335ef1e 100644 --- a/AsyncDisplayKit/Layout/ASAsciiArtBoxCreator.m +++ b/AsyncDisplayKit/Layout/ASAsciiArtBoxCreator.m @@ -10,6 +10,8 @@ #import "ASAsciiArtBoxCreator.h" +#import + static const NSUInteger kDebugBoxPadding = 2; typedef NS_ENUM(NSUInteger, PIDebugBoxPaddingLocation) @@ -69,7 +71,7 @@ typedef NS_ENUM(NSUInteger, PIDebugBoxPaddingLocation) for (NSString *child in children) { NSMutableArray *lines = [[child componentsSeparatedByString:@"\n"] mutableCopy]; - NSUInteger topPadding = ceilf((CGFloat)(lineCountPerChild - [lines count])/2.0); + NSUInteger topPadding = ceil((CGFloat)(lineCountPerChild - [lines count])/2.0); NSUInteger bottomPadding = (lineCountPerChild - [lines count])/2.0; NSUInteger lineLength = [lines[0] length]; @@ -98,7 +100,7 @@ typedef NS_ENUM(NSUInteger, PIDebugBoxPaddingLocation) NSUInteger totalLineLength = [concatenatedLines[0] length]; if (totalLineLength < [parent length]) { NSUInteger difference = [parent length] + (2 * kDebugBoxPadding) - totalLineLength; - NSUInteger leftPadding = ceilf((CGFloat)difference/2.0); + NSUInteger leftPadding = ceil((CGFloat)difference/2.0); NSUInteger rightPadding = difference/2; NSString *leftString = [@"|" debugbox_stringByAddingPadding:@" " count:leftPadding location:PIDebugBoxPaddingLocationEnd]; @@ -137,7 +139,7 @@ typedef NS_ENUM(NSUInteger, PIDebugBoxPaddingLocation) if (maxChildLength < [parent length]) { NSUInteger difference = [parent length] + (2 * kDebugBoxPadding) - maxChildLength; - leftPadding = ceilf((CGFloat)difference/2.0); + leftPadding = ceil((CGFloat)difference/2.0); rightPadding = difference/2; } @@ -147,7 +149,7 @@ typedef NS_ENUM(NSUInteger, PIDebugBoxPaddingLocation) for (NSString *child in children) { NSMutableArray *lines = [[child componentsSeparatedByString:@"\n"] mutableCopy]; - NSUInteger leftLinePadding = ceilf((CGFloat)(maxChildLength - [lines[0] length])/2.0); + NSUInteger leftLinePadding = ceil((CGFloat)(maxChildLength - [lines[0] length])/2.0); NSUInteger rightLinePadding = (maxChildLength - [lines[0] length])/2.0; for (NSString *line in lines) { @@ -171,7 +173,7 @@ typedef NS_ENUM(NSUInteger, PIDebugBoxPaddingLocation) NSUInteger totalLineLength = [boxStrings[0] length]; [boxStrings addObject:[NSString debugbox_stringWithString:@"-" repeatedCount:totalLineLength]]; - NSUInteger leftPadding = ceilf(((CGFloat)(totalLineLength - [parent length]))/2.0); + NSUInteger leftPadding = ceil(((CGFloat)(totalLineLength - [parent length]))/2.0); NSUInteger rightPadding = (totalLineLength - [parent length])/2; NSString *topLine = [parent debugbox_stringByAddingPadding:@"-" count:leftPadding location:PIDebugBoxPaddingLocationFront]; diff --git a/AsyncDisplayKit/Layout/ASRatioLayoutSpec.mm b/AsyncDisplayKit/Layout/ASRatioLayoutSpec.mm index 8b51c71148..32e1bdea84 100644 --- a/AsyncDisplayKit/Layout/ASRatioLayoutSpec.mm +++ b/AsyncDisplayKit/Layout/ASRatioLayoutSpec.mm @@ -11,6 +11,7 @@ #import "ASRatioLayoutSpec.h" #import +#import #import #import "ASAssert.h" @@ -64,7 +65,7 @@ // Choose the size closest to the desired ratio. const auto &bestSize = std::max_element(sizeOptions.begin(), sizeOptions.end(), [&](const CGSize &a, const CGSize &b){ - return fabs((a.height / a.width) - _ratio) > fabs((b.height / b.width) - _ratio); + return std::fabs((a.height / a.width) - _ratio) > std::fabs((b.height / b.width) - _ratio); }); // If there is no max size in *either* dimension, we can't apply the ratio, so just pass our size range through. diff --git a/AsyncDisplayKit/Private/ASStackPositionedLayout.mm b/AsyncDisplayKit/Private/ASStackPositionedLayout.mm index 82cc1608be..629b4eee71 100644 --- a/AsyncDisplayKit/Private/ASStackPositionedLayout.mm +++ b/AsyncDisplayKit/Private/ASStackPositionedLayout.mm @@ -10,6 +10,8 @@ #import "ASStackPositionedLayout.h" +#import + #import "ASInternalHelpers.h" #import "ASLayoutSpecUtilities.h" @@ -105,16 +107,16 @@ ASStackPositionedLayout ASStackPositionedLayout::compute(const ASStackUnposition case ASStackLayoutJustifyContentStart: return stackedLayout(style, 0, unpositionedLayout, constrainedSize); case ASStackLayoutJustifyContentCenter: - return stackedLayout(style, floorf(violation / 2), unpositionedLayout, constrainedSize); + return stackedLayout(style, std::floor(violation / 2), unpositionedLayout, constrainedSize); case ASStackLayoutJustifyContentEnd: return stackedLayout(style, violation, unpositionedLayout, constrainedSize); case ASStackLayoutJustifyContentSpaceBetween: { const auto numOfSpacings = numOfItems - 1; - return stackedLayout(style, 0, floorf(violation / numOfSpacings), fmodf(violation, numOfSpacings), unpositionedLayout, constrainedSize); + return stackedLayout(style, 0, std::floor(violation / numOfSpacings), std::fmod(violation, numOfSpacings), unpositionedLayout, constrainedSize); } case ASStackLayoutJustifyContentSpaceAround: { // Spacing between items are twice the spacing on the edges - CGFloat spacingUnit = floorf(violation / (numOfItems * 2)); + CGFloat spacingUnit = std::floor(violation / (numOfItems * 2)); return stackedLayout(style, spacingUnit, spacingUnit * 2, 0, unpositionedLayout, constrainedSize); } } diff --git a/AsyncDisplayKit/Private/ASStackUnpositionedLayout.mm b/AsyncDisplayKit/Private/ASStackUnpositionedLayout.mm index e0026fcba9..0dfa11fb06 100644 --- a/AsyncDisplayKit/Private/ASStackUnpositionedLayout.mm +++ b/AsyncDisplayKit/Private/ASStackUnpositionedLayout.mm @@ -10,6 +10,7 @@ #import "ASStackUnpositionedLayout.h" +#import #import #import "ASLayoutSpecUtilities.h" @@ -87,7 +88,7 @@ static void stretchChildrenAlongCrossDimension(std::vector 0.01) { + if (alignItems == ASStackLayoutAlignItemsStretch && std::fabs(cross - childCrossMax) > 0.01) { l.layout = crossChildLayout(child, style, stack, stack, childCrossMax, childCrossMax); } } @@ -182,7 +183,7 @@ static const CGFloat kViolationEpsilon = 0.01; */ static std::function isFlexibleInViolationDirection(const CGFloat violation) { - if (fabs(violation) < kViolationEpsilon) { + if (std::fabs(violation) < kViolationEpsilon) { return [](const ASStackUnpositionedItem &l) { return NO; }; } else if (violation > 0) { return [](const ASStackUnpositionedItem &l) { return l.child.flexGrow; }; @@ -263,7 +264,7 @@ static void flexChildrenAlongStackDimension(std::vector } // Each flexible child along the direction of the violation is expanded or contracted equally - const CGFloat violationPerFlexChild = floorf(violation / flexibleChildren); + const CGFloat violationPerFlexChild = std::floor(violation / flexibleChildren); // If the floor operation above left a remainder we may have a remainder after deducting the adjustments from all the // contributions of the flexible children. const CGFloat violationRemainder = violation - (violationPerFlexChild * flexibleChildren); diff --git a/AsyncDisplayKit/Private/_ASCoreAnimationExtras.mm b/AsyncDisplayKit/Private/_ASCoreAnimationExtras.mm index 3456308183..64eea95892 100644 --- a/AsyncDisplayKit/Private/_ASCoreAnimationExtras.mm +++ b/AsyncDisplayKit/Private/_ASCoreAnimationExtras.mm @@ -32,8 +32,8 @@ extern void ASDisplayNodeSetupLayerContentsWithResizableImage(CALayer *layer, UI UIEdgeInsets insets = [image capInsets]; // These are lifted from what UIImageView does by experimentation. Without these exact values, the stretching is slightly off. - const float halfPixelFudge = 0.49f; - const float otherPixelFudge = 0.02f; + const CGFloat halfPixelFudge = 0.49f; + const CGFloat otherPixelFudge = 0.02f; // Convert to unit coordinates for the contentsCenter property. CGRect contentsCenter = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f); if (insets.left > 0 || insets.right > 0) { diff --git a/AsyncDisplayKit/TextKit/ASTextKitFontSizeAdjuster.mm b/AsyncDisplayKit/TextKit/ASTextKitFontSizeAdjuster.mm index bf910a10de..441aa5c921 100644 --- a/AsyncDisplayKit/TextKit/ASTextKitFontSizeAdjuster.mm +++ b/AsyncDisplayKit/TextKit/ASTextKitFontSizeAdjuster.mm @@ -8,12 +8,15 @@ // of patent rights can be found in the PATENTS file in the same directory. // -#import "ASTextKitContext.h" -#import "ASTextKitFontSizeAdjuster.h" -#import "ASLayoutManager.h" +#import "ASTextKitFontSizeAdjuster.h" + +#import #import +#import "ASTextKitContext.h" +#import "ASLayoutManager.h" + //#define LOG(...) NSLog(__VA_ARGS__) #define LOG(...) @@ -48,7 +51,7 @@ [attrString enumerateAttributesInRange:NSMakeRange(0, attrString.length) options:0 usingBlock:^(NSDictionary * _Nonnull attrs, NSRange range, BOOL * _Nonnull stop) { if (attrs[NSFontAttributeName] != nil) { UIFont *font = attrs[NSFontAttributeName]; - font = [font fontWithSize:roundf(font.pointSize * scaleFactor)]; + font = [font fontWithSize:std::round(font.pointSize * scaleFactor)]; [attrString removeAttribute:NSFontAttributeName range:range]; [attrString addAttribute:NSFontAttributeName value:font range:range]; } @@ -166,7 +169,7 @@ // adjust here so we start at the proper place in our scale array if we have too many lines scaleIndex++; - if (ceilf(longestWordSize.width * [scaleFactor floatValue]) <= _constrainedSize.width) { + if (std::ceil(longestWordSize.width * [scaleFactor floatValue]) <= _constrainedSize.width) { // we fit! we are done break; } diff --git a/AsyncDisplayKit/TextKit/ASTextKitRenderer+Positioning.mm b/AsyncDisplayKit/TextKit/ASTextKitRenderer+Positioning.mm index 3a3abb5e47..1039f86494 100755 --- a/AsyncDisplayKit/TextKit/ASTextKitRenderer+Positioning.mm +++ b/AsyncDisplayKit/TextKit/ASTextKitRenderer+Positioning.mm @@ -11,6 +11,7 @@ #import "ASTextKitRenderer+Positioning.h" #import +#import #import "ASAssert.h" @@ -163,7 +164,7 @@ static const CGFloat ASTextKitRendererTextCapHeightPadding = 1.3; [self enumerateTextIndexesAtPosition:position usingBlock:^(NSUInteger characterIndex, CGRect glyphBoundingRect, BOOL *stop) { CGPoint glyphLocation = CGPointMake(CGRectGetMidX(glyphBoundingRect), CGRectGetMidY(glyphBoundingRect)); - CGFloat currentDistance = sqrtf(powf(position.x - glyphLocation.x, 2.f) + powf(position.y - glyphLocation.y, 2.f)); + CGFloat currentDistance = std::sqrt(std::pow(position.x - glyphLocation.x, 2.f) + std::pow(position.y - glyphLocation.y, 2.f)); if (currentDistance < minimumGlyphDistance) { minimumGlyphDistance = currentDistance; minimumGlyphCharacterIndex = characterIndex; diff --git a/AsyncDisplayKit/TextKit/ASTextKitShadower.mm b/AsyncDisplayKit/TextKit/ASTextKitShadower.mm index 5da2b55b75..a4960e6699 100755 --- a/AsyncDisplayKit/TextKit/ASTextKitShadower.mm +++ b/AsyncDisplayKit/TextKit/ASTextKitShadower.mm @@ -10,6 +10,8 @@ #import "ASTextKitShadower.h" +#import + static inline CGSize _insetSize(CGSize size, UIEdgeInsets insets) { return UIEdgeInsetsInsetRect({.size = size}, insets).size; @@ -87,11 +89,11 @@ static inline UIEdgeInsets _invertInsets(UIEdgeInsets insets) // min values are expected to be negative for most typical shadowOffset and // blurRadius settings: - shadowPadding.top = fminf(0.0f, _shadowOffset.height - _shadowRadius); - shadowPadding.left = fminf(0.0f, _shadowOffset.width - _shadowRadius); + shadowPadding.top = std::fmin(0.0f, _shadowOffset.height - _shadowRadius); + shadowPadding.left = std::fmin(0.0f, _shadowOffset.width - _shadowRadius); - shadowPadding.bottom = fminf(0.0f, -_shadowOffset.height - _shadowRadius); - shadowPadding.right = fminf(0.0f, -_shadowOffset.width - _shadowRadius); + shadowPadding.bottom = std::fmin(0.0f, -_shadowOffset.height - _shadowRadius); + shadowPadding.right = std::fmin(0.0f, -_shadowOffset.width - _shadowRadius); _calculatedShadowPadding = shadowPadding; }