Last active
December 11, 2015 14:48
-
-
Save jhoughjr/4616530 to your computer and use it in GitHub Desktop.
this seems slow
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-(void) angleDidChange:(NSNotification*) notifcation | |
{ | |
DLog(@""); | |
_timesAngleDidChangeWasCalled++; | |
//// | |
const float theWidth = [self bounds].size.width; | |
const float myRad = [_circle radius]; | |
const float mySin = [_angle sine] * myRad; | |
const float myCos = [_angle cosine] * myRad; | |
const float myTan = [_angle tangent] * myRad; | |
const float centerX = [_circle centerPoint].x; | |
const float centerY = [_circle centerPoint].y; | |
const CGPoint centerPoint = CGPointMake(centerX, centerY); | |
UIBezierPath* newRadianPathFinal = [UIBezierPath bezierPathWithArcCenter:CGPointMake(centerX, centerY) | |
radius:myRad | |
startAngle:0.0f | |
endAngle:M_PI * 2.0f - [[[notifcation userInfo] objectForKey:@"radians"] doubleValue] | |
clockwise:NO]; | |
[_radianLayer setPath:[newRadianPathFinal CGPath]]; | |
UIBezierPath* newSinePath = [UIBezierPath bezierPath]; | |
[newSinePath moveToPoint:CGPointMake(centerX + myCos, centerY)]; | |
[newSinePath addLineToPoint:CGPointMake(centerX + myCos, centerY - mySin)]; | |
//[_sineAnimation setFromValue:(id)[_sineLayer path]]; | |
[_sineLayer setPath:[newSinePath CGPath]]; | |
UIBezierPath* newCosinePath = [UIBezierPath bezierPath]; | |
[newCosinePath moveToPoint:centerPoint]; | |
[newCosinePath addLineToPoint:CGPointMake(centerX + myCos, centerY)]; | |
// [_cosineAnimation setFromValue:(id) [_cosineLayer path]]; | |
[_cosineLayer setPath:[newCosinePath CGPath]]; | |
UIBezierPath* newTangentPath = [UIBezierPath bezierPath]; | |
//[newTangentPath moveToPoint:CGPointMake(centerX + myRad, centerY)]; | |
[newTangentPath addLineToPoint:CGPointMake(centerX + myRad, centerY - myTan)]; | |
// [_tangentAnimation setFromValue:(id)[_tangentLayer path]]; | |
[_tangentLayer setPath:[newTangentPath CGPath]]; | |
UIBezierPath* newCosecantPath = [UIBezierPath bezierPath]; | |
[newCosecantPath moveToPoint:centerPoint]; | |
[newCosecantPath addLineToPoint:CGPointMake(centerX + [_angle cotangent] * myRad, centerY - myRad)]; | |
//[_cosecantAnimation setFromValue:(id) [_cosecantLayer path]]; | |
[_cosecantLayer setPath:[newCosecantPath CGPath]]; | |
UIBezierPath* newSecantPath = [UIBezierPath bezierPath]; | |
[newSecantPath moveToPoint:centerPoint]; | |
[newSecantPath addLineToPoint:CGPointMake(centerX + myRad, centerY - myTan)]; | |
// [_secantAnimation setFromValue:(id)[_secantLayer path]]; | |
[_secantLayer setPath:[newSecantPath CGPath]]; | |
UIBezierPath* newCotangentPath = [UIBezierPath bezierPath]; | |
[newCotangentPath moveToPoint:CGPointMake(centerX, centerY - myRad)]; | |
[newCotangentPath addLineToPoint:CGPointMake(centerX + [_angle cotangent] * myRad, centerY - myRad)]; | |
// [_cotangentAnimation setFromValue:(id)[_cotangentLayer path]]; | |
[_cotangentLayer setPath:[newCotangentPath CGPath]]; | |
// textLayers | |
[_sineValueTextLayer setPosition:CGPointMake(theWidth - 5, centerY - mySin - 8)]; | |
[_sineValueTextLayer setString:[NSString stringWithFormat:@"%0.4f", [_angle sine]]]; | |
[_cosineValueTextLayer setString:[NSString stringWithFormat:@"%0.4f", [_angle cosine]]]; | |
[_cosineValueTextLayer setPosition:CGPointMake(centerX + myCos + 5, 40)]; | |
[_tangentValueTextLayer setString:[NSString stringWithFormat:@"%0.4f", [_angle tangent]]]; | |
[_tangentValueTextLayer setPosition:CGPointMake(theWidth - 5 , centerY - myTan - 8)] ; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// this allows a tap on the view to change the angle | |
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event | |
{ | |
DLog(@""); | |
UITouch *touch = [[event allTouches] anyObject]; | |
CGPoint location = [touch locationInView:touch.view]; | |
CGFloat centerXPosition = [self bounds].size.width/2.0f; | |
CGFloat centerYPosition = [self bounds].size.height/2.0f; | |
CGFloat adjustedXTapPosition; | |
CGFloat adjustedYTapPosition; | |
// DLog(@"tap location is %@", [NSValue valueWithCGPoint:location]); | |
if (location.x < centerXPosition) { | |
CGFloat xDifference = centerXPosition - location.x; | |
//DLog(@"difference = %f", xDifference); | |
adjustedXTapPosition = xDifference * -1.0f; | |
//DLog(@"adjustedXTapPosition = %f", adjustedXTapPosition); | |
} | |
if (location.x == centerXPosition) { | |
adjustedXTapPosition = 0.0f; | |
// DLog(@"adjustedTapPosition = %f", adjustedXTapPosition); | |
} | |
if (location.x > centerXPosition) { | |
CGFloat xDifference = location.x - centerXPosition; | |
//DLog(@"difference = %f", xDifference); | |
adjustedXTapPosition = xDifference;// | |
// DLog(@"adjustedXTapPosition = %f", adjustedXTapPosition); | |
} | |
if (location.y < centerYPosition) { | |
CGFloat yDifference = centerYPosition - location.y; | |
//DLog(@"yDifference = %f", yDifference); | |
adjustedYTapPosition = yDifference ; | |
// DLog(@"adjustedYTapPosition = %f", adjustedYTapPosition); | |
} | |
if (location.y == centerYPosition) { | |
adjustedYTapPosition = 0.0f; | |
} | |
if (location.y > centerYPosition) { | |
CGFloat yDifference = location.y - centerYPosition; | |
// DLog(@"yDifference = %f", yDifference); | |
adjustedYTapPosition = yDifference * -1.0f; | |
// DLog(@"adjustedYTapPosition = %f", adjustedYTapPosition); | |
} | |
double angle = atan2(adjustedYTapPosition, adjustedXTapPosition); | |
if ( angle < 0) | |
{ | |
angle = M_PI + ( M_PI - (angle * -1.0f)); | |
} | |
// tell our delegate we wish to set a new angle in its model | |
[_unitCircleViewDelegate circleViewDidPickAngle:angle]; | |
} | |
// this allows a tap, or a drag | |
- (void) touchesMoved:(NSSet *)touches withEvent: (UIEvent *)event | |
{ | |
[self touchesBegan:touches withEvent:event]; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma mark <PHUnitCircleViewDelegate> | |
-(void) circleViewDidPickAngle:(double)radians | |
{ | |
DLog(@""); | |
// jsut set the angle | |
// ill update ui when i respond to the notification | |
[_angle setRadians:radians]; | |
} | |
// in PHAngle.m | |
-(void) setRadians: (double) newRadians | |
{ | |
_radians = newRadians; | |
// post notifications of angle change for interested objects to observe | |
[self notify]; | |
} | |
-(void) notify | |
{ | |
DLog(@""); | |
NSNumber* radiansValue = [NSNumber numberWithDouble: [self radians]] ; | |
NSNumber* sineValue = [NSNumber numberWithDouble: [self sine]]; | |
NSNumber* cosineValue = [NSNumber numberWithDouble:[self cosine]]; | |
NSNumber* tangentValue = [NSNumber numberWithDouble:[self tangent]]; | |
NSNumber* cosecantValue = [NSNumber numberWithDouble:[self cosecant]]; | |
NSNumber* secantValue = [NSNumber numberWithDouble: [self secant]]; | |
NSNumber* cotangentValue = [NSNumber numberWithDouble: [self cotangent]]; | |
if (!_angleID) { | |
_angleID = @"defaultID"; | |
} | |
NSArray* keysArray = @[@"angleID", @"radians", @"sine", @"cosine", @"tangent", @"cosecant", @"secant",@"cotangent"]; | |
NSArray* objectsArray = @[_angleID,radiansValue, sineValue, cosineValue, tangentValue, cosecantValue, secantValue, cotangentValue]; | |
NSDictionary* dict = [NSDictionary dictionaryWithObjects: objectsArray | |
forKeys: keysArray]; | |
[[NSNotificationCenter defaultCenter] postNotificationName: @"angleDidChangeNotification" | |
object: nil | |
userInfo: dict]; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment