Skip to content

Commit

Permalink
Internal change
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 331764642
  • Loading branch information
Jeff Verkoeyen authored and material-automation committed Sep 15, 2020
1 parent aba747b commit eb82984
Show file tree
Hide file tree
Showing 17 changed files with 40 additions and 51 deletions.
2 changes: 1 addition & 1 deletion components/Cards/src/MDCCard.m
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ - (void)setShapeGenerator:(id<MDCShapeGenerating>)shapeGenerator {
- (void)updateInkForShape {
CGRect boundingBox = CGPathGetBoundingBox(self.layer.shapeLayer.path);
self.inkView.maxRippleRadius =
(CGFloat)(MDCHypot(CGRectGetHeight(boundingBox), CGRectGetWidth(boundingBox)) / 2 + 10);
(CGFloat)(hypot(CGRectGetHeight(boundingBox), CGRectGetWidth(boundingBox)) / 2 + 10);
self.inkView.layer.masksToBounds = NO;
}

Expand Down
2 changes: 1 addition & 1 deletion components/Cards/src/MDCCardCollectionCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ - (id)shapeGenerator {
- (void)updateInkForShape {
CGRect boundingBox = CGPathGetBoundingBox(self.layer.shapeLayer.path);
self.inkView.maxRippleRadius =
(CGFloat)(MDCHypot(CGRectGetHeight(boundingBox), CGRectGetWidth(boundingBox)) / 2 + 10);
(CGFloat)(hypot(CGRectGetHeight(boundingBox), CGRectGetWidth(boundingBox)) / 2 + 10);
self.inkView.layer.masksToBounds = NO;
}

Expand Down
5 changes: 2 additions & 3 deletions components/Chips/src/MDCChipField.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

#import "MDCChipFieldDelegate.h"
#import "MaterialTextFields.h"
#import "MaterialMath.h"

NSString *const MDCEmptyTextString = @"";
NSString *const MDCChipDelimiterSpace = @" ";
Expand Down Expand Up @@ -414,8 +413,8 @@ - (UIImage *)drawClearButton {

CGRect innerBounds =
CGRectMake(CGRectGetMinX(frame) + 2, CGRectGetMinY(frame) + 2,
MDCFloor((frame.size.width - 2) * (CGFloat)0.90909 + (CGFloat)0.5),
MDCFloor((frame.size.height - 2) * (CGFloat)0.90909 + (CGFloat)0.5));
floor((frame.size.width - 2) * (CGFloat)0.90909 + (CGFloat)0.5),
floor((frame.size.height - 2) * (CGFloat)0.90909 + (CGFloat)0.5));
UIBezierPath *ic_clear_path = [UIBezierPath bezierPath];
[ic_clear_path moveToPoint:CGPointMake(CGRectGetMinX(innerBounds) +
(CGFloat)0.50000 * innerBounds.size.width,
Expand Down
8 changes: 4 additions & 4 deletions components/Chips/src/MDCChipView.m
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ static CGRect CGRectVerticallyCentered(CGRect rect,
CGFloat pixelScale) {
CGFloat viewHeight = CGRectGetHeight(rect) + padding.top + padding.bottom;
CGFloat yValue = (height - viewHeight) / 2;
yValue = MDCRound(yValue * pixelScale) / pixelScale;
yValue = round(yValue * pixelScale) / pixelScale;
return CGRectOffset(rect, 0, yValue);
}

Expand Down Expand Up @@ -756,9 +756,9 @@ - (UIEdgeInsets)visibleAreaInsets {
CGFloat additionalRequiredHeight =
MAX(0, CGRectGetHeight(self.bounds) - visibleAreaSize.height);
CGFloat additionalRequiredWidth = MAX(0, CGRectGetWidth(self.bounds) - visibleAreaSize.width);
visibleAreaInsets.top = MDCCeil(additionalRequiredHeight * 0.5f);
visibleAreaInsets.top = ceil(additionalRequiredHeight * 0.5f);
visibleAreaInsets.bottom = additionalRequiredHeight - visibleAreaInsets.top;
visibleAreaInsets.left = MDCCeil(additionalRequiredWidth * 0.5f);
visibleAreaInsets.left = ceil(additionalRequiredWidth * 0.5f);
visibleAreaInsets.right = additionalRequiredWidth - visibleAreaInsets.left;
}

Expand Down Expand Up @@ -1049,7 +1049,7 @@ - (void)startTouchBeganAnimationAtPoint:(CGPoint)point {
CGSize size = [self sizeThatFits:CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX)];
CGFloat widthDiff = 24; // Difference between unselected and selected frame widths.
CGFloat maxRadius =
(CGFloat)(MDCHypot(size.height, size.width + widthDiff) / 2 + 10 + widthDiff / 2);
(CGFloat)(hypot(size.height, size.width + widthDiff) / 2 + 10 + widthDiff / 2);
if (self.enableRippleBehavior) {
_rippleView.maximumRadius = maxRadius;
[_rippleView beginRippleTouchDownAtPoint:point animated:YES completion:nil];
Expand Down
5 changes: 2 additions & 3 deletions components/Chips/tests/unit/MDCChipViewTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#import <XCTest/XCTest.h>

#import "MDCChipView.h"
#import "MaterialMath.h"

static inline UIImage *TestImage(CGSize size) {
CGFloat scale = [UIScreen mainScreen].scale;
Expand Down Expand Up @@ -273,9 +272,9 @@ - (void)testVisibleAreaInsetsIsCorrectWhenCenterVisibleAreaIsYES {
CGSize visibleAreaSize = [chip sizeThatFits:CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX)];
CGFloat verticalInsets = 50 - visibleAreaSize.height;
CGFloat horizontalInsets = 300 - visibleAreaSize.width;
CGFloat topInsets = MDCCeil(verticalInsets * 0.5f);
CGFloat topInsets = ceil(verticalInsets * 0.5f);
CGFloat bottomInsets = verticalInsets - topInsets;
CGFloat leftInsets = MDCCeil(horizontalInsets * 0.5f);
CGFloat leftInsets = ceil(horizontalInsets * 0.5f);
CGFloat rightInsets = horizontalInsets - leftInsets;
UIEdgeInsets expectedVisibleAreaInsets =
UIEdgeInsetsMake(topInsets, leftInsets, bottomInsets, rightInsets);
Expand Down
5 changes: 2 additions & 3 deletions components/CollectionCells/src/MDCCollectionViewTextCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#import "MDCCollectionViewTextCell.h"

#import <MDFInternationalization/MDFInternationalization.h>
#import "MaterialMath.h"
#import "MaterialTypography.h"

#include <tgmath.h>
Expand Down Expand Up @@ -63,14 +62,14 @@ static inline CGFloat CellDefaultDetailTextFontOpacity(void) {
// account. At a scale of 1, equivalent to Ceil().
static inline CGFloat AlignValueToUpperPixel(CGFloat value) {
CGFloat scale = [[UIScreen mainScreen] scale];
return (CGFloat)MDCCeil(value * scale) / scale;
return (CGFloat)ceil(value * scale) / scale;
}

// Returns the closest pixel-aligned value lower than |value|, taking the scale factor into
// account. At a scale of 1, equivalent to Floor().
static inline CGFloat AlignValueToLowerPixel(CGFloat value) {
CGFloat scale = [[UIScreen mainScreen] scale];
return (CGFloat)MDCFloor(value * scale) / scale;
return (CGFloat)floor(value * scale) / scale;
}

// Returns the rect resulting from applying AlignSizeToUpperPixel to the rect size.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,17 +135,17 @@ - (CGFloat)progressForTouchPosition:(CGPoint)touchPos {

// Now compute in the form at^2 + bt + c = 0
// a = (r2 - r1)^2 - (c2.x - c1.x)^2 - (c2.y - c1.y)^2
CGFloat a = MDCPow(r2 - r1, 2) - MDCPow(c2.x - c1.x, 2) - MDCPow(c2.y - c1.y, 2);
CGFloat a = pow(r2 - r1, 2) - pow(c2.x - c1.x, 2) - pow(c2.y - c1.y, 2);
// b = 2r1(r2 - r1) - 2c1.x(c2.x - c1.x) + 2(c2.x - c1.x)p.x - 2c1.y(c2.y - c1.y) + 2(c2.y -
// c1.y)p.y
CGFloat b = 2 * r1 * (r2 - r1) - 2 * c1.x * (c2.x - c1.x) + 2 * (c2.x - c1.x) * p.x -
2 * c1.y * (c2.y - c1.y) + 2 * (c2.y - c1.y) * p.y;
// c = r1^2 - c1.x^2 + 2c1.x*p.x - p.x^2 - c1.y^2 + 2c1.y*p.y - p.y^2
CGFloat c = MDCPow(r1, 2) - MDCPow(c1.x, 2) + 2 * c1.x * p.x - MDCPow(p.x, 2) - MDCPow(c1.y, 2) +
2 * c1.y * p.y - MDCPow(p.y, 2);
CGFloat c = pow(r1, 2) - pow(c1.x, 2) + 2 * c1.x * p.x - pow(p.x, 2) - pow(c1.y, 2) +
2 * c1.y * p.y - pow(p.y, 2);

// Apply the quadratic equation
CGFloat t = (-b - MDCSqrt(b * b - 4 * a * c)) / (2 * a);
CGFloat t = (-b - sqrt(b * b - 4 * a * c)) / (2 * a);

return MIN(1, MAX(0, t));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#import "MaterialTypography.h"

static inline CGFloat CGPointDistanceToPoint(CGPoint a, CGPoint b) {
return MDCHypot(a.x - b.x, a.y - b.y);
return hypot(a.x - b.x, a.y - b.y);
}

const CGFloat kMDCFeatureHighlightMinimumInnerRadius = 44;
Expand Down
1 change: 0 additions & 1 deletion components/Ink/src/MDCInkView.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#import "private/MDCInkLayer.h"
#import "private/MDCLegacyInkLayer.h"
#import "MDCInkViewDelegate.h"
#import "MaterialMath.h"

@interface MDCInkPendingAnimation : NSObject <CAAction>

Expand Down
5 changes: 2 additions & 3 deletions components/Ink/src/private/MDCInkLayer.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#import "MDCInkLayer.h"

#import "MDCInkLayerDelegate.h"
#import "MaterialMath.h"

static const CGFloat MDCInkLayerCommonDuration = (CGFloat)0.083;
static const CGFloat MDCInkLayerEndFadeOutDuration = (CGFloat)0.15;
Expand Down Expand Up @@ -79,8 +78,8 @@ - (void)setNeedsLayout {

- (void)setRadiiWithRect:(CGRect)rect {
self.initialRadius =
(CGFloat)(MDCHypot(CGRectGetHeight(rect), CGRectGetWidth(rect)) / 2 * (CGFloat)0.6);
self.finalRadius = (CGFloat)(MDCHypot(CGRectGetHeight(rect), CGRectGetWidth(rect)) / 2 + 10);
(CGFloat)(hypot(CGRectGetHeight(rect), CGRectGetWidth(rect)) / 2 * (CGFloat)0.6);
self.finalRadius = (CGFloat)(hypot(CGRectGetHeight(rect), CGRectGetWidth(rect)) / 2 + 10);
}

- (void)startAnimationAtPoint:(CGPoint)point {
Expand Down
1 change: 0 additions & 1 deletion components/Ripple/src/MDCRippleView.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

#import "MaterialAvailability.h"
#import "MDCRippleViewDelegate.h"
#import "MaterialMath.h"

@interface MDCRippleView () <CALayerDelegate, MDCRippleLayerDelegate>

Expand Down
3 changes: 1 addition & 2 deletions components/Ripple/src/private/MDCRippleLayer.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

#import "MaterialAnimationTiming.h"
#import "MDCRippleLayerDelegate.h"
#import "MaterialMath.h"

static const CGFloat kExpandRippleBeyondSurface = 10;
static const CGFloat kRippleStartingScale = (CGFloat)0.6;
Expand All @@ -35,7 +34,7 @@ static CGFloat GetInitialRippleRadius(CGRect rect) {
}

static CGFloat GetFinalRippleRadius(CGRect rect) {
return (CGFloat)(MDCHypot(CGRectGetMidX(rect), CGRectGetMidY(rect)) + kExpandRippleBeyondSurface);
return (CGFloat)(hypot(CGRectGetMidX(rect), CGRectGetMidY(rect)) + kExpandRippleBeyondSurface);
}

@implementation MDCRippleLayer
Expand Down
7 changes: 3 additions & 4 deletions components/ShadowLayer/examples/ShadowCornerRadiusExample.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

#import <UIKit/UIKit.h>

#import "MaterialMath.h"
#import "MaterialShadowLayer.h"
#import "MaterialSlider.h"
#import "ShadowRadiusLabel.h"
Expand Down Expand Up @@ -75,19 +74,19 @@ - (id)initWithFrame:(CGRect)frame {
}

- (NSString *)slider:(MDCSlider *)slider displayedStringForValue:(CGFloat)value {
NSInteger points = (NSInteger)MDCRound(value);
NSInteger points = (NSInteger)round(value);
return [NSString stringWithFormat:@"%ld pt", (long)points];
}

// TODO: (#4848) [ShadowLayer] cornerRadius changes don't render
- (void)sliderValueChanged:(MDCSlider *)slider {
NSInteger points = (NSInteger)MDCRound(slider.value);
NSInteger points = (NSInteger)round(slider.value);
_paper.cornerRadius = (CGFloat)points;
_elevationLabel.text = [NSString stringWithFormat:@"%ld pt", (long)points];
}

- (NSString *)slider:(MDCSlider *)slider accessibilityLabelForValue:(CGFloat)value {
NSInteger points = (NSInteger)MDCRound(slider.value);
NSInteger points = (NSInteger)round(slider.value);
return [NSString stringWithFormat:@"%ld points", (long)points];
}

Expand Down
3 changes: 1 addition & 2 deletions components/Shapes/src/MDCPathGenerator.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

#import "MDCPathGenerator.h"

#import "MaterialMath.h"

@interface MDCPathCommand : NSObject
- (void)applyToCGPath:(CGMutablePathRef)cgPath transform:(CGAffineTransform *)transform;
Expand Down Expand Up @@ -95,7 +94,7 @@ - (void)addArcWithCenter:(CGPoint)center
[_operations addObject:op];

_endPoint =
CGPointMake(center.x + radius * MDCCos(endAngle), center.y + radius * MDCSin(endAngle));
CGPointMake(center.x + radius * cos(endAngle), center.y + radius * sin(endAngle));
}

- (void)addArcWithTangentPoint:(CGPoint)tangentPoint
Expand Down
9 changes: 4 additions & 5 deletions components/Shapes/src/MDCRectangleShapeGenerator.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@
#import "MDCCornerTreatment.h"
#import "MDCEdgeTreatment.h"
#import "MDCPathGenerator.h"
#import "MaterialMath.h"

static inline CGFloat CGPointDistanceToPoint(CGPoint a, CGPoint b) {
return MDCHypot(a.x - b.x, a.y - b.y);
return hypot(a.x - b.x, a.y - b.y);
}

// Edges in clockwise order
Expand Down Expand Up @@ -208,8 +207,8 @@ - (CGFloat)angleOfCorner:(MDCShapeCornerPosition)cornerPosition forViewSize:(CGS
CGPointMake(prevCornerCoord.x - cornerCoord.x, prevCornerCoord.y - cornerCoord.y);
CGPoint nextVector =
CGPointMake(nextCornerCoord.x - cornerCoord.x, nextCornerCoord.y - cornerCoord.y);
CGFloat prevAngle = MDCAtan2(prevVector.y, prevVector.x);
CGFloat nextAngle = MDCAtan2(nextVector.y, nextVector.x);
CGFloat prevAngle = atan2(prevVector.y, prevVector.x);
CGFloat nextAngle = atan2(nextVector.y, nextVector.x);
CGFloat angle = prevAngle - nextAngle;
if (angle < 0)
angle += (CGFloat)(2 * M_PI);
Expand All @@ -224,7 +223,7 @@ - (CGFloat)angleOfEdge:(MDCShapeEdgePosition)edgePosition forViewSize:(CGSize)si

CGPoint edgeVector =
CGPointMake(endCornerCoord.x - startCornerCoord.x, endCornerCoord.y - startCornerCoord.y);
return MDCAtan2(edgeVector.y, edgeVector.x);
return atan2(edgeVector.y, edgeVector.x);
}

- (CGPoint)cornerCoordsForPosition:(MDCShapeCornerPosition)cornerPosition
Expand Down
20 changes: 10 additions & 10 deletions components/private/ThumbTrack/src/MDCThumbTrack.m
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
@return Absolute straight line distance.
*/
static inline CGFloat DistanceFromPointToPoint(CGPoint point1, CGPoint point2) {
return MDCHypot(point1.x - point2.x, point1.y - point2.y);
return hypot(point1.x - point2.x, point1.y - point2.y);
}

#if MDC_AVAILABLE_SDK_IOS(10_0)
Expand Down Expand Up @@ -638,8 +638,8 @@ - (void)updateThumbTrackAnimated:(BOOL)animated
completion:(void (^)(void))completion {
[self updateViewsNoAnimation];

BOOL activeSegmentShrinking = MDCFabs(self.value - self.filledTrackAnchorValue) <
MDCFabs(previousValue - self.filledTrackAnchorValue);
BOOL activeSegmentShrinking = fabs(self.value - self.filledTrackAnchorValue) <
fabs(previousValue - self.filledTrackAnchorValue);

UIViewAnimationOptions baseAnimationOptions =
UIViewAnimationOptionBeginFromCurrentState | UIViewAnimationOptionAllowUserInteraction;
Expand Down Expand Up @@ -670,8 +670,8 @@ - (void)updateThumbTrackAnimated:(BOOL)animated
(_value < _filledTrackAnchorValue && _filledTrackAnchorValue < previousValue);
if (crossesAnchor) {
CGFloat currentValue = _value;
CGFloat animationDurationToAnchor = (MDCFabs(previousValue - _filledTrackAnchorValue) /
MDCFabs(previousValue - currentValue)) *
CGFloat animationDurationToAnchor = (fabs(previousValue - _filledTrackAnchorValue) /
fabs(previousValue - currentValue)) *
kAnimationDuration;
void (^afterCrossingAnchorAnimation)(BOOL) = ^void(__unused BOOL finished) {
UIViewAnimationOptions options = baseAnimationOptions | UIViewAnimationOptionCurveEaseOut;
Expand Down Expand Up @@ -785,7 +785,7 @@ - (void)updateDotsViewActiveSegment {
(self.filledTrackAnchorValue - self.minimumValue) / (self.maximumValue - self.minimumValue);
CGFloat relativeValuePoint =
(self.value - self.minimumValue) / (self.maximumValue - self.minimumValue);
CGFloat activeSegmentWidth = MDCFabs(relativeAnchorPoint - relativeValuePoint);
CGFloat activeSegmentWidth = fabs(relativeAnchorPoint - relativeValuePoint);
CGFloat activeSegmentOriginX = MIN(relativeAnchorPoint, relativeValuePoint);
_discreteDots.activeDotsSegment = CGRectMake(activeSegmentOriginX, 0, activeSegmentWidth, 0);
}
Expand Down Expand Up @@ -826,7 +826,7 @@ - (void)updateViewsMainIsAnimated:(__unused BOOL)animated
if (CGRectGetWidth(_valueLabel.frame) > 1) {
CGFloat scale = self.window.screen.scale > 0 ?: UIScreen.mainScreen.scale;
_valueLabelHeight =
MAX(kValueLabelHeight, MDCCeil(_valueLabel.font.lineHeight * scale) / scale);
MAX(kValueLabelHeight, ceil(_valueLabel.font.lineHeight * scale) / scale);
CGFloat valueLabelWidth =
MAX((CGFloat)0.81 * _valueLabelHeight,
[_valueLabel sizeThatFits:CGSizeMake(CGFLOAT_MAX, _valueLabelHeight)].height);
Expand Down Expand Up @@ -866,7 +866,7 @@ - (void)updateViewsMainIsAnimated:(__unused BOOL)animated
timingFunctionFromUIViewAnimationOptions:animationOptions]];
[CATransaction setAnimationDuration:duration];
_trackOnLayer.frame =
CGRectMake(trackOnXValue, 0, MDCFabs(currentXValue - anchorXValue), _trackHeight);
CGRectMake(trackOnXValue, 0, fabs(currentXValue - anchorXValue), _trackHeight);
[CATransaction commit];
} else {
// Set background colors for disabled state.
Expand Down Expand Up @@ -1075,7 +1075,7 @@ - (CGFloat)relativeValueForValue:(CGFloat)value {
if (MDCCGFloatEqual(_minimumValue, _maximumValue)) {
return _minimumValue;
}
CGFloat relValue = (value - _minimumValue) / MDCFabs(_minimumValue - _maximumValue);
CGFloat relValue = (value - _minimumValue) / fabs(_minimumValue - _maximumValue);
// For RTL we invert the value
if (self.mdf_effectiveUserInterfaceLayoutDirection == UIUserInterfaceLayoutDirectionRightToLeft) {
relValue = 1 - relValue;
Expand All @@ -1093,7 +1093,7 @@ - (CGFloat)closestValueToTargetValue:(CGFloat)targetValue {

CGFloat scaledTargetValue = (targetValue - _minimumValue) / (_maximumValue - _minimumValue);
CGFloat snappedValue =
MDCRound((_numDiscreteValues - 1) * scaledTargetValue) / (_numDiscreteValues - 1);
round((_numDiscreteValues - 1) * scaledTargetValue) / (_numDiscreteValues - 1);
return (1 - snappedValue) * _minimumValue + snappedValue * _maximumValue;
}

Expand Down
5 changes: 2 additions & 3 deletions components/private/ThumbTrack/src/MDCThumbView.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#import "MaterialShadowElevations.h"
#import "MaterialShapeLibrary.h"
#import "MaterialShapes.h"
#import "MaterialMath.h"

@interface MDCThumbView ()

Expand Down Expand Up @@ -110,9 +109,9 @@ - (void)configureShapeGeneratorWithCornerRadius:(CGFloat)cornerRadius
CGFloat additionalRequiredHeight =
MAX(0, CGRectGetHeight(self.bounds) - visibleAreaSize.height);
CGFloat additionalRequiredWidth = MAX(0, CGRectGetWidth(self.bounds) - visibleAreaSize.width);
visibleAreaInsets.top = MDCCeil(additionalRequiredHeight * 0.5f);
visibleAreaInsets.top = ceil(additionalRequiredHeight * 0.5f);
visibleAreaInsets.bottom = additionalRequiredHeight - visibleAreaInsets.top;
visibleAreaInsets.left = MDCCeil(additionalRequiredWidth * 0.5f);
visibleAreaInsets.left = ceil(additionalRequiredWidth * 0.5f);
visibleAreaInsets.right = additionalRequiredWidth - visibleAreaInsets.left;

self.shapeGenerator.topLeftCornerOffset =
Expand Down

0 comments on commit eb82984

Please sign in to comment.