@@ -44,15 +44,27 @@ var Path = this.Path = PathItem.extend(/** @lends Path# */{
4444 * var path = new Path(segments);
4545 * path.strokeColor = 'black';
4646 */
47- initialize : function ( segments ) {
48- this . base ( ) ;
47+ initialize : function ( arg ) {
4948 this . _closed = false ;
50- this . _selectedSegmentState = 0 ;
51- // Support both passing of segments as array or arguments
49+ this . _segments = [ ] ;
50+ this . base ( ) ;
51+ // arg can either be an object literal describing properties to be set
52+ // on the path, a list of segments to be set, or the first of multiple
53+ // arguments describing separate segments.
5254 // If it is an array, it can also be a description of a point, so
53- // check its first entry for object as well
54- this . setSegments ( Array . isArray ( segments )
55- && typeof segments [ 0 ] === 'object' ? segments : arguments ) ;
55+ // check its first entry for object as well.
56+ // But first see if segments are directly passed at all. If not, try
57+ // #setProperties(arg).
58+ var segments = Array . isArray ( arg )
59+ ? typeof arg [ 0 ] === 'object'
60+ ? arg
61+ : arguments
62+ : arg && ( arg . point !== undefined || arg . x !== undefined )
63+ ? arguments
64+ : null ;
65+ this . setSegments ( segments || [ ] ) ;
66+ if ( ! segments )
67+ this . setProperties ( arg ) ;
5668 } ,
5769
5870 clone : function ( ) {
@@ -94,15 +106,10 @@ var Path = this.Path = PathItem.extend(/** @lends Path# */{
94106 } ,
95107
96108 setSegments : function ( segments ) {
97- if ( ! this . _segments ) {
98- this . _segments = [ ] ;
99- } else {
100- this . _selectedSegmentState = 0 ;
101- this . _segments . length = 0 ;
102- // Make sure new curves are calculated next time we call getCurves()
103- if ( this . _curves )
104- delete this . _curves ;
105- }
109+ this . _selectedSegmentState = 0 ;
110+ this . _segments . length = 0 ;
111+ // Make sure new curves are calculated next time we call getCurves()
112+ delete this . _curves ;
106113 this . _add ( Segment . readAll ( segments ) ) ;
107114 } ,
108115
0 commit comments