Skip to content
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

Add Start and End angle to circle. #1675

Merged
merged 4 commits into from
Sep 18, 2014
Merged

Add Start and End angle to circle. #1675

merged 4 commits into from
Sep 18, 2014

Conversation

asturur
Copy link
Member

@asturur asturur commented Sep 17, 2014

Add option to circle for start and end angle, to draw an ARC.
in radiants, not in degree to avoid writing a setter and getter that does the conversion.
Internally is better radiants i think.

as per request of issue #1612

I modified the render, the initialize method, toObject and toSvg methods.
Did i forget something?
Bounding box is the original of the circle, i think it makes sense to leave how it is.

Canvas:
image

svg export
image

resulting svg

<?xml version="1.0" encoding="UTF-8" standalone="no" ?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="900" height="500" xml:space="preserve"><desc>Created with Fabric.js 1.4.11</desc><defs></defs><path d="M 21.213203435596427 21.213203435596423 A 30 30 0 0 1  -21.213203435596423 21.213203435596427" style="stroke: #00FF00; stroke-width: 1; stroke-dasharray: ; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: #00FF00; fill-rule: source-over; opacity: 1;" transform="translate(445.74 232.61) rotate(51.79) scale(4.21 4.21) "/>
<path d="M -21.213203435596423 -21.213203435596427 A 30 30 0 0 1  21.213203435596427 -21.213203435596423" style="stroke: #FF0000; stroke-width: 1; stroke-dasharray: ; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: #00FF00; fill-rule: source-over; opacity: 1;" transform="translate(305.74 242.61) rotate(51.79) scale(4.21 4.21) "/>
<path d="M -21.213203435596423 21.213203435596427 A 30 30 0 0 1  -21.21320343559643 -21.213203435596423" style="stroke: #0000FF; stroke-width: 1; stroke-dasharray: ; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: #00FF00; fill-rule: source-over; opacity: 1;" transform="translate(439.2 278.3) rotate(51.79) scale(3.86 4.21) matrix(-1 0 0 1 0 0)  "/>
<path d="M 21.213203435596427 -21.213203435596423 A 30 30 0 0 1  21.213203435596427 21.213203435596423" style="stroke: #00FFFF; stroke-width: 1; stroke-dasharray: ; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: #00FF00; fill-rule: source-over; opacity: 1;" transform="translate(291.74 316.61) rotate(51.79) scale(4.21 4.21) matrix(-1 0 0 1 0 0)  "/>
<path d="M 21.213203435596427 21.213203435596423 A 30 30 0 0 1  -21.213203435596423 21.213203435596427" style="stroke: #00FF00; stroke-width: 1; stroke-dasharray: ; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: #00FF00; fill-rule: source-over; opacity: 1;" transform="translate(174.5 130.5) "/>
<path d="M -21.213203435596423 -21.213203435596427 A 30 30 0 0 1  21.213203435596427 -21.213203435596423" style="stroke: #FF0000; stroke-width: 1; stroke-dasharray: ; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: #00FF00; fill-rule: source-over; opacity: 1;" transform="translate(174.5 130.5) "/>
<path d="M -21.213203435596423 21.213203435596427 A 30 30 0 0 1  -21.21320343559643 -21.213203435596423" style="stroke: #0000FF; stroke-width: 1; stroke-dasharray: ; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: #00FF00; fill-rule: source-over; opacity: 1;" transform="translate(174.5 130.5) "/>
<path d="M 21.213203435596427 -21.213203435596423 A 30 30 0 0 1  21.213203435596427 21.213203435596423" style="stroke: #00FFFF; stroke-width: 1; stroke-dasharray: ; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: #00FF00; fill-rule: source-over; opacity: 1;" transform="translate(174.5 130.5) "/>
</svg>

Add option to circle for start and end angle, to draw an ARC.
in radians, not in degree to avoid writing a setter and getter that does the conversion.
Internally is better radians i think.
Added start and end Angle to tests.
Code styles error fix
@kangax
Copy link
Member

kangax commented Sep 18, 2014

Looks great @asturur, thanks! Would be nice to add some visual-functional tests for this feature. For example, under miscellaneous http://fabricjs.com/test/

kangax added a commit that referenced this pull request Sep 18, 2014
…gle-,-endAngle

Add Start and End angle to circle.
@kangax kangax merged commit 79a6123 into fabricjs:master Sep 18, 2014
@asturur
Copy link
Member Author

asturur commented Sep 18, 2014

Ok, i'll try,
Let me know if you want to extend even to ellipse. it would be similar.

Please consider my question in #1671, about FillRule, i would like to go
on, but i'm stuck waiting for
directions.

Basically FillRule for path is a FillRule in SVG - PATH

FillRule for everything else in fabric is a globalcompoisteoperation
paramenter, not present in SVG.

We should divide in 2 different properties.

2014-09-18 15:04 GMT+02:00 Juriy Zaytsev notifications@github.com:

Merged #1675 #1675.


Reply to this email directly or view it on GitHub
#1675 (comment).

@kangax
Copy link
Member

kangax commented Sep 19, 2014

Let me know if you want to extend even to ellipse. it would be similar.

That would make sense, sure. And we can add ellipses with different angles to a test page as well!

@asturur
Copy link
Member Author

asturur commented Sep 19, 2014

i'll finish test on those polygons and then check the fabricjs.com
repository for adding visual tests.

2014-09-19 12:35 GMT+02:00 Juriy Zaytsev notifications@github.com:

Let me know if you want to extend even to ellipse. it would be similar.

That would make sense, sure. And we can add ellipses with different angles
to a test page as well!


Reply to this email directly or view it on GitHub
#1675 (comment).

@asturur asturur deleted the Add-parameter-to-circle-startAngle-,-endAngle branch September 20, 2014 09:25
@evandavey
Copy link

@asturur - what is the logic of keeping the original bounding box and how could this be changed? I am trying to use the mouse:over event for a semi-circle but it triggers on the half of the circle that is not drawn which is confusing to a user. As another example, if I add a semi-circle to the group along with other objects and access group.width in order to calculate the group center point, the undrawn part of the circle is included so the center point is inaccurate.

@asturur
Copy link
Member Author

asturur commented Aug 22, 2018

This startAngle and endAngle are not complete.
We should add methods to fix the bounding box indeed.

I think that writing a specific method for get nonTrasnformedDimensions should be enough.
Its a bit of a geometric problem if someone is interested in doing it

@asturur
Copy link
Member Author

asturur commented Aug 22, 2018

Also maybe giving an option to include the center point and making a circle sector may be another idea?

@evandavey
Copy link

OK, thanks for the quick reply. Should this be moved to a new issue? Might be relevant: https://mathoverflow.net/questions/93659/find-the-bounding-box-of-a-circle-segment

@asturur
Copy link
Member Author

asturur commented Aug 22, 2018

We have 2 ways to find the bbox, already embedded in fabricJS.
One is to calculate the path and use what we use for paths, the other is to take the points and use what we use for polygon, we should we covered for that, the problem is just doing it in a nice elegant way.

@asturur
Copy link
Member Author

asturur commented Aug 22, 2018

i see how including the center in the segment can be usefull to create pie charts without starting from SVGs ( i also imagine that positioning the slices is difficult )

@evandavey
Copy link

I implemented a draft algorithm which I think calculates the width and height of the arc correctly, which I use to set the width/height properties. However, the bounding box location (from getBoundingRect()) is not positioned correctly (see image) and the arc no longer triggers a mouseover event. This arc was drawn with originX = originY = 'center'.

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants