@@ -42,6 +42,11 @@ CurveLocation = Base.extend(/** @lends CurveLocation# */{
4242 */
4343 initialize : function ( curve , parameter , point , distance ) {
4444 this . _curve = curve ;
45+ // Also store references to segment1 and segment2, in case path
46+ // splitting / dividing is going to happen, in which case the segments
47+ // can be used to determine the new curves, see #getCurve(true)
48+ this . _segment1 = curve . _segment1 ;
49+ this . _segment2 = curve . _segment2 ;
4550 this . _parameter = parameter ;
4651 this . _point = point ;
4752 this . _distance = distance ;
@@ -55,7 +60,7 @@ CurveLocation = Base.extend(/** @lends CurveLocation# */{
5560 */
5661 getSegment : function ( ) {
5762 if ( ! this . _segment ) {
58- var curve = this . _curve ,
63+ var curve = this . getCurve ( ) ,
5964 parameter = this . getParameter ( ) ;
6065 if ( parameter == 0 ) {
6166 this . _segment = curve . _segment1 ;
@@ -80,7 +85,17 @@ CurveLocation = Base.extend(/** @lends CurveLocation# */{
8085 * @type Curve
8186 * @bean
8287 */
83- getCurve : function ( ) {
88+ getCurve : function ( /* uncached */ ) {
89+ if ( ! this . _curve || arguments [ 0 ] ) {
90+ // If we're asked to get the curve uncached, access current curve
91+ // objects through segment1 / segment2. Since path splitting or
92+ // dividing might have happened in the meantime, try segment1's
93+ // curve, and see if _point lies on it still, otherwise assume it's
94+ // the curve before segment2.
95+ this . _curve = this . _segment1 . getCurve ( ) ;
96+ if ( this . _curve . getParameterOf ( this . _point ) == null )
97+ this . _curve = this . _segment2 . getPrevious ( ) . getCurve ( ) ;
98+ }
8499 return this . _curve ;
85100 } ,
86101
@@ -91,7 +106,8 @@ CurveLocation = Base.extend(/** @lends CurveLocation# */{
91106 * @bean
92107 */
93108 getPath : function ( ) {
94- return this . _curve && this . _curve . _path ;
109+ var curve = this . getCurve ( ) ;
110+ return curve && curve . _path ;
95111 } ,
96112
97113 /**
@@ -102,7 +118,8 @@ CurveLocation = Base.extend(/** @lends CurveLocation# */{
102118 * @bean
103119 */
104120 getIndex : function ( ) {
105- return this . _curve && this . _curve . getIndex ( ) ;
121+ var curve = this . getCurve ( ) ;
122+ return curve && curve . getIndex ( ) ;
106123 } ,
107124
108125 /**
@@ -113,7 +130,7 @@ CurveLocation = Base.extend(/** @lends CurveLocation# */{
113130 * @bean
114131 */
115132 getOffset : function ( ) {
116- var path = this . _curve && this . _curve . _path ;
133+ var path = this . getPath ( ) ;
117134 return path && path . _getOffset ( this ) ;
118135 } ,
119136
@@ -125,9 +142,9 @@ CurveLocation = Base.extend(/** @lends CurveLocation# */{
125142 * @bean
126143 */
127144 getCurveOffset : function ( ) {
128- var parameter = this . getParameter ( ) ;
129- return parameter != null && this . _curve
130- && this . _curve . getLength ( 0 , parameter ) ;
145+ var curve = this . getCurve ( ) ,
146+ parameter = this . getParameter ( ) ;
147+ return parameter != null && curve && curve . getLength ( 0 , parameter ) ;
131148 } ,
132149
133150 /**
@@ -139,9 +156,10 @@ CurveLocation = Base.extend(/** @lends CurveLocation# */{
139156 * @bean
140157 */
141158 getParameter : function ( /* uncached */ ) {
142- if ( ( this . _parameter == null || arguments [ 0 ] )
143- && this . _curve && this . _point )
144- this . _parameter = this . _curve . getParameterOf ( this . _point ) ;
159+ if ( ( this . _parameter == null || arguments [ 0 ] ) && this . _point ) {
160+ var curve = this . getCurve ( arguments [ 0 ] && this . _point ) ;
161+ this . _parameter = curve && curve . getParameterOf ( this . _point ) ;
162+ }
145163 return this . _parameter ;
146164 } ,
147165
@@ -153,8 +171,10 @@ CurveLocation = Base.extend(/** @lends CurveLocation# */{
153171 * @bean
154172 */
155173 getPoint : function ( ) {
156- if ( ! this . _point && this . _curve && this . _parameter != null )
157- this . _point = this . _curve . getPoint ( this . _parameter ) ;
174+ if ( ! this . _point && this . _parameter != null ) {
175+ var curve = this . getCurve ( ) ;
176+ this . _point = curve && curve . getPoint ( this . _parameter ) ;
177+ }
158178 return this . _point ;
159179 } ,
160180
@@ -165,9 +185,9 @@ CurveLocation = Base.extend(/** @lends CurveLocation# */{
165185 * @bean
166186 */
167187 getTangent : function ( ) {
168- var parameter = this . getParameter ( ) ;
169- return parameter != null && this . _curve
170- && this . _curve . getTangent ( parameter ) ;
188+ var parameter = this . getParameter ( ) ,
189+ curve = this . getCurve ( ) ;
190+ return parameter != null && curve && curve . getTangent ( parameter ) ;
171191 } ,
172192
173193 /**
@@ -177,9 +197,9 @@ CurveLocation = Base.extend(/** @lends CurveLocation# */{
177197 * @bean
178198 */
179199 getNormal : function ( ) {
180- var parameter = this . getParameter ( ) ;
181- return parameter != null && this . _curve
182- && this . _curve . getNormal ( parameter ) ;
200+ var parameter = this . getParameter ( ) ,
201+ curve = this . getCurve ( ) ;
202+ return parameter != null && curve && curve . getNormal ( parameter ) ;
183203 } ,
184204
185205 /**
@@ -193,11 +213,13 @@ CurveLocation = Base.extend(/** @lends CurveLocation# */{
193213 } ,
194214
195215 divide : function ( ) {
196- return this . _curve ? this . _curve . divide ( this . getParameter ( true ) ) : null ;
216+ var curve = this . getCurve ( ) ;
217+ return curve && curve . divide ( this . getParameter ( true ) ) ;
197218 } ,
198219
199220 split : function ( ) {
200- return this . _curve ? this . _curve . split ( this . getParameter ( true ) ) : null ;
221+ var curve = this . getCurve ( ) ;
222+ return curve && curve . split ( this . getParameter ( true ) ) ;
201223 } ,
202224
203225 /**
0 commit comments