-
Notifications
You must be signed in to change notification settings - Fork 254
Behavior-preserving refactor — remove dead row-style state, share limit-gap math #218
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1707,6 +1707,18 @@ - (MTDisplay*) makeLargeOp:(MTLargeOperator*) op | |
| } | ||
| } | ||
|
|
||
| - (CGFloat) upperLimitGapFor:(MTDisplay*)limit | ||
| { | ||
| return MAX(_styleFont.mathTable.upperLimitGapMin, | ||
| _styleFont.mathTable.upperLimitBaselineRiseMin - limit.descent); | ||
| } | ||
|
|
||
| - (CGFloat) lowerLimitGapFor:(MTDisplay*)limit | ||
| { | ||
| return MAX(_styleFont.mathTable.lowerLimitGapMin, | ||
| _styleFont.mathTable.lowerLimitBaselineDropMin - limit.ascent); | ||
| } | ||
|
Comment on lines
+1716
to
+1720
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To ensure robust defensive programming and prevent potential issues if this helper is reused in the future, add a parameter assertion to verify that - (CGFloat) lowerLimitGapFor:(MTDisplay*)limit
{
NSParameterAssert(limit);
return MAX(_styleFont.mathTable.lowerLimitGapMin,
_styleFont.mathTable.lowerLimitBaselineDropMin - limit.ascent);
}
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Declining for the same reason as the upper-limit thread: caller guards with |
||
|
|
||
| - (MTDisplay*) addLimitsToDisplay:(MTDisplay*) display forOperator:(MTLargeOperator*) op delta:(CGFloat)delta | ||
| { | ||
| // If there is no subscript or superscript, just return the current display | ||
|
|
@@ -1726,12 +1738,10 @@ - (MTDisplay*) addLimitsToDisplay:(MTDisplay*) display forOperator:(MTLargeOpera | |
| NSAssert(superScript || subScript, @"Atleast one of superscript or subscript should have been present."); | ||
| MTLargeOpLimitsDisplay* opsDisplay = [[MTLargeOpLimitsDisplay alloc] initWithNucleus:display upperLimit:superScript lowerLimit:subScript limitShift:delta/2 extraPadding:0]; | ||
| if (superScript) { | ||
| CGFloat upperLimitGap = MAX(_styleFont.mathTable.upperLimitGapMin, _styleFont.mathTable.upperLimitBaselineRiseMin - superScript.descent); | ||
| opsDisplay.upperLimitGap = upperLimitGap; | ||
| opsDisplay.upperLimitGap = [self upperLimitGapFor:superScript]; | ||
| } | ||
| if (subScript) { | ||
| CGFloat lowerLimitGap = MAX(_styleFont.mathTable.lowerLimitGapMin, _styleFont.mathTable.lowerLimitBaselineDropMin - subScript.ascent); | ||
| opsDisplay.lowerLimitGap = lowerLimitGap; | ||
| opsDisplay.lowerLimitGap = [self lowerLimitGapFor:subScript]; | ||
| } | ||
| opsDisplay.position = _currentPosition; | ||
| opsDisplay.range = op.indexRange; | ||
|
|
@@ -2042,9 +2052,10 @@ - (MTDisplay*) buildStackConstruction:(MTMathStackConstruction*)construction | |
|
|
||
| case kMTMathStackConstructionMathList: { | ||
| return [MTTypesetter createLineForMathList:construction.list | ||
| font:_font | ||
| style:construction.listStyle | ||
| cramped:construction.listCramped]; | ||
| font:_font | ||
| style:self.scriptStyle | ||
| cramped:(role == kMTStackRoleOver ? self.superScriptCramped | ||
| : self.subscriptCramped)]; | ||
| } | ||
|
|
||
| case kMTMathStackConstructionRule: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To ensure robust defensive programming and prevent potential issues if this helper is reused in the future, add a parameter assertion to verify that
limitis notnilbefore accessing its properties.- (CGFloat) upperLimitGapFor:(MTDisplay*)limit { NSParameterAssert(limit); return MAX(_styleFont.mathTable.upperLimitGapMin, _styleFont.mathTable.upperLimitBaselineRiseMin - limit.descent); }There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Declining. Both call sites guard with
if (superScript)/if (subScript)immediately above (MTTypesetter.m:1740-1745), so nil can't reach the helper today. And even if it did, sendingdescent/ascentto a nil receiver returns 0 in Obj-C, soMAX(upperLimitGapMin, upperLimitBaselineRiseMin - 0)would yield a valid CGFloat — not a crash.NSParameterAssertis also a no-op in release builds (NS_BLOCK_ASSERTIONS), so it would only signal in debug. Helper is private to MTTypesetter; no future caller to defend against (YAGNI).