<commit_before>//******************************************************************************
//
// Copyright (c) 2015 Microsoft Corporation. All rights reserved.
//
// This code is licensed under the MIT License (MIT).
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
//******************************************************************************

#import "UIKit/UIKit.h"
#import "CoreGraphics/CGPath.h"
#import "CoreGraphics/CGGeometry.h"
#import "CoreGraphics/CGContext.h"
#import "IwMalloc.h"
#import "StubReturn.h"

static CGAffineTransform* getTransform(UIBezierPath* path);

@implementation UIBezierPath {
    float _lineWidth;
    CGLineJoin _lineJoin;
    CGPathRef _path;
    BOOL _usesEvenOddFillRule;

    float* _pattern;
    NSInteger _patternCount;
    float _dashPhase;

    bool _hasTransform;
    CGAffineTransform _transform;
}

CGAffineTransform* getTransform(UIBezierPath* path) {
    if (path->_hasTransform) {
        return &path->_transform;
    } else {
        return NULL;
    }
}

/**
 @Status Interoperable
*/
+ (instancetype)bezierPathWithRoundedRect:(CGRect)rect byRoundingCorners:(UIRectCorner)roundingCorners cornerRadii:(CGSize)size {
    UIBezierPath* ret = [self new];

    CGRect innerRect;

    float radius = size.width;
    innerRect = CGRectInset(rect, float(radius), float(radius));

    CGFloat inside_right = innerRect.origin.x + innerRect.size.width;
    CGFloat outside_right = rect.origin.x + rect.size.width;
    CGFloat inside_bottom = innerRect.origin.y + innerRect.size.height;
    CGFloat outside_bottom = rect.origin.y + rect.size.height;

    CGFloat inside_top = innerRect.origin.y;
    CGFloat outside_top = rect.origin.y;
    CGFloat outside_left = rect.origin.x;

    CGPathMoveToPoint(ret->_path, getTransform(ret), innerRect.origin.x, outside_top);

    CGPathAddLineToPoint(ret->_path, getTransform(ret), inside_right, outside_top);
    CGPathAddArcToPoint(ret->_path, getTransform(ret), outside_right, outside_top, outside_right, inside_top, radius);
    CGPathAddLineToPoint(ret->_path, getTransform(ret), outside_right, inside_bottom);
    CGPathAddArcToPoint(ret->_path, getTransform(ret), outside_right, outside_bottom, inside_right, outside_bottom, radius);

    CGPathAddLineToPoint(ret->_path, getTransform(ret), innerRect.origin.x, outside_bottom);
    CGPathAddArcToPoint(ret->_path, NULL, outside_left, outside_bottom, outside_left, inside_bottom, radius);
    CGPathAddLineToPoint(ret->_path, NULL, outside_left, inside_top);
    CGPathAddArcToPoint(ret->_path, NULL, outside_left, outside_top, innerRect.origin.x, outside_top, radius);

    CGPathCloseSubpath(ret->_path);

    return [ret autorelease];
}

/**
 @Status Interoperable
*/
+ (instancetype)bezierPathWithRoundedRect:(CGRect)rect cornerRadius:(CGFloat)radius {
    UIBezierPath* ret = [self new];

    CGRect innerRect;

    innerRect = CGRectInset(rect, radius, radius);

    CGFloat inside_right = innerRect.origin.x + innerRect.size.width;
    CGFloat outside_right = rect.origin.x + rect.size.width;
    CGFloat inside_bottom = innerRect.origin.y + innerRect.size.height;
    CGFloat outside_bottom = rect.origin.y + rect.size.height;

    CGFloat inside_top = innerRect.origin.y;
    CGFloat outside_top = rect.origin.y;
    CGFloat outside_left = rect.origin.x;

    CGPathMoveToPoint(ret->_path, NULL, innerRect.origin.x, outside_top);

    CGPathAddLineToPoint(ret->_path, NULL, inside_right, outside_top);
    CGPathAddArcToPoint(ret->_path, NULL, outside_right, outside_top, outside_right, inside_top, radius);
    CGPathAddLineToPoint(ret->_path, NULL, outside_right, inside_bottom);
    CGPathAddArcToPoint(ret->_path, NULL, outside_right, outside_bottom, inside_right, outside_bottom, radius);

    CGPathAddLineToPoint(ret->_path, NULL, innerRect.origin.x, outside_bottom);
    CGPathAddArcToPoint(ret->_path, NULL, outside_left, outside_bottom, outside_left, inside_bottom, radius);
    CGPathAddLineToPoint(ret->_path, NULL, outside_left, inside_top);
    CGPathAddArcToPoint(ret->_path, NULL, outside_left, outside_top, innerRect.origin.x, outside_top, radius);

    CGPathCloseSubpath(ret->_path);

    return [ret autorelease];
}

/**
 @Status Interoperable
*/
+ (instancetype)bezierPathWithArcCenter:(CGPoint)center
                                 radius:(CGFloat)radius
                             startAngle:(CGFloat)startAngle
                               endAngle:(CGFloat)endAngle
                              clockwise:(BOOL)clockwise {
    UIBezierPath* ret = [self new];

    CGPathAddArc(ret->_path, NULL, center.x, center.y, radius, startAngle, endAngle, clockwise == FALSE);

    return [ret autorelease];
}<commit_msg>Fix starting position of arc in bezierPathWithArcCenter (#1864)<commit_after>//******************************************************************************
//
// Copyright (c) 2015 Microsoft Corporation. All rights reserved.
//
// This code is licensed under the MIT License (MIT).
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
//******************************************************************************

#import "UIKit/UIKit.h"
#import "CoreGraphics/CGPath.h"
#import "CoreGraphics/CGGeometry.h"
#import "CoreGraphics/CGContext.h"
#import "IwMalloc.h"
#import "StubReturn.h"

static CGAffineTransform* getTransform(UIBezierPath* path);

@implementation UIBezierPath {
    float _lineWidth;
    CGLineJoin _lineJoin;
    CGPathRef _path;
    BOOL _usesEvenOddFillRule;

    float* _pattern;
    NSInteger _patternCount;
    float _dashPhase;

    bool _hasTransform;
    CGAffineTransform _transform;
}

CGAffineTransform* getTransform(UIBezierPath* path) {
    if (path->_hasTransform) {
        return &path->_transform;
    } else {
        return NULL;
    }
}

/**
 @Status Interoperable
*/
+ (instancetype)bezierPathWithRoundedRect:(CGRect)rect byRoundingCorners:(UIRectCorner)roundingCorners cornerRadii:(CGSize)size {
    UIBezierPath* ret = [self new];

    CGRect innerRect;

    float radius = size.width;
    innerRect = CGRectInset(rect, float(radius), float(radius));

    CGFloat inside_right = innerRect.origin.x + innerRect.size.width;
    CGFloat outside_right = rect.origin.x + rect.size.width;
    CGFloat inside_bottom = innerRect.origin.y + innerRect.size.height;
    CGFloat outside_bottom = rect.origin.y + rect.size.height;

    CGFloat inside_top = innerRect.origin.y;
    CGFloat outside_top = rect.origin.y;
    CGFloat outside_left = rect.origin.x;

    CGPathMoveToPoint(ret->_path, getTransform(ret), innerRect.origin.x, outside_top);

    CGPathAddLineToPoint(ret->_path, getTransform(ret), inside_right, outside_top);
    CGPathAddArcToPoint(ret->_path, getTransform(ret), outside_right, outside_top, outside_right, inside_top, radius);
    CGPathAddLineToPoint(ret->_path, getTransform(ret), outside_right, inside_bottom);
    CGPathAddArcToPoint(ret->_path, getTransform(ret), outside_right, outside_bottom, inside_right, outside_bottom, radius);

    CGPathAddLineToPoint(ret->_path, getTransform(ret), innerRect.origin.x, outside_bottom);
    CGPathAddArcToPoint(ret->_path, NULL, outside_left, outside_bottom, outside_left, inside_bottom, radius);
    CGPathAddLineToPoint(ret->_path, NULL, outside_left, inside_top);
    CGPathAddArcToPoint(ret->_path, NULL, outside_left, outside_top, innerRect.origin.x, outside_top, radius);

    CGPathCloseSubpath(ret->_path);

    return [ret autorelease];
}

/**
 @Status Interoperable
*/
+ (instancetype)bezierPathWithRoundedRect:(CGRect)rect cornerRadius:(CGFloat)radius {
    UIBezierPath* ret = [self new];

    CGRect innerRect;

    innerRect = CGRectInset(rect, radius, radius);

    CGFloat inside_right = innerRect.origin.x + innerRect.size.width;
    CGFloat outside_right = rect.origin.x + rect.size.width;
    CGFloat inside_bottom = innerRect.origin.y + innerRect.size.height;
    CGFloat outside_bottom = rect.origin.y + rect.size.height;

    CGFloat inside_top = innerRect.origin.y;
    CGFloat outside_top = rect.origin.y;
    CGFloat outside_left = rect.origin.x;

    CGPathMoveToPoint(ret->_path, NULL, innerRect.origin.x, outside_top);

    CGPathAddLineToPoint(ret->_path, NULL, inside_right, outside_top);
    CGPathAddArcToPoint(ret->_path, NULL, outside_right, outside_top, outside_right, inside_top, radius);
    CGPathAddLineToPoint(ret->_path, NULL, outside_right, inside_bottom);
    CGPathAddArcToPoint(ret->_path, NULL, outside_right, outside_bottom, inside_right, outside_bottom, radius);

    CGPathAddLineToPoint(ret->_path, NULL, innerRect.origin.x, outside_bottom);
    CGPathAddArcToPoint(ret->_path, NULL, outside_left, outside_bottom, outside_left, inside_bottom, radius);
    CGPathAddLineToPoint(ret->_path, NULL, outside_left, inside_top);
    CGPathAddArcToPoint(ret->_path, NULL, outside_left, outside_top, innerRect.origin.x, outside_top, radius);

    CGPathCloseSubpath(ret->_path);

    return [ret autorelease];
}

/**
 @Status Interoperable
*/
+ (instancetype)bezierPathWithArcCenter:(CGPoint)center
                                 radius:(CGFloat)radius
                             startAngle:(CGFloat)startAngle
                               endAngle:(CGFloat)endAngle
                              clockwise:(BOOL)clockwise {
    UIBezierPath* ret = [self new];

    // Path needs to move to the actual start of the arc location otherwise CGPathAddArc will draw a line to this
    // start point instead.
    CGPathMoveToPoint(ret->_path, NULL, center.x + cos(startAngle) * radius, center.y + sin(startAngle) * radius);
    CGPathAddArc(ret->_path, NULL, center.x, center.y, radius, startAngle, endAngle, clockwise == FALSE);

    return [ret autorelease];
}
{'fraction_non_alphanumeric': 0.13103904698874919, 'fraction_numerical': 0.0011345372033657937, 'mean_word_length': 4.383206106870229, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 50, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6252250', 'n_tokens_mistral': 3344, 'n_tokens_neox': 3160, 'n_words': 736}