//
//  GSPathOperator.h
//  PathOperations
//
//  Created by Georg Seifert on 03.03.14.
//  Copyright (c) 2014 Georg Seifert. All rights reserved.
//

#import <GlyphsCore/GSPathSegment.h>
#import <GlyphsCore/GSBase.h>

void GSIntersectCubicCubicSegmentsOperations(GSSegmentStruct *P, GSSegmentStruct *Q, GSIntersectResultsStruct *results, int depth);

void GSIntersectQuadraticQuadraticSegmentsOperations(GSSegmentStruct *P, GSSegmentStruct *Q, GSIntersectResultsStruct *results, int depth);

bool GSSignificantT(CGFloat t);

@class GSPath;

CGFloat GSMultiplicator(NSPoint a, NSPoint b, NSPoint c);

// checks if all four points are on one line. But make sure to test if the offcurves are between the oncurves.
BOOL GSCubicCollinearish(CGPoint p[4], CGFloat eps);

typedef NS_ENUM(uint8_t, GSPathOperations) {
	GSRemoveOverlap,
	GSSubtract,
};

typedef NS_OPTIONS(uint8_t, GSRemoveOverlapOptions) {
	GSRemoveOverlapOptionsKeepOpenPaths = 1 << 1,
};

@interface GSPathOperator : NSObject

+ (BOOL)removeOverlapPaths:(NSMutableArray<GSPath *> *)paths italicAngle:(CGFloat)italicAngle error:(out NSError **)error;
/// Uses the `italicAngle` of the layer of the first path.
+ (BOOL)removeOverlapPaths:(NSMutableArray<GSPath *> *)paths error:(out NSError **)error;
// + (BOOL)removeOverlapPaths:(NSMutableArray<GSPath *> *)paths1 otherPaths:(NSMutableArray<GSPath *> *)paths2 error:(out NSError **)error;
+ (BOOL)removeOverlapPaths:(NSArray *)paths intoPen:(id<GSPenProtocol>)pen error:(out NSError **)error;
+ (BOOL)removeOverlapPaths:(NSArray *)paths intoPen:(NSObject<GSPenProtocol> *)pen options:(GSRemoveOverlapOptions)options italicAngle:(CGFloat)italicAngle error:(out NSError **)error;
+ (NSMutableArray<GSPathSegment *> *)removeOverlapSegments:(NSArray<GSPathSegment *> *)originalSegments error:(out NSError **)error NS_RETURNS_RETAINED;
+ (BOOL)subtractPaths:(NSArray<GSPath *> *)subtractPaths from:(NSMutableArray<GSPath *> *)paths error:(out NSError **)error;
+ (BOOL)subtractPaths:(NSArray<GSPath *> *)subtractPaths from:(NSMutableArray<GSPath *> *)paths keepOverlaps:(BOOL)keepOverlaps error:(out NSError **)error;
+ (BOOL)intersectPaths:(NSArray<GSPath *> *)intersectPaths with:(NSMutableArray<GSPath *> *)paths error:(out NSError **)error;
+ (NSArray *)segmentsFromPaths:(NSArray<GSPath *> *)paths;
+ (BOOL)addIntersections:(NSMutableArray<GSPathSegment *> *)segments;
+ (void)addIntersections:(NSMutableArray<GSPathSegment *> *)segments otherSegments:(NSMutableArray<GSPathSegment *> *)otherSegments;

@end
