Implement menclose notation "phasorangle"

RESOLVED FIXED in mozilla32

Status

()

defect
RESOLVED FIXED
6 years ago
5 years ago

People

(Reporter: fredw, Assigned: bkrzno)

Tracking

(Blocks 1 bug, {dev-doc-complete})

Trunk
mozilla32
Points:
---
Dependency tree / graph
Bug Flags:
in-testsuite +

Firefox Tracking Flags

(Not tracked)

Details

(Whiteboard: [mentor=fredw][lang=c++])

Attachments

(2 attachments, 12 obsolete attachments)

979 bytes, text/html
Details
16.21 KB, patch
Details | Diff | Splinter Review
Reporter

Description

6 years ago
A future version of MathML3 will add "phasorangle" to the list of suggested notations:

http://www.w3.org/Math/draft-spec/chapter3-d.html#id.3.3.9.3

Comment from Neil Soiffer: "The key part (at least for me to implement it in MathPlayer) was to see that it uses a slope of 2 (angle = tan^-1(2)) for the angled line and that value seems to work reasonably well.  It was relatively simple to implement in MathPlayer. I and the rest of the MathML WG hope that it will be easy to add to MathJax, FireFox, and Webkit."

For people willing to work on this: the code to modify is

http://dxr.mozilla.org/mozilla-central/source/layout/mathml/nsMathMLmencloseFrame.cpp

probably the bottom line will be drawn with the same line as NOTATION_BOTTOM while the other line will need a specific drawing in nsDisplayNotation::Paint. This will be very similar to bug 875294, so attachment 757830 [details] [diff] [review] should help to find the places to modify.
I'd like to take it up.
I don't have knowledge of the layout. So, it take time to understand. Please pardon me developing slow.
Assignee

Comment 2

6 years ago
Posted patch menclose-phasor.patch (obsolete) — Splinter Review
proposed patch
Attachment #819007 - Flags: review?(fred.wang)
Reporter

Comment 3

6 years ago
Thanks, I haven't tested but the patch looks good. I'm not familiar with this phasorangle notation, but it seems to me that with your code the slanted line may be drawn over the content. Is that what we want? If not, I think you must update dx_left to leave some space to draw that slanted line.

Also, can you please create a reftest:
https://developer.mozilla.org/en-US/docs/Creating_reftest-based_unit_tests

For example a != reftest <menclose> vs <menclose notation="phasorangle">

You can also do something more complicated to get a == reftest. First, draw your notation in a phasorangle.html page with

<div style="position: absolute; top: 20px; left; 20px">
<math>
<mspace height="100px" depth="100px"/>
<menclose notation="phasorangle"><mspace width="100px" height="50px" mathbackground="red"/></menclose>
</math>
</div>

then on the same page, use

<div style="position: absolute; top: 20px; left; 20px">
<math>
<mspace height="100px" depth="100px"/>
???
</math>
</div>

where ??? are <mspace> rectangles (with a mathbackground) positioned with <mpadded> at the places you expect to see your phasorangle lines (i.e. on the left and at the bottom). So your rectangles should hide the phasorangle lines. The <mspace height="100px" depth="100px"/> ensures that the two <math> elements have the same height. 

This means that if you copy this in a phasorangle-ref.html page and just modify the color of the phasorangle lines (e.g. by using <menclose notation="phasorangle" mathcolor="red">) then the two pages should still be the same, unless the phasorangle lines are outside the area you delimited with your rectangles.

You can do something even more accurate using SVG and Javascript to hide the phasorangle lines. See the testcase for MathJax: https://github.com/mathjax/MathJax-test/tree/master/testsuite/MathMLToDisplay/Presentation/GeneralLayout/menclose

Actually, I don't think we have such tests for the other menclose notations, so that would be great if you can write tests for these notations too or import those from MathJax.
Assignee: nobody → bkrzno
Reporter

Updated

6 years ago
Attachment #819007 - Flags: review?(fred.wang) → feedback+
Reporter

Comment 4

6 years ago
Branko, any update on this?
Flags: needinfo?(bkrzno)
Reporter

Updated

6 years ago
Flags: needinfo?(bkrzno)
Assignee

Comment 5

6 years ago
Posted file testcase
Attachment #8371124 - Flags: review?(fred.wang)
Assignee

Comment 6

6 years ago
Posted patch patch 2 (obsolete) — Splinter Review
Hi Frédéric,
Thank you for your explanation the other day!
I hope this patch is fine now.
I will create the reftest.
Cheers,
Branko
Attachment #819007 - Attachment is obsolete: true
Attachment #8371137 - Flags: review?(fred.wang)
Reporter

Comment 7

6 years ago
Comment on attachment 8371124 [details]
testcase

No need to ask review for a testcase.
Attachment #8371124 - Flags: review?(fred.wang)
Reporter

Comment 8

6 years ago
Comment on attachment 8371137 [details] [diff] [review]
patch 2

Review of attachment 8371137 [details] [diff] [review]:
-----------------------------------------------------------------

Thanks Branko. I have left some comments.

Since you use the BOTTOM notation to draw the horizontal line, I now think this will be a bit different than LONGDIV and RADICAL.

What you want is

- adding kPhasorangleWidth * mRuleThickness to dx_left to leave room for the notation (what you did)
- set the bottom metrics (ink and logical). This will be automatically be done by the BOTTOM notation.
- update the top metrics if necessary. You can only compute it once you have the final logical bottom. Then it is obtained by moving up from the bottom by the angled line height (2 * kPhasorangleWidth * mRuleThickness).

::: layout/mathml/nsMathMLmencloseFrame.cpp
@@ +289,5 @@
> +  if (IsToDraw(NOTATION_PHASORANGLE)) {
> +  DisplayNotation(aBuilder, this, mencloseRect, aLists,
> +                mRuleThickness, NOTATION_PHASORANGLE);
> +  }
> +  

The empty lines should not contain whitespace.

Please verify the indentation level of content of the if statement. See https://developer.mozilla.org/en-US/docs/Developer_Guide/Coding_Style

@@ +447,5 @@
> +                                       phasorangleAscent);
> +      mBoundingMetrics.descent = std::max(mBoundingMetrics.descent,
> +                                        phasorangleDescent);
> +    }
> +	}

The computation of the vertical metrics might be a bit different (see my initial comment). I suspect this should be adapted and moved below.

@@ +644,1 @@
>      mBoundingMetrics.ascent = aDesiredSize.TopAscent();

I don't think that's appropriate to do that for NOTATION_PHASORANGLE since we don't have "top" notation. I think you will need to compute the vertical metrics differently (see my initial comment).

@@ +651,5 @@
>        IsToDraw(NOTATION_DOWNDIAGONALSTRIKE) ||
>        IsToDraw(NOTATION_VERTICALSTRIKE) ||
>        IsToDraw(NOTATION_CIRCLE) ||
> +      IsToDraw(NOTATION_ROUNDEDBOX) ||
> +      IsToDraw(NOTATION_PHASORANGLE))

This is redundant since you set NOTATION_BOTTOM above.

@@ +850,5 @@
> +      // that uses a slope of 2 (angle = tan^-1(2)).
> +      // H = w * tan(angle) = w * 2
> +
> +      gfxFloat H = rect.Height();
> +      gfxFloat w = .5*H;	

there should be space around the * operator.

It's possible that the height of the frame is no longer the one you originally computed so you won't get the desired slope (try notation="phasorangle top circle"). I think what you want is 

w = gfxFloat(kPhasorangleWidth) * e;
and H = 2 * w

then the line is now from rect.BottomLeft() to rect.BottomLeft() - gfxPoint(w, H)

(note that you actually didn't use H in your code)

@@ +859,5 @@
> +      gfxCtx->Stroke();
> +
> +    }	
> +      break;
> +

Please remove the whitespace at the end of lines (https://developer.mozilla.org/en-US/docs/Developer_Guide/Coding_Style#Whitespace) and put the break inside the braces (https://developer.mozilla.org/en-US/docs/Developer_Guide/Coding_Style#Control_Structures)
Attachment #8371137 - Flags: review?(fred.wang) → review-
Reporter

Comment 9

6 years ago
Note: alternatively, if you don't want to use the BOTTOM line and do as radical/longdiv, you will need to call DisplayBar to draw the bottom line. And the coordinates of the angled line should be computed from the position of that bar rather than from the bottom of the frame.
Assignee

Comment 10

5 years ago
Posted patch menclose-phasorangle-v3.patch (obsolete) — Splinter Review
Thanks for the comments, Frédéric. I have added another patch.
Attachment #8371137 - Attachment is obsolete: true
Attachment #8376743 - Flags: review?(fred.wang)
Reporter

Comment 11

5 years ago
Comment on attachment 8376743 [details] [diff] [review]
menclose-phasorangle-v3.patch

Review of attachment 8376743 [details] [diff] [review]:
-----------------------------------------------------------------

Thanks Branko. That's almost ready.

For the reftests, cf bug 963453 and those already available in http://mxr.mozilla.org/mozilla-central/source/layout/reftests/mathml/

::: layout/mathml/nsMathMLmencloseFrame.cpp
@@ +431,5 @@
> +	
> +	  // Update horizontal parameters
> +    dx_left = std::max(dx_left, phasorangleWidth);
> +	}
> +

No need for this empty line before the "Update horizontal parameters" comment. Also please check the alignment and remove extra trailing space at the end of lines (in other places too).

@@ +638,5 @@
>  
> +  // phasorangle notation:
> +  // move up from the bottom by the angled line height
> +  if (IsToDraw(NOTATION_PHASORANGLE) && !aWidthOnly)
> +    mBoundingMetrics.ascent = 2 * kPhasorangleWidth * mRuleThickness - mBoundingMetrics.descent;

So I think this should be 

mBoundingMetrics.ascent = std::max(mBoundingMetrics.ascent, 2 * kPhasorangleWidth * mRuleThickness - mBoundingMetrics.descent)

to take into account other notations with larger ascent.

Also, don't bother testing aWidthOnly. If we are only measuring the width, mBoundingMetrics.ascent will be set with irrelevant value but won't be used anyway.
Attachment #8376743 - Flags: review?(fred.wang) → feedback+
Reporter

Comment 12

5 years ago
I'm cc'ing Anuj since he worked on menclose tests.
Assignee

Comment 13

5 years ago
Posted patch patch v4 (obsolete) — Splinter Review
Thanks, Frédéric. Updated patch.
Attachment #8376743 - Attachment is obsolete: true
Attachment #8378654 - Flags: review?(fred.wang)
Assignee

Comment 14

5 years ago
Posted patch patch v5 (obsolete) — Splinter Review
Oooups, I have just noticed the misalignment in the patch v4. It was aligned properly on my system. I had a tab char there which was differently interpreted. OK, I have fixed it now. Patch v5.
Attachment #8378654 - Attachment is obsolete: true
Attachment #8378654 - Flags: review?(fred.wang)
Attachment #8378674 - Flags: review?(fred.wang)
Reporter

Updated

5 years ago
Depends on: 963453
Reporter

Comment 15

5 years ago
Comment on attachment 8378674 [details] [diff] [review]
patch v5

Review of attachment 8378674 [details] [diff] [review]:
-----------------------------------------------------------------

OK, that looks good, thanks. Would you mind waiting that bug 963453 is fixed (hopefully soon) and update your patch again. I think it would be best to combine the != test menclose-1r with a == test menclose-2-phasorangle (you can already start to write such a reftest). I'll then submit your patch to try server.
Attachment #8378674 - Flags: review?(fred.wang) → review+
Reporter

Comment 16

5 years ago
@Branko: now that bug 963453 is fixed, can you try to write menclose2-* menclose-5, menclose-6 tests for phasorangle?
Flags: needinfo?(bkrzno)
@fredw: Any updates here?

Comment 18

5 years ago
Posted patch phasorangle.patch (obsolete) — Splinter Review
This is the patch for menclose 5 and menclose 6 tests. Please review.
Attachment #8400513 - Flags: review?(fred.wang)
Reporter

Comment 19

5 years ago
Comment on attachment 8400513 [details] [diff] [review]
phasorangle.patch

Review of attachment 8400513 [details] [diff] [review]:
-----------------------------------------------------------------

The tests look good. However, your patch is weird: the  menclose-5-phasorangle.html and menclose-6-phasorangle.html are marked as deletion and reftest.list is marked as a new file.

Could you try to use to get a proper format:

https://developer.mozilla.org/en-US/docs/Mercurial_Queues

You could import Branko's patch and either directly do the modifications or create a separate patch on top of it.

Also, could you try to write a menclose-2-phasorangle test (see what Anuj did for the other notations).
Attachment #8400513 - Flags: review?(fred.wang) → feedback+

Comment 20

5 years ago
Posted patch Revised patch (obsolete) — Splinter Review
Submitting revised patch with added menclose-2 tests. Please review.

Thank you.
Aniket.
Attachment #8409780 - Flags: review?(fred.wang)
Reporter

Comment 21

5 years ago
Comment on attachment 8409780 [details] [diff] [review]
Revised patch

Review of attachment 8409780 [details] [diff] [review]:
-----------------------------------------------------------------

The patch seems to delete menclose-6-ref.html...

I think you don't need to add menclose-6-phasorangle-ref.html, but instead just reuse the existing menclose-6-ref.html.

::: layout/reftests/mathml/menclose-2-phasorangle.html
@@ +8,5 @@
> +      {
> +        var box = document.getElementById("box").getBoundingClientRect();
> +        document.getElementById("path").setAttribute("d",
> +        "M" + (box.left + "," + (box.top + box.bottom)/2 ) + " " +
> +        "l" + (box.width + "," + (-box.height)));

I'm not sure I understand that one. This is supposed to cover the drawing of the phasorangle implemented by Branko's patch. I only see a diagonal line here.

::: layout/reftests/mathml/reftest.list
@@ +260,5 @@
>  != rowlines-3-1.html rowlines-3-1-ref.html
>  == rowlines-3-2.html rowlines-3-2-ref.html
> +== menclose-6-phasorangle.html menclose-6-phasorangle-ref.html
> +== menclose-5-phasorangle.html menclose-5-phasorangle-ref.html
> +== menclose-2-phasorangle.html menclose-2-phasorangle-ref.html

perhaps you can add these lines at a logical place (near the existing menclose-* tests and preserving the order)
Attachment #8409780 - Flags: review?(fred.wang) → feedback+

Comment 22

5 years ago
Okay! Will make the said changes and will submit the patch soon!

Thank you!
Attachment #8400513 - Attachment is obsolete: true
Attachment #8409780 - Attachment is obsolete: true
Attachment #8419289 - Flags: review?(fred.wang)
Reporter

Updated

5 years ago
Attachment #8419289 - Flags: review?(fred.wang) → review+
Reporter

Comment 25

5 years ago
Comment on attachment 8419555 [details] [diff] [review]
added menclose notation phasorangle with reftest

Review of attachment 8419555 [details] [diff] [review]:
-----------------------------------------------------------------

thanks
Attachment #8419555 - Flags: review?(fred.wang) → review+
Reporter

Updated

5 years ago
Attachment #8419289 - Attachment is obsolete: true
Reporter

Updated

5 years ago
Attachment #8378674 - Attachment is obsolete: true
Reporter

Updated

5 years ago
Flags: needinfo?(bkrzno)
Reporter

Comment 27

5 years ago
@Anuj: it seems that there are a few test failures for the phasorangle test. As usual, we probably want to increase a bit the length and thickness of the bar, as necessary.
Flags: needinfo?(anujagarwal464)
(In reply to Frédéric Wang (:fredw) from comment #27)
> @Anuj: it seems that there are a few test failures for the phasorangle test.
> As usual, we probably want to increase a bit the length and thickness of the
> bar, as necessary.

Tests are failing on Android Build and B2G ICS Emulator Opt, I think we should mark them fails-if.
Flags: needinfo?(fred.wang)
Reporter

Comment 29

5 years ago
(In reply to Anuj Agarwal [:anujagarwal464] from comment #28)
> Tests are failing on Android Build and B2G ICS Emulator Opt, I think we
> should mark them fails-if.

Did you try to use the reftest-analyser? I checked a few of them and I only saw small pixel diffs due to antialiasing. So increasing a bit the length/thickness should work in these cases.
Flags: needinfo?(fred.wang)
B2G ICS Emulator Opt
> max difference: 255, number of differing pixels: 81

Increased the stroke width and length of sloped line.
Attachment #8419555 - Attachment is obsolete: true
Flags: needinfo?(anujagarwal464)
By mistake uploaded old patch.
Attachment #8420491 - Attachment is obsolete: true
Reporter

Comment 33

5 years ago
Still seems to fail on B2G ICS Emulator Opt.

The problem seems to be that the rulethicness is > 1 so the length of the sloped line is larger. Perhaps you should do w = 8 * 2 to be less strict.
Attachment #8420492 - Attachment is obsolete: true
Attachment #8420619 - Flags: review?(fred.wang)
Reporter

Updated

5 years ago
Attachment #8420619 - Flags: review?(fred.wang) → review+
https://hg.mozilla.org/mozilla-central/rev/2978bc838b2d
Status: NEW → RESOLVED
Closed: 5 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla32
Flags: in-testsuite+
You need to log in before you can comment on or make changes to this bug.