Rectangular electromagnets