Forward declaring an object won't work, I know, but it describes kind of what I 
want.

In the code below I (at some time will) have in a library objects and procs for 
defining and working on a half edge based polygon datastructure.

The user (I) can define properties for the connection elements in the mesh. Now 
I'd like to somehowe fix the names of the objects and field names of Properties 
on the library side of things. The problem is that they are depending on what 
is done and can be wildly different. Is there a way to do this, kind of like 
extending an object or forward declaring it?

Now for every new situation I every time have to write things like 
`getVertexProperies()` instead of having it in the library side once.

Is there a way to achieve the result I look for?
    
    
    import std/[options]
    import vmath
    
    # library defined
    type
      Vertex = object
        point: int         # unique, references mesh.vv[int], not null
        hedge: int         # an outgoing halfedge references conn.hedge[int], 
not null
      
      Face = object
        hedge: int         # incident halfedge references conn.hedge[int], not 
null
      
      HalfEdge = object
        face: Option[int]  # references conn.face[int],
        vxi: int           # references conn.vertex[int], not null
        twin: int          # references conn.hedge[int], not null
        next: int          # references conn.hedge[int], not null
        prev: int          # references conn.hedge[int], not null
      
      Connect = object
        vx: seq[Vertex]
        face: seq[Face]
        hedge: seq[HalfEdge]
      
      Mesh* = object
        vv*: seq[Vec3]      # vertex vector seq
        conn*: Connect
    
    #==========
    
    # user defined
    type
      # fields in xxProp can vary per use case
      VxProp = object
        normal: Vec3
        uv: Vec2
        # add a weight to vx for cloth animation
        weight: float
      
      FaceProp = object
        normal: Vec3
        # wind direction and force
        wind: Vec4
      
      HedgeProp = object
        # stiffness of cloth
        # in hedge as val varies for warp and weft
        springconstant: seq[float]
      
      Propertie = object
        vx: seq[VxProp]        # indices in sync with mesh.conn.vx
        face: seq[FaceProp]    # indices in sync with mesh.conn.face
        hedge: seq[HedgeProp]  # indices in sync with mesh.conn.hedge
      
      MeshProp = object
        mesh: Mesh
        prop: Propertie
    
    
    Run

Reply via email to