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

Render Ellipses as ellipses #10

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 32 additions & 12 deletions src/Athens-SVG/ASEllipse.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,32 @@ If the attribute is not specified, the effect is as if a value of 0 were specifi
cy := self translateLength: aString
]

{ #category : #'as yet unclassified' }
ASEllipse >> ellipseToPhath [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Path instead of Phath

| kappa ox oy conv stream |
"Please refer to https://stackoverflow.com/questions/59011294/ellipse-to-path-convertion-using-javascript for implementation details"
kappa := 0.5522847498.
ox := rx * kappa. "x offset for the control point"
oy := ry * kappa. "y offset for the control point"
stream := ReadWriteStream on: (String new: 10).
stream << 'M' << (cx - rx) asString << $, << cy asString
<<'C' << (cx - rx) asString << ', ' << (cy - oy) asString
<< ', ' << (cx - ox) asString << ', ' << (cy - ry) asString
<< ', ' << cx asString << ', ' << (cy - ry) asString
<< ',C' << (cx + ox) asString << ', ' << (cy - ry) asString
<< ', ' << (cx + rx) asString << ', ' << (cy - oy) asString
<< ', ' << (cx + rx) asString << ', ' << cy asString
<< ',C' << (cx + rx) asString << ', ' << (cy + oy) asString
<< ', ' << (cx + ox) asString << ', ' << (cy + ry) asString
<< ', ' << cx asString << ', ' << (cy + ry) asString
<< ',C' << (cx - ox) asString << ', ' << (cy + ry) asString
<< ', ' << (cx - rx) asString << ', ' << (cy + oy) asString
<< ', ' << (cx - rx) asString << ', ' << cy asString
<< ',z'.
conv := ASPathConverter new stream: stream contents readStream.
^ conv convertPathData
]

{ #category : #'as yet unclassified' }
ASEllipse >> rx: aString [

Expand All @@ -47,17 +73,11 @@ ASEllipse >> ry: aString [

{ #category : #'as yet unclassified' }
ASEllipse >> setShapeOn: aCanvas [
| circle |


circle := aCanvas createPath: [:builder |
builder
absolute;
moveTo: (cx - rx @ cy);
cwArcTo: (cx + rx @ cy ) angle: 180 degreesToRadians;
cwArcTo: (cx - rx @ cy) angle: 180 degreesToRadians
| ellipse |
ellipse := aCanvas createPath: [:builder |
self ellipseToPhath do: [:each |
builder perform: each first withArguments: each second
]
].

aCanvas setShape: circle.

aCanvas setShape: ellipse.
]