@@ -166,8 +166,8 @@ export class Solid {
166166 `Cylinder dimensions must be finite (got radius: ${ radius } , height: ${ height } )`
167167 ) ;
168168 if ( options ?. topRadius !== undefined ) {
169- if ( options . topRadius <= 0 )
170- throw new Error ( `Cylinder topRadius must be positive (got ${ options . topRadius } )` ) ;
169+ if ( options . topRadius < 0 )
170+ throw new Error ( `Cylinder topRadius must be non-negative (got ${ options . topRadius } )` ) ;
171171 if ( ! Number . isFinite ( options . topRadius ) )
172172 throw new Error ( `Cylinder topRadius must be finite (got ${ options . topRadius } )` ) ;
173173 }
@@ -319,8 +319,8 @@ export class Solid {
319319 if ( ! Number . isFinite ( radius ) || ! Number . isFinite ( height ) )
320320 throw new Error ( `Prism dimensions must be finite (got radius: ${ radius } , height: ${ height } )` ) ;
321321 if ( options ?. topRadius !== undefined ) {
322- if ( options . topRadius <= 0 )
323- throw new Error ( `Prism topRadius must be positive (got ${ options . topRadius } )` ) ;
322+ if ( options . topRadius < 0 )
323+ throw new Error ( `Prism topRadius must be non-negative (got ${ options . topRadius } )` ) ;
324324 if ( ! Number . isFinite ( options . topRadius ) )
325325 throw new Error ( `Prism topRadius must be finite (got ${ options . topRadius } )` ) ;
326326 }
@@ -404,6 +404,9 @@ export class Solid {
404404 steps : 1
405405 } ) ;
406406
407+ // Center geometry along extrusion axis before rotation
408+ geometry . translate ( 0 , 0 , - height / 2 ) ;
409+
407410 // Rotate so extrusion direction (Z-axis) becomes height (Y-axis)
408411 return new Solid ( this . geometryToBrush ( geometry ) , color ) . normalize ( ) . rotate ( { x : 90 } ) ;
409412 } ;
@@ -922,6 +925,14 @@ export class Solid {
922925
923926 // Centering method
924927 public center ( axes ?: { x ?: boolean ; y ?: boolean ; z ?: boolean } ) : Solid {
928+ // First, bake all transformations (position, rotation, scale) into geometry
929+ this . brush . geometry . applyMatrix4 ( this . brush . matrix ) ;
930+ this . brush . position . set ( 0 , 0 , 0 ) ;
931+ this . brush . rotation . set ( 0 , 0 , 0 ) ;
932+ this . brush . scale . set ( 1 , 1 , 1 ) ;
933+ this . brush . updateMatrixWorld ( ) ;
934+
935+ // Now get fresh bounds (geometry-only, no transformations)
925936 const bounds = this . getBounds ( ) ;
926937
927938 // Default to all axes if no parameter provided
@@ -934,48 +945,46 @@ export class Solid {
934945 const translateZ = centerZ ? - bounds . center . z : 0 ;
935946
936947 this . brush . geometry . translate ( translateX , translateY , translateZ ) ;
937-
938- if ( centerX ) this . brush . position . x = 0 ;
939- if ( centerY ) this . brush . position . y = 0 ;
940- if ( centerZ ) this . brush . position . z = 0 ;
941-
942948 this . brush . updateMatrixWorld ( ) ;
949+
943950 return this ;
944951 }
945952
946953 // Edge alignment method
947954 public align ( direction : 'bottom' | 'top' | 'left' | 'right' | 'front' | 'back' ) : Solid {
955+ // First, bake all transformations (position, rotation, scale) into geometry
956+ this . brush . geometry . applyMatrix4 ( this . brush . matrix ) ;
957+ this . brush . position . set ( 0 , 0 , 0 ) ;
958+ this . brush . rotation . set ( 0 , 0 , 0 ) ;
959+ this . brush . scale . set ( 1 , 1 , 1 ) ;
960+ this . brush . updateMatrixWorld ( ) ;
961+
962+ // Now get fresh bounds (geometry-only, no transformations)
948963 const bounds = this . getBounds ( ) ;
949964
950965 switch ( direction ) {
951966 case 'bottom' : {
952967 this . brush . geometry . translate ( 0 , - bounds . min . y , 0 ) ;
953- this . brush . position . y = 0 ;
954968 break ;
955969 }
956970 case 'top' : {
957971 this . brush . geometry . translate ( 0 , - bounds . max . y , 0 ) ;
958- this . brush . position . y = 0 ;
959972 break ;
960973 }
961974 case 'left' : {
962975 this . brush . geometry . translate ( - bounds . min . x , 0 , 0 ) ;
963- this . brush . position . x = 0 ;
964976 break ;
965977 }
966978 case 'right' : {
967979 this . brush . geometry . translate ( - bounds . max . x , 0 , 0 ) ;
968- this . brush . position . x = 0 ;
969980 break ;
970981 }
971982 case 'front' : {
972983 this . brush . geometry . translate ( 0 , 0 , - bounds . min . z ) ;
973- this . brush . position . z = 0 ;
974984 break ;
975985 }
976986 case 'back' : {
977987 this . brush . geometry . translate ( 0 , 0 , - bounds . max . z ) ;
978- this . brush . position . z = 0 ;
979988 break ;
980989 }
981990 }
0 commit comments