-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Creating holes in .arc
via the counter-clockwise flag does not work
#1808
Comments
Well, I think the issue is in /*
* Adds an arc at x, y with the given radis and start/end angles.
*/
NAN_METHOD(Context2d::Arc) {
if (!info[0]->IsNumber()
|| !info[1]->IsNumber()
|| !info[2]->IsNumber()
|| !info[3]->IsNumber()
|| !info[4]->IsNumber()) return;
bool anticlockwise = Nan::To<bool>(info[5]).FromMaybe(false);
Context2d *context = Nan::ObjectWrap::Unwrap<Context2d>(info.This());
cairo_t *ctx = context->context();
if (anticlockwise && M_PI * 2 != Nan::To<double>(info[4]).FromMaybe(0)) {
cairo_arc_negative(ctx
, Nan::To<double>(info[0]).FromMaybe(0)
, Nan::To<double>(info[1]).FromMaybe(0)
, Nan::To<double>(info[2]).FromMaybe(0)
, Nan::To<double>(info[3]).FromMaybe(0)
, Nan::To<double>(info[4]).FromMaybe(0));
} else {
cairo_arc(ctx
, Nan::To<double>(info[0]).FromMaybe(0)
, Nan::To<double>(info[1]).FromMaybe(0)
, Nan::To<double>(info[2]).FromMaybe(0)
, Nan::To<double>(info[3]).FromMaybe(0)
, Nan::To<double>(info[4]).FromMaybe(0));
}
} Specifically, the line: ...
if (anticlockwise && M_PI * 2 != Nan::To<double>(info[4]).FromMaybe(0)) {
.. It's not pretty, but here's a potential fix that "works for me": /*
* Adds an arc at x, y with the given radis and start/end angles.
*/
NAN_METHOD(Context2d::Arc) {
if (!info[0]->IsNumber()
|| !info[1]->IsNumber()
|| !info[2]->IsNumber()
|| !info[3]->IsNumber()
|| !info[4]->IsNumber()) return;
bool anticlockwise = Nan::To<bool>(info[5]).FromMaybe(false);
Context2d *context = Nan::ObjectWrap::Unwrap<Context2d>(info.This());
cairo_t *ctx = context->context();
if (anticlockwise && ((M_PI * 2) == Nan::To<double>(info[4]).FromMaybe(0)) ) {
cairo_arc_negative(ctx
, Nan::To<double>(info[0]).FromMaybe(0)
, Nan::To<double>(info[1]).FromMaybe(0)
, Nan::To<double>(info[2]).FromMaybe(0)
, Nan::To<double>(info[3]).FromMaybe(0)
, -M_PI * 2);
}
else if (anticlockwise && ((M_PI * 2) != Nan::To<double>(info[4]).FromMaybe(0)) ) {
cairo_arc_negative(ctx
, Nan::To<double>(info[0]).FromMaybe(0)
, Nan::To<double>(info[1]).FromMaybe(0)
, Nan::To<double>(info[2]).FromMaybe(0)
, Nan::To<double>(info[3]).FromMaybe(0)
, Nan::To<double>(info[4]).FromMaybe(0));
} else {
cairo_arc(ctx
, Nan::To<double>(info[0]).FromMaybe(0)
, Nan::To<double>(info[1]).FromMaybe(0)
, Nan::To<double>(info[2]).FromMaybe(0)
, Nan::To<double>(info[3]).FromMaybe(0)
, Nan::To<double>(info[4]).FromMaybe(0));
}
} Using diff --git a/src/CanvasRenderingContext2d.cc b/src/CanvasRenderingContext2d.cc
index 98d0372..13a44a7 100644
--- a/src/CanvasRenderingContext2d.cc
+++ b/src/CanvasRenderingContext2d.cc
@@ -2932,7 +2932,15 @@ NAN_METHOD(Context2d::Arc) {
Context2d *context = Nan::ObjectWrap::Unwrap<Context2d>(info.This());
cairo_t *ctx = context->context();
- if (anticlockwise && M_PI * 2 != Nan::To<double>(info[4]).FromMaybe(0)) {
+ if (anticlockwise && ((M_PI * 2) == Nan::To<double>(info[4]).FromMaybe(0)) ) {
+ cairo_arc_negative(ctx
+ , Nan::To<double>(info[0]).FromMaybe(0)
+ , Nan::To<double>(info[1]).FromMaybe(0)
+ , Nan::To<double>(info[2]).FromMaybe(0)
+ , Nan::To<double>(info[3]).FromMaybe(0)
+ , -M_PI * 2);
+ }
+ else if (anticlockwise && ((M_PI * 2) != Nan::To<double>(info[4]).FromMaybe(0)) ) {
cairo_arc_negative(ctx
, Nan::To<double>(info[0]).FromMaybe(0)
, Nan::To<double>(info[1]).FromMaybe(0) |
zbjornson
added a commit
that referenced
this issue
Jul 27, 2022
Borrowed from Chromium instead of reinventing the wheel. Firefox's is similar: https://searchfox.org/mozilla-central/source/gfx/2d/PathHelpers.h#127 Fixes #1736 Fixes #1808
zbjornson
added a commit
that referenced
this issue
Jul 27, 2022
Borrowed from Chromium instead of reinventing the wheel. Firefox's is similar: https://searchfox.org/mozilla-central/source/gfx/2d/PathHelpers.h#127 Fixes #1736 Fixes #1808
zbjornson
added a commit
that referenced
this issue
Aug 5, 2022
Borrowed from Chromium instead of reinventing the wheel. Firefox's is similar: https://searchfox.org/mozilla-central/source/gfx/2d/PathHelpers.h#127 Fixes #1736 Fixes #1808
zbjornson
added a commit
that referenced
this issue
Aug 5, 2022
Borrowed from Chromium instead of reinventing the wheel. Firefox's is similar: https://searchfox.org/mozilla-central/source/gfx/2d/PathHelpers.h#127 Fixes #1736 Fixes #1808
zbjornson
added a commit
that referenced
this issue
Aug 5, 2022
Borrowed from Chromium instead of reinventing the wheel. Firefox's is similar: https://searchfox.org/mozilla-central/source/gfx/2d/PathHelpers.h#127 Fixes #1736 Fixes #1808
This was referenced Jun 13, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Issue or Feature
Creating a circle with a hole in it using
arc
and the counter-clockwise flags does not work.I'm not sure but this could be related to #1736.
Steps to Reproduce
The above produces a completely filled in circle of radius 50.
Were it to render through a browser canvas, this would be a circle with a hole in it.
Here is a more complete example showing the different permutations of the angle and flag:
Producing the following pictures:
fill_bug0
fill_bug1
fill_bug2
fill_bug3
outline
Note that the negative angles work as expected as do does doing the outline, whereas using the counterclockwise flags to draw the hole do not.
Your Environment
The text was updated successfully, but these errors were encountered: