Archived
1

Corrected Fractions' property name: nominator to numerator

This commit is contained in:
Kim Wittenburg
2015-01-09 15:58:15 +01:00
parent 1f7e924c19
commit 1a8dd6e901
7 changed files with 31 additions and 32 deletions

View File

@@ -145,7 +145,6 @@
if (!selectWords && !extendingSelection && (locationInElement == 0 || locationInTarget == targetExpression.countSymbols)) { if (!selectWords && !extendingSelection && (locationInElement == 0 || locationInTarget == targetExpression.countSymbols)) {
// First or last index in an element or expression // First or last index in an element or expression
// Last element in the expression
if (locationInTarget == targetExpression.countSymbols) { if (locationInTarget == targetExpression.countSymbols) {
// The selection is inside a function and should proceed // The selection is inside a function and should proceed
if (selectionPath.length > 1) { if (selectionPath.length > 1) {
@@ -805,7 +804,7 @@
if (self.selection.length == 0) { if (self.selection.length == 0) {
MPExpression *targetExpression = [self.expressionStorage elementAtIndexPath:[self.selection.location indexPathByRemovingLastIndex]]; MPExpression *targetExpression = [self.expressionStorage elementAtIndexPath:[self.selection.location indexPathByRemovingLastIndex]];
NSInteger index = self.selection.location.lastIndex; NSInteger index = self.selection.location.lastIndex;
NSRange nominatorSymbols = NSMakeRange(index, 0); NSRange numeratorSymbols = NSMakeRange(index, 0);
while (--index >= 0) { while (--index >= 0) {
id<MPExpressionElement> symbol = [targetExpression symbolAtIndex:index]; id<MPExpressionElement> symbol = [targetExpression symbolAtIndex:index];
if ([symbol isString]) { if ([symbol isString]) {
@@ -814,33 +813,33 @@
toReferenceFrame:MPTokenReferenceFrame]; toReferenceFrame:MPTokenReferenceFrame];
id<MPToken> token = [targetExpression tokenAtIndex:tokenIndex]; id<MPToken> token = [targetExpression tokenAtIndex:tokenIndex];
if (token.tokenType == MPNumberToken || token.tokenType == MPVariableToken || token.tokenType == MPElementaryFunctionToken) { if (token.tokenType == MPNumberToken || token.tokenType == MPVariableToken || token.tokenType == MPElementaryFunctionToken) {
nominatorSymbols.location--; numeratorSymbols.location--;
nominatorSymbols.length++; numeratorSymbols.length++;
} else { } else {
break; break;
} }
} else if (nominatorSymbols.length == 0) { } else if (numeratorSymbols.length == 0) {
nominatorSymbols.location--; numeratorSymbols.location--;
nominatorSymbols.length++; numeratorSymbols.length++;
} else { } else {
break; break;
} }
} }
MPExpression *nominatorExpression = [targetExpression subexpressionWithRange:nominatorSymbols MPExpression *numeratorExpression = [targetExpression subexpressionWithRange:numeratorSymbols
referenceFrame:MPSymbolReferenceFrame]; referenceFrame:MPSymbolReferenceFrame];
MPFractionFunction *function = [[MPFractionFunction alloc] init]; MPFractionFunction *function = [[MPFractionFunction alloc] init];
function.nominatorExpression = nominatorExpression; function.numeratorExpression = numeratorExpression;
[targetExpression replaceItemsInRange:nominatorSymbols referenceFrame:MPSymbolReferenceFrame withElements:@[function]]; [targetExpression replaceItemsInRange:numeratorSymbols referenceFrame:MPSymbolReferenceFrame withElements:@[function]];
NSUInteger functionElementIndex = [targetExpression convertIndex:nominatorSymbols.location NSUInteger functionElementIndex = [targetExpression convertIndex:numeratorSymbols.location
fromReferenceFrame:MPSymbolReferenceFrame fromReferenceFrame:MPSymbolReferenceFrame
toReferenceFrame:MPElementReferenceFrame]; toReferenceFrame:MPElementReferenceFrame];
NSUInteger selectedSubexpression = nominatorSymbols.length == 0 ? 0 : 1; NSUInteger selectedSubexpression = numeratorSymbols.length == 0 ? 0 : 1;
self.selection = MPMakeRangePath([[[self.selection.location indexPathByReplacingLastIndexWithIndex:functionElementIndex] indexPathByAddingIndex:selectedSubexpression] indexPathByAddingIndex:0], 0); self.selection = MPMakeRangePath([[[self.selection.location indexPathByReplacingLastIndexWithIndex:functionElementIndex] indexPathByAddingIndex:selectedSubexpression] indexPathByAddingIndex:0], 0);
} else { } else {
MPExpression *selectedElementsExpression = [self.expressionStorage subexpressionWithRangePath:self.selection MPExpression *selectedElementsExpression = [self.expressionStorage subexpressionWithRangePath:self.selection
referenceFrame:MPSymbolReferenceFrame]; referenceFrame:MPSymbolReferenceFrame];
MPFractionFunction *function = [[MPFractionFunction alloc] init]; MPFractionFunction *function = [[MPFractionFunction alloc] init];
function.nominatorExpression = selectedElementsExpression; function.numeratorExpression = selectedElementsExpression;
[self.expressionStorage replaceItemsInRangePath:self.selection [self.expressionStorage replaceItemsInRangePath:self.selection
referenceFrame:MPSymbolReferenceFrame referenceFrame:MPSymbolReferenceFrame
withElements:@[function]]; withElements:@[function]];

View File

@@ -23,21 +23,21 @@
@class MPFractionFunction @class MPFractionFunction
@abstract This class represents a fraction. @abstract This class represents a fraction.
@discussion A fraction has two children: the nominator and the denominator. @discussion A fraction has two children: the numerator and the denominator.
Typically it is displayed with a horizontal bar between the two Typically it is displayed with a horizontal bar between the two
child expressions which are on top and below the bar child expressions which are on top and below the bar
respectively. When a fraction is evaluated the nominator is respectively. When a fraction is evaluated the numerator is
divided by the denominator. divided by the denominator.
*/ */
@interface MPFractionFunction : MPFunction @interface MPFractionFunction : MPFunction
/*! /*!
@property nominatorExpression @property numeratorExpression
@abstract The receiver's nominator. @abstract The receiver's numerator.
@discussion The nominator must not define a variable. @discussion The numerator must not define a variable.
*/ */
@property (nonatomic, strong) MPExpression *nominatorExpression; /* Index 0 */ @property (nonatomic, strong) MPExpression *numeratorExpression; /* Index 0 */
/*! /*!

View File

@@ -15,13 +15,13 @@
@implementation MPFractionFunction @implementation MPFractionFunction
MPFunctionAccessorImplementation(NominatorExpression, _nominatorExpression) MPFunctionAccessorImplementation(NumeratorExpression, _numeratorExpression)
MPFunctionAccessorImplementation(DenominatorExpression, _denominatorExpression) MPFunctionAccessorImplementation(DenominatorExpression, _denominatorExpression)
- (NSArray *)childrenAccessors - (NSArray *)childrenAccessors
{ {
return @[@"nominatorExpression", @"denominatorExpression"]; return @[@"numeratorExpression", @"denominatorExpression"];
} }
@@ -33,7 +33,7 @@ MPFunctionAccessorImplementation(DenominatorExpression, _denominatorExpression)
- (NSString *)description - (NSString *)description
{ {
return [NSString stringWithFormat:@"%@ / %@", self.nominatorExpression, self.denominatorExpression]; return [NSString stringWithFormat:@"%@ / %@", self.numeratorExpression, self.denominatorExpression];
} }
@end @end

View File

@@ -24,7 +24,7 @@
@abstract A fraction function layout displays a <code>@link @abstract A fraction function layout displays a <code>@link
//apple_ref/occ/cl/MPFractionFunction@/link</code>. //apple_ref/occ/cl/MPFractionFunction@/link</code>.
@discussion The nominator is displayed above the denominator. Between the two @discussion The numerator is displayed above the denominator. Between the two
children a horizontal bar is drawn. children a horizontal bar is drawn.
*/ */
@interface MPFractionFunctionLayout : MPFunctionLayout @interface MPFractionFunctionLayout : MPFunctionLayout

View File

@@ -50,9 +50,9 @@
{ {
NSRect bounds = self.bounds; NSRect bounds = self.bounds;
if (index == 0) { if (index == 0) {
NSRect nominatorBounds = [self childLayoutAtIndex:0].bounds; NSRect numeratorBounds = [self childLayoutAtIndex:0].bounds;
CGFloat y = MPFractionMiddle + kFractionFunctionLineWidth / 2 - nominatorBounds.origin.y; CGFloat y = MPFractionMiddle + kFractionFunctionLineWidth / 2 - numeratorBounds.origin.y;
return NSMakePoint((bounds.size.width - nominatorBounds.size.width) / 2, y); return NSMakePoint((bounds.size.width - numeratorBounds.size.width) / 2, y);
} else { } else {
NSRect denominatorBounds = [self childLayoutAtIndex:1].bounds; NSRect denominatorBounds = [self childLayoutAtIndex:1].bounds;
CGFloat y = MPFractionMiddle - kFractionFunctionLineWidth / 2; CGFloat y = MPFractionMiddle - kFractionFunctionLineWidth / 2;
@@ -80,13 +80,13 @@
- (NSRect)generateBounds - (NSRect)generateBounds
{ {
NSRect nominatorBounds = [self childLayoutAtIndex:0].bounds; NSRect numeratorBounds = [self childLayoutAtIndex:0].bounds;
NSRect denominatorBounds = [self childLayoutAtIndex:1].bounds; NSRect denominatorBounds = [self childLayoutAtIndex:1].bounds;
NSRect bounds; NSRect bounds;
bounds.origin.x = 0; bounds.origin.x = 0;
bounds.origin.y = MPFractionMiddle - kFractionFunctionLineWidth / 2 - denominatorBounds.size.height; bounds.origin.y = MPFractionMiddle - kFractionFunctionLineWidth / 2 - denominatorBounds.size.height;
bounds.size.width = MAX(nominatorBounds.size.width, denominatorBounds.size.width) + 2 * kFractionFunctionHorizontalInset; bounds.size.width = MAX(numeratorBounds.size.width, denominatorBounds.size.width) + 2 * kFractionFunctionHorizontalInset;
bounds.size.height = nominatorBounds.size.height + denominatorBounds.size.height + kFractionFunctionLineWidth; bounds.size.height = numeratorBounds.size.height + denominatorBounds.size.height + kFractionFunctionLineWidth;
return bounds; return bounds;
} }

View File

@@ -24,7 +24,7 @@
@abstract Represens a <code>@link @abstract Represens a <code>@link
//apple_ref/occ/cl/MPFractionFunction@/link</code>. //apple_ref/occ/cl/MPFractionFunction@/link</code>.
@discussion A fraction is evaluating by dividing the nominator by the @discussion A fraction is evaluating by dividing the numerator by the
denominator. denominator.
*/ */
@interface MPFractionTerm : MPFunctionTerm @interface MPFractionTerm : MPFunctionTerm

View File

@@ -16,7 +16,7 @@
- (NSDecimalNumber *)doEvaluation:(NSError *__autoreleasing *)error - (NSDecimalNumber *)doEvaluation:(NSError *__autoreleasing *)error
{ {
MPEvaluateExpression(nominator, 0); MPEvaluateExpression(numerator, 0);
MPEvaluateExpression(denominator, 1); MPEvaluateExpression(denominator, 1);
if ([denominator isEqualToNumber:@0]) { if ([denominator isEqualToNumber:@0]) {
if (error) { if (error) {
@@ -26,7 +26,7 @@
} }
return nil; return nil;
} else { } else {
return [nominator decimalNumberByDividingBy:denominator]; return [numerator decimalNumberByDividingBy:denominator];
} }
} }