@@ -261,3 +261,34 @@ describe('roundCorners', () => {
261261 }
262262 } ) ;
263263} ) ;
264+
265+ describe ( 'miter limit semantics' , ( ) => {
266+ /** Closed triangle with a ~5.7 degree apex at (50, 0): ratio ~20. */
267+ const spike = [
268+ { x : 50 , y : 0 , handleIn : null , handleOut : null } ,
269+ { x : 60 , y : 200 , handleIn : null , handleOut : null } ,
270+ { x : 40 , y : 200 , handleIn : null , handleOut : null } ,
271+ ] ;
272+
273+ it ( 'clips an acute miter once the ratio exceeds the limit' , ( ) => {
274+ // ratio = 1 / sin(2.86 deg) ~ 20, so miterLimit 4 must bevel the corner
275+ // instead of letting the spike run past the offset edge.
276+ const result = offsetPath ( spike , true , 10 , 'miter' , 4 ) ;
277+ expect ( Math . min ( ...result . map ( ( p ) => p . y ) ) ) . toBeGreaterThan ( - 10 ) ;
278+ } ) ;
279+
280+ it ( 'keeps the same miter when the limit allows it' , ( ) => {
281+ const result = offsetPath ( spike , true , 10 , 'miter' , 100 ) ;
282+ expect ( Math . min ( ...result . map ( ( p ) => p . y ) ) ) . toBeLessThan ( - 100 ) ;
283+ } ) ;
284+
285+ it ( 'decides from the angle, not the edge length' , ( ) => {
286+ // Uniform scaling preserves the angles, so the decision must not change.
287+ // The pre-fix ratio divided by edge length, so longer edges never clipped.
288+ const scaled = spike . map ( ( p ) => ( { ...p , x : p . x * 5 , y : p . y * 5 } ) ) ;
289+ const short = offsetPath ( spike , true , 10 , 'miter' , 4 ) ;
290+ const long = offsetPath ( scaled , true , 10 , 'miter' , 4 ) ;
291+ expect ( Math . min ( ...short . map ( ( p ) => p . y ) ) ) . toBeGreaterThan ( - 10 ) ;
292+ expect ( Math . min ( ...long . map ( ( p ) => p . y ) ) ) . toBeGreaterThan ( - 10 ) ;
293+ } ) ;
294+ } ) ;
0 commit comments