I'm writing a simple geometry composition/manipulation library. The library needs to allow the clients to express high-level logic like below:

table_base = Cylinder(r=..., h=..., anchor=None)
table_stem = Cylinder(r=..., h=..., anchor=None)
table_top = Cylinder(r=..., h=..., anchor=None)

# Build an abstract entity 'table' by specifying relationships
# between its components. No concrete locations specified yet. 
table = Geometry()
table.stack(table_stem, table_base)
table.stack(table_top, table_stem)

# Provide concrete location for the base
# Assume 'table_base' is accessible via its name
table['table_base'].anchor = (0, 0, 0)  

# At this point we have information to populate 
# 'anchor' locations for other components

As shown above, we first build primitives (assume I have representations for that). Then we build table as an abstract geometry object. Finally we provide the anchor location for the base. When I hit build(), I want this information to cascade down the dependency tree and populate anchor locations for other components. Admittedly, I can require clients to bookeep their own anchor locations, but with complex objects it becomes tedious. What is an appropriate representation to hold the abstract relationships between the components prior to the build step?

As you can probably tell, I dont have background in compilers or writing DSLs. So even the name for what I'm looking for would be a great starting point. Language preference Python, but I'm more interested in conceptual understanding.

0 Answers