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

View File

@@ -23,21 +23,21 @@
@class MPFractionFunction
@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
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.
*/
@interface MPFractionFunction : MPFunction
/*!
@property nominatorExpression
@abstract The receiver's nominator.
@property numeratorExpression
@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
MPFunctionAccessorImplementation(NominatorExpression, _nominatorExpression)
MPFunctionAccessorImplementation(NumeratorExpression, _numeratorExpression)
MPFunctionAccessorImplementation(DenominatorExpression, _denominatorExpression)
- (NSArray *)childrenAccessors
{
return @[@"nominatorExpression", @"denominatorExpression"];
return @[@"numeratorExpression", @"denominatorExpression"];
}
@@ -33,7 +33,7 @@ MPFunctionAccessorImplementation(DenominatorExpression, _denominatorExpression)
- (NSString *)description
{
return [NSString stringWithFormat:@"%@ / %@", self.nominatorExpression, self.denominatorExpression];
return [NSString stringWithFormat:@"%@ / %@", self.numeratorExpression, self.denominatorExpression];
}
@end

View File

@@ -24,7 +24,7 @@
@abstract A fraction function layout displays a <code>@link
//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.
*/
@interface MPFractionFunctionLayout : MPFunctionLayout

View File

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

View File

@@ -24,7 +24,7 @@
@abstract Represens a <code>@link
//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.
*/
@interface MPFractionTerm : MPFunctionTerm

View File

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