//
//  GSGuide.h
//  GlyphsCore
//
//  Created by Georg Seifert on 03.02.10.
//  Copyright 2010 schriftgestaltung.de. All rights reserved.
//

#import <GlyphsCore/GSElement.h>
#import <GlyphsCore/GSUserDataProtocol.h>

@class GSHandle;
@class GSLayer;
@class FTPointArray;

/**
 Enum defining the types of guides.
 */
typedef NS_ENUM(uint8_t, GSGuideType) {
	/// A guide that is a straight line.
	GSGuideTypeLine = 0,
	/// A guide that is a circle.
	GSGuideTypeCircle,
	/// A guide that is a rectangle.
	GSGuideTypeRect,
};

/**
 The Guide object
 */
@interface GSGuide : GSElement <GSUserDataProtocol>

/// The angle of the guide.
@property (nonatomic) CGFloat angle;

/// Indicates if the angle is locked.
@property (nonatomic) BOOL lockAngle;

/// Indicates if the guide has a slope.
@property (nonatomic) BOOL hasSlope;

/// The slope UI of the guide.
@property (nonatomic, copy) NSString *slopeUI;

/**
 The handle of the guide.

 @see GSHandle
 */
@property (nonatomic, strong) GSHandle *handle;

/// If active, the guide shows the distances between the intersections with the outline.
@property (nonatomic, assign) BOOL showMeasurement;

/// The intersections with the outline.
@property (nonatomic, strong) FTPointArray *intersections;

/// The name of the guide.
@property (nonatomic, retain) NSString *name;

/// A filter that allows to show the guide only in certain glyphs.
@property (nonatomic, retain) NSPredicate *filter;

/// The grid of the guide.
@property (nonatomic, assign) CGFloat grid;

/// The length of the guide.
@property (nonatomic, assign) CGFloat length;

/// The size of the guide.
@property (nonatomic, assign) NSSize size;

/// The type of the guide.
@property (nonatomic, assign) GSGuideType type;

/// The type of the guide as a string.
@property (nonatomic, assign) NSString *typeString;

/**
 Checks if the guide is equal to another guide.

 @param other The other guide to compare against.
 @return YES if the guides are equal, NO otherwise.
 */
- (BOOL)isEqualToGuide:(GSGuide *)other;

/**
 Updates the intersections list for a given layer.

 @param layer The layer to calculate intersections for.
 */
- (void)calculateIntersectionsForLayer:(GSLayer *)layer;

/**
 Checks if the guide is visible in a given glyph.

 @param glyph The glyph to check visibility for.
 @return YES if the guide is visible, NO otherwise.
 */
- (BOOL)visibleInGlyph:(GSGlyph *)glyph;

/**
 Checks if a point is close enough to the guide.

 @param aPoint The point to check.
 @param layer The layer to check within.
 @param tolerance The tolerance for the hit test.
 @return YES if the point is close enough to the guide, NO otherwise.
 */
- (BOOL)hitTest:(NSPoint)aPoint inLayer:(GSLayer *)layer tolerance:(CGFloat)tolerance;

/**
 Returns the beginning point for the layer with the specified width.

 @param width The width of the layer.
 @return The beginning point.
 */
- (NSPoint)beginPointForLayerWidth:(CGFloat)width;

/**
 Returns the end point for the layer with the specified width.

 @param width The width of the layer.
 @return The end point.
 */
- (NSPoint)endPointForLayerWidth:(CGFloat)width;

@end
