diff --git a/src/Athens-SVG/ASEllipse.class.st b/src/Athens-SVG/ASEllipse.class.st index c58e2c5..4920cd3 100644 --- a/src/Athens-SVG/ASEllipse.class.st +++ b/src/Athens-SVG/ASEllipse.class.st @@ -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 [ +| 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 [ @@ -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. ]