//
//  GSLayer+PathOperations.h
//  GlyphsCoreMini
//
//  Created by Georg Seifert on 31/01/2017.
//  Copyright © 2017 schriftgestaltung.de. All rights reserved.
//

#import <GlyphsCore/GSLayer.h>

typedef NS_ENUM(uint8_t, GSPathOperationOptions) {
	GSPathOperationOptionCheckSelection = 1 << 0,
	GSPathOperationOptionKeepOpenPath = 1 << 1,
	GSPathOperationOptionCompatible = 1 << 2,
};

@interface GSLayer (PathOperations)

/// Removes overlaps between applicable paths.
///
/// When selection checking is enabled but no path is selected, all applicable paths are processed.
///
/// - Parameter checkSelection: Whether to restrict the operation to paths containing selected nodes.
/// - Returns: Whether the operation completed successfully.
- (BOOL)removeOverlapCheckSelection:(BOOL)checkSelection error:(out NSError **)error;

/// Removes overlaps between applicable paths using explicit open-path and grid settings.
///
/// When selection checking is enabled but no path is selected, all applicable paths are processed.
///
/// - Parameter checkSelection: Whether to restrict the operation to paths containing selected nodes.
/// - Parameter keepOpenPaths: Whether to preserve open paths that do not explicitly participate in overlap removal.
/// - Returns: Whether the operation completed successfully.
- (BOOL)removeOverlapCheckSelection:(BOOL)checkSelection keepOpenPaths:(BOOL)keepOpenPaths grid:(GSGridSettings)grid error:(out NSError **)error;

/// Removes overlaps between paths according to a set of options.
///
/// - Returns: Whether the operation completed successfully.
- (BOOL)removeOverlap:(GSPathOperationOptions)options grid:(GSGridSettings)grid error:(out NSError **)error;

/// Subtracts selected paths from unselected paths.
///
/// - Returns: Whether the operation completed successfully.
- (BOOL)pathSubtract:(out NSError **)error;

/// Subtracts selected paths from unselected paths.
///
/// - Parameter keepOverlaps: Whether to preserve overlapping path fragments in the result.
/// - Returns: Whether the operation completed successfully.
- (BOOL)pathSubtractKeepOverlaps:(BOOL)keepOverlaps error:(out NSError **)error;

/// Subtracts one mutable path collection from another.
///
/// Both collections are replaced with operation results.
///
/// - Parameter selectedPaths: The paths to subtract.
/// - Parameter notSelectedPaths: The paths from which to subtract.
/// - Parameter keepOverlaps: Whether to preserve overlapping path fragments in the result.
/// - Returns: Whether the operation completed successfully.
- (BOOL)pathSubtract:(NSMutableArray *)selectedPaths from:(NSMutableArray *)notSelectedPaths keepOverlaps:(BOOL)keepOverlaps error:(out NSError **)error;

/// Intersects selected paths with unselected paths.
///
/// - Returns: Whether the operation completed successfully.
- (BOOL)pathIntersect:(out NSError **)error;

/// Intersects applicable selected and unselected paths.
///
/// - Parameter checkSelection: Whether to use the layer selection to partition the paths.
/// - Returns: Whether the operation completed successfully.
- (BOOL)pathIntersectCheckSelection:(BOOL)checkSelection error:(out NSError **)error;

@end
