Open dustinlacewell opened 7 years ago
This issue has been automatically marked as stale because it has not had recent activity. If you think it is still a valid issue, write a comment below; otherwise it will be closed. Thank you for your contributions.
Preface
Assuming you have the
sdl2
andperlin
packages installed:46e66e41f7205b9f7f292d5fb27d68961517abeb
of https://github.com/dustinlacewell/dadren withnimble install
dadren/examples/bsp2
executemake run
h
,v
, andd
keys along with the mouse to interact with the demo.The demo implements a 2D binary-space-partition graph. That is for a given 2D rectangle, split it either vertically or horizontally and get two new rectangles. Repeat.
The implementation of the binary tree is here: https://github.com/dustinlacewell/dadren/blob/46e66e41f7205b9f7f292d5fb27d68961517abeb/dadren/bsp.nim
It implements a simple inheritance tree:
Intended Implementation
The example that uses this BSP implementation is here: https://github.com/dustinlacewell/dadren/blob/46e66e41f7205b9f7f292d5fb27d68961517abeb/examples/bsp2/main.nim
In that example
Color
a simpleref object
type is used as theT
content for building theBSPTree
. This all works as expected.The
BSPNode
base type defines theparent
field asBSPNode
. This is not the ideal expression of the program's design. Only aParentNode
should ever be a parent in the graph. Therefore it would be ideal to have theBSPNode.parent
field by of typeParentNode
. This would avoid the otherwise unnecessary casts anytime theparent
field is accessed:https://github.com/dustinlacewell/dadren/blob/46e66e41f7205b9f7f292d5fb27d68961517abeb/dadren/bsp.nim#L134 https://github.com/dustinlacewell/dadren/blob/46e66e41f7205b9f7f292d5fb27d68961517abeb/dadren/bsp.nim#L160 https://github.com/dustinlacewell/dadren/blob/46e66e41f7205b9f7f292d5fb27d68961517abeb/dadren/bsp.nim#L172 https://github.com/dustinlacewell/dadren/blob/46e66e41f7205b9f7f292d5fb27d68961517abeb/dadren/bsp.nim#L177
Problem
When changing the
BSPNode.parent
field from typeBSPNode
toParentNode
the following error is generated:With some exploration an unusual result was discovered. Make the following changes:
Color
fromref object
=>ref object of RootObj
parent: float
The compiler error is now:
This would imply that, even though no type in the
BSPNode
hierarchy inherits fromT
, the compiler is some how conflatingT
into the resolution ofBSPNode
fields.