Blender problems with getting the center of an object. (Origin to center is not the center)
The origin of an object can be anywhere you like with respect to the object's mesh.
There are two possible definitions of 'center' provided by Blender's Header menu &gt; Set Origin &gt; Origin to Geometry operation, in Object Mode.

'Median Center', which is the mean location of the object's vertices

'Bounds Center', which is the center of the object's bounding
box.


It looks as if you want 'Bounds Center'.
(In Edit mode, the behaviour of ShiftS Cursor to Selected also varies, depending to whether 'Median' or 'Bounding Box' is selected as Transform Pivot Point.)