workaround
    
    
    import strformat
    
    type
      
      # The 3 notations refer to the same 3-D entity, and some coordinates are 
shared
      CoordinateSystem = enum
        csCar, # Cartesian    (x,y,z)
        csCyl, # Cylindrical  (r,φ,z)
        csSph  # Spherical    (ρ,θ,φ)
      
      Cartesian = object
        x, y, z: float
      Cylindrical = object
        r, phi, z: float
      Spherical = object
        rho, theta, phi: float
      Coordinates = object
        case cs: CoordinateSystem: # cs is the coordinate discriminator
          of csCar:
            car: Cartesian
          of csCyl:
            cy: Cylindrical
          of csSph:
            sph: Spherical
    
    proc `$`(point: Coordinates): string =
      case point.cs
      of csCar: result = &"(x: {point.car.x:5.2f}, y: {point.car.y:5.2f}, z: 
{point.car.z:5.2f})"
      of csCyl: result = &"(r: {point.cy.r:5.2f}, φ: {point.cy.phi:5.2f}, z: 
{point.cy.z:5.2f})"
      of csSph: result = &"(ρ: {point.sph.rho:5.2f}, θ: {point.sph.theta:5.2f}, 
φ: {point.sph.phi:5.2f})"
    
    
    Run

Reply via email to