From c3aed5277dac6baf2105e57a0c0616c82796e598 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Tue, 29 Oct 2013 18:10:30 +0100 Subject: [PATCH] Use center and radius in all ellipse code, rather than bounding rect. Simplifies things. --- src/item/Shape.js | 8 +++----- src/path/Path.Constructors.js | 37 ++++++++++++++++------------------- 2 files changed, 20 insertions(+), 25 deletions(-) diff --git a/src/item/Shape.js b/src/item/Shape.js index 984eb12b..711394e5 100644 --- a/src/item/Shape.js +++ b/src/item/Shape.js @@ -436,19 +436,17 @@ statics: new function() { */ Ellipse: function(/* rectangle */) { var center, - size, radius; if (Base.hasNamed(arguments, 'center')) { center = Point.readNamed(arguments, 'center'); radius = Size.readNamed(arguments, 'radius'); - size = radius.multiply(2); } else { var rect = Rectangle.readNamed(arguments, 'rectangle'); center = rect.getCenter(true); - size = rect.getSize(true); - radius = size.divide(2); + radius = rect.getSize(true).divide(2); } - return createShape('ellipse', center, size, radius, arguments); + return createShape('ellipse', center, radius.multiply(2), radius, + arguments); } }; }}); diff --git a/src/path/Path.Constructors.js b/src/path/Path.Constructors.js index 4f042b9b..26a6092b 100644 --- a/src/path/Path.Constructors.js +++ b/src/path/Path.Constructors.js @@ -13,25 +13,22 @@ Path.inject({ statics: new function() { var kappa = Numerical.KAPPA, - halfKappa = kappa / 2, ellipseSegments = [ - new Segment([0, 0.5], [0, halfKappa ], [0, -halfKappa]), - new Segment([0.5, 0], [-halfKappa, 0], [halfKappa, 0 ]), - new Segment([1, 0.5], [0, -halfKappa], [0, halfKappa ]), - new Segment([0.5, 1], [halfKappa, 0 ], [-halfKappa, 0]) + new Segment([-1, 0], [0, kappa ], [0, -kappa]), + new Segment([0, -1], [-kappa, 0], [kappa, 0 ]), + new Segment([1, 0], [0, -kappa], [0, kappa ]), + new Segment([0, 1], [kappa, 0 ], [-kappa, 0]) ]; - function createEllipse(rect, args) { + function createEllipse(center, radius, args) { var path = new Path(), - point = rect.getPoint(true), - size = rect.getSize(true), segments = new Array(4); for (var i = 0; i < 4; i++) { var segment = ellipseSegments[i]; segments[i] = new Segment( - segment._point.multiply(size).add(point), - segment._handleIn.multiply(size), - segment._handleOut.multiply(size) + segment._point.multiply(radius).add(center), + segment._handleIn.multiply(radius), + segment._handleOut.multiply(radius) ); } path._add(segments); @@ -113,8 +110,7 @@ Path.inject({ statics: new function() { Circle: function(/* center, radius */) { var center = Point.readNamed(arguments, 'center'), radius = Base.readNamed(arguments, 'radius'); - return createEllipse(new Rectangle(center.subtract(radius), - new Size(radius * 2, radius * 2)), arguments); + return createEllipse(center, new Size(radius), arguments); }, /** @@ -286,16 +282,17 @@ Path.inject({ statics: new function() { * }); */ Ellipse: function(/* rectangle */) { - var rect; + var center, + radius; if (Base.hasNamed(arguments, 'center')) { - var center = Point.readNamed(arguments, 'center'), - radius = Size.readNamed(arguments, 'radius'); - rect = new Rectangle(center.subtract(radius), - center.add(radius)); + center = Point.readNamed(arguments, 'center'); + radius = Size.readNamed(arguments, 'radius'); } else { - rect = Rectangle.readNamed(arguments, 'rectangle'); + var rect = Rectangle.readNamed(arguments, 'rectangle'); + center = rect.getCenter(true); + radius = rect.getSize(true).divide(2); } - return createEllipse(rect, arguments); + return createEllipse(center, radius, arguments); }, /**