Implement isPointInStroke

RESOLVED FIXED in Firefox 19

Status

()

Core
Canvas: 2D
--
enhancement
RESOLVED FIXED
5 years ago
4 years ago

People

(Reporter: tobytailor, Assigned: tobytailor)

Tracking

({dev-doc-complete})

unspecified
mozilla19
dev-doc-complete
Points:
---
Bug Flags:
in-testsuite +

Firefox Tracking Flags

(firefox17 unaffected, firefox18 unaffected, firefox19 fixed, firefox20 fixed)

Details

Attachments

(2 attachments, 6 obsolete attachments)

(Assignee)

Description

5 years ago
Created attachment 672798 [details] [diff] [review]
Implement mozIsPointInStroke

In addition to isPointInPath, the Canvas API should also provide isPointInStroke for hit testing. Right now there is no efficient way to test if a point lies inside the filled AND stroked region of a path. (except of checking for nontransparend pixels using getImageData, which is awful slow if 2D rendering is hw accelerated).
(Assignee)

Updated

5 years ago
Attachment #672798 - Attachment filename: patch.diff → 803124-mozIsPointInStroke.patch
Attachment #672798 - Attachment is patch: true
(Assignee)

Comment 1

5 years ago
Created attachment 672886 [details] [diff] [review]
Patch v2
Attachment #672798 - Attachment is obsolete: true
(Assignee)

Updated

5 years ago
Attachment #672886 - Attachment description: Implement mozIsPointInStroke → Remove whitespace changes
(Assignee)

Comment 2

5 years ago
Created attachment 672894 [details] [diff] [review]
Patch v3
Attachment #672886 - Attachment is obsolete: true
(Assignee)

Comment 3

5 years ago
Created attachment 672928 [details] [diff] [review]
Patch v4
Attachment #672894 - Attachment is obsolete: true
(Assignee)

Updated

5 years ago
Attachment #672886 - Attachment description: Remove whitespace changes → Patch v2
(Assignee)

Updated

5 years ago
Attachment #672894 - Attachment description: Add test, change IDL UUID → Patch v3
(Assignee)

Updated

5 years ago
Attachment #672928 - Attachment description: Fix syntax error → Patch v4
(Assignee)

Comment 4

5 years ago
Created attachment 673128 [details] [diff] [review]
Patch v5
Attachment #672928 - Attachment is obsolete: true
(Assignee)

Updated

5 years ago
Attachment #672886 - Attachment filename: 803124-mozIsPointInStroke.diff → 803124-mozIsPointInStroke.patch
(Assignee)

Updated

5 years ago
Attachment #672894 - Attachment filename: 803124-mozIsPointInStroke.diff → 803124-mozIsPointInStroke.patch
(Assignee)

Updated

5 years ago
Attachment #672928 - Attachment filename: 803124-mozIsPointInStroke.diff → 803124-mozIsPointInStroke.patch
(Assignee)

Updated

5 years ago
Attachment #673128 - Attachment filename: 803124-mozIsPointInStroke.diff → 803124-mozIsPointInStroke.patch
Comment on attachment 673128 [details] [diff] [review]
Patch v5

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

::: content/canvas/test/test_mozIsPointInStroke.html
@@ +33,5 @@
> +
> +ok(ctx.mozIsPointInStroke(20, 20) === false);
> +ok(ctx.mozIsPointInStroke(80, 20) === false);
> +ok(ctx.mozIsPointInStroke(80, 30) === false);
> +ok(ctx.mozIsPointInStroke(20, 30) === false);

This test should include curves and transformed paths/transformed userspace. It might also be worth testing different cap modes.
(Assignee)

Comment 6

5 years ago
Created attachment 675015 [details] [diff] [review]
Patch v6
Attachment #673128 - Attachment is obsolete: true
(Assignee)

Updated

5 years ago
Attachment #675015 - Flags: review?(jmuizelaar)
Comment on attachment 675015 [details] [diff] [review]
Patch v6

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

::: content/canvas/test/test_mozIsPointInStroke.html
@@ +191,5 @@
> +ok(ctx.mozIsPointInStroke(14, 15) === true, 'ctx.mozIsPointInStroke(14, 15) === true');
> +ok(ctx.mozIsPointInStroke(81, 15) === true, 'ctx.mozIsPointInStroke(81, 15) === true');
> +ok(ctx.mozIsPointInStroke(79, 41) === true, 'ctx.mozIsPointInStroke(79, 41) === true');
> +ok(ctx.mozIsPointInStroke(73, 21) === true, 'ctx.mozIsPointInStroke(73, 21) === true');
> +

How about a final test that does a curve scaled by 3x?

Also you should test changing the scale during path construction.

::: gfx/2d/PathSkia.cpp
@@ +184,5 @@
> +                    int32_t(SkFloatToScalar(transformed.y + 1)));
> +
> +  SkRegion pathRegion;
> +
> +  return pathRegion.setPath(strokePath, pointRect);

This should use SkPathContainsPoint if possible.
Attachment #675015 - Flags: review?(jmuizelaar) → review+
(Assignee)

Comment 8

5 years ago
(In reply to Jeff Muizelaar [:jrmuizel] from comment #7)
> 
> How about a final test that does a curve scaled by 3x?
>
> Also you should test changing the scale during path construction.

Sounds reasonable, will add those tests.

> > +  return pathRegion.setPath(strokePath, pointRect);
> 
> This should use SkPathContainsPoint if possible.

Don't think SkPathContainsPoint is a standard Skia API, is it? Seems to be an internal helper defined and used in Chromium (http://code.google.com/p/chromium/source/search?q=SkPathContainsPoint&origq=SkPathContainsPoint&btnG=Search+Trunk) and itself uses setPath().
Flags: needinfo?
(In reply to Tobias Schneider from comment #8)
> (In reply to Jeff Muizelaar [:jrmuizel] from comment #7)
>
> Don't think SkPathContainsPoint is a standard Skia API, is it? Seems to be
> an internal helper defined and used in Chromium
> (http://code.google.com/p/chromium/source/
> search?q=SkPathContainsPoint&origq=SkPathContainsPoint&btnG=Search+Trunk)
> and itself uses setPath().

True. I thought they had fixed this in Skia.
Flags: needinfo?
(In reply to Jeff Muizelaar [:jrmuizel] from comment #9)
> (In reply to Tobias Schneider from comment #8)
> > (In reply to Jeff Muizelaar [:jrmuizel] from comment #7)
> >
> > Don't think SkPathContainsPoint is a standard Skia API, is it? Seems to be
> > an internal helper defined and used in Chromium
> > (http://code.google.com/p/chromium/source/
> > search?q=SkPathContainsPoint&origq=SkPathContainsPoint&btnG=Search+Trunk)
> > and itself uses setPath().
> 
> True. I thought they had fixed this in Skia.

Actually, the function is SkPath::contains(x,y)
(Assignee)

Comment 11

5 years ago
Created attachment 676169 [details] [diff] [review]
Patch v7
Attachment #675015 - Attachment is obsolete: true
(Assignee)

Updated

5 years ago
Attachment #676169 - Flags: review?(jmuizelaar)
Attachment #676169 - Flags: review?(jmuizelaar) → review+
(Assignee)

Updated

5 years ago
Keywords: checkin-needed
Pushed to Try since I don't see any results posted here.
https://tbpl.mozilla.org/?tree=Try&rev=079dc1ebac54
Unfortunately, this causes hangs in android armv6 builds.
https://tbpl.mozilla.org/?tree=Try&rev=7f236ae2ee94
Keywords: checkin-needed
I wonder if it still hangs on armv6 without the test changes. I find it pretty unlikely that this would cause all the mochitests to fail...
(Assignee)

Comment 15

5 years ago
Didn't happen in https://tbpl.mozilla.org/?tree=Try&rev=8cab7ad6c0bf.
(Assignee)

Updated

5 years ago
Keywords: checkin-needed
https://hg.mozilla.org/integration/mozilla-inbound/rev/69c7ee7683e0
Flags: in-testsuite+
Keywords: checkin-needed
https://hg.mozilla.org/mozilla-central/rev/69c7ee7683e0
Status: NEW → RESOLVED
Last Resolved: 5 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla19
Was this ever even suggested on a standards list?
(In reply to :Ms2ger from comment #18)
> Was this ever even suggested on a standards list?

I don't believe it was. Would you be willing to do so?
I have no idea what this API is good for; it's probably better to let someone who does suggest it.
http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2012-November/037911.html

Updated

5 years ago
Depends on: 812039
There's no need for this to be prefixed, by the way. It'll either be added, in which case I'll ensure it's compatible and so it won't conflict, or it won't, in which case nothing with this name will be added and it still won't conflict.

The idea seems pretty sound, the main thing that would stop me from adding it to the spec right now is lack of interest from other vendors. I'll ask around, but if you can convince another vendor to indicate an interest that would certainly help.
Can this be unprefixed, please? As Hixie says, the prefix is useless and unprefixing later will cause breakage later.
(Assignee)

Comment 24

5 years ago
Created attachment 684393 [details] [diff] [review]
Patch to remove prefix
Attachment #684393 - Flags: review?(jmuizelaar)
Attachment #684393 - Flags: review?(jmuizelaar) → review+
(Assignee)

Updated

4 years ago
Keywords: checkin-needed
https://hg.mozilla.org/integration/mozilla-inbound/rev/eed5cbd0b622
Keywords: checkin-needed
Keywords: dev-doc-needed
https://hg.mozilla.org/mozilla-central/rev/eed5cbd0b622

Updated

4 years ago
Assignee: nobody → schneider
Comment on attachment 684393 [details] [diff] [review]
Patch to remove prefix

[Approval Request Comment]
Bug caused by (feature/regressing bug #): N/A
User impact if declined: proliferating more -moz prefixes
Testing completed (on m-c, etc.): on m-c
Risk to taking this patch (and alternatives if risky): maybe low, simple renaming
String or UUID changes made by this patch: none
Attachment #684393 - Flags: approval-mozilla-aurora?
status-firefox17: --- → unaffected
status-firefox18: --- → unaffected
status-firefox19: --- → affected
status-firefox20: --- → fixed
Comment on attachment 684393 [details] [diff] [review]
Patch to remove prefix

Approving based on the m-c testing.
Attachment #684393 - Flags: approval-mozilla-aurora? → approval-mozilla-aurora+
https://hg.mozilla.org/releases/mozilla-aurora/rev/a55bc8cb8a8e
status-firefox19: affected → fixed
Summary: Implement mozIsPointInStroke → Implement isPointInStroke
Documented:
https://developer.mozilla.org/en-US/docs/DOM/CanvasRenderingContext2D#isPointInStroke%28%29
https://developer.mozilla.org/en-US/docs/Firefox_19_for_developers#DOM
Keywords: dev-doc-needed → dev-doc-complete
You need to log in before you can comment on or make changes to this bug.