//  Created by Joe Becker on 3/7/05.
//  Copyright 2005 __MyCompanyName__. All rights reserved.

#import "Tick.h"

@implementation Tick

const float halfWidthInPixels = 3.;

- initFrom:(NSPoint)theStart to:(NSPoint)theEnd view:(id)theView record:(GmtShipTrackRecord *)obj
{
	[super initFrom:theStart to:theEnd view:theView record:obj];
	
	NSSize tmp2 = [view convertSize:NSMakeSize(halfWidthInPixels, halfWidthInPixels) fromView:nil];
	dx = tmp2.width;
	dy = tmp2.height;
	
	return self;
}

- (NSRect)bounds
{
	NSSize tmp2 = [view convertSize:NSMakeSize(halfWidthInPixels, halfWidthInPixels) fromView:nil];
	dx = tmp2.width;
	dy = tmp2.height;

	const float sloppyCoding = 0.99;
	NSPoint origin = [self end];
	NSRect minga = NSMakeRect(origin.x  - sloppyCoding, 
							  origin.y  - sloppyCoding, 
							  dx*sloppyCoding, 
							  dy*sloppyCoding);

	return minga;
	
	//	return NSMakeRect( start.x, start.y, fabs(start.x-end.x) + FLT_MIN, fabs(start.y-end.y) + FLT_MIN);
}

- (void)stroke
{	
	NSPoint origin = [self end];
	
	NSPoint left = NSMakePoint(origin.x-dx, origin.y-dy);
	NSPoint right= NSMakePoint(origin.x+dx, origin.y+dy);
	NSPoint top  = NSMakePoint(origin.x-dx, origin.y+dy);
	NSPoint bot  = NSMakePoint(origin.x+dx, origin.y-dy);
	
	[color set];
	[NSBezierPath strokeLineFromPoint:top  toPoint:bot];
	[NSBezierPath strokeLineFromPoint:left toPoint:right];
}

@end
