You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
use the h, v, and d 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.
BSPNode[T] -> Leaf[T] # contains actual T content
BSPNode[T] -> ParentNode[T] -> VSplit[T] # has two BSPNode children
BSPNode[T] -> ParentNode[T] -> HSplit[T] # has two BSPNode children
In that example Color a simple ref object type is used as the T content for building the BSPTree. This all works as expected.
The BSPNode base type defines the parent field as BSPNode. This is not the ideal expression of the program's design. Only a ParentNode should ever be a parent in the graph. Therefore it would be ideal to have the BSPNode.parent field by of type ParentNode. This would avoid the otherwise unnecessary casts anytime the parent field is accessed:
When changing the BSPNode.parent field from type BSPNode to ParentNode the following error is generated:
bsp.nim(30, 20) Error: inheritance only works with non-final objects
With some exploration an unusual result was discovered. Make the following changes:
change the base type of Color from ref object => ref object of RootObj
add a field to color: parent: float
The compiler error is now:
bsp.nim(31, 17) Error: type mismatch: got (BSPNode[]) but expected 'float'
This would imply that, even though no type in the BSPNode hierarchy inherits from T, the compiler is some how conflating T into the resolution of BSPNode fields.
The text was updated successfully, but these errors were encountered:
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.
stalebot
added
the
stale
Staled PR/issues; remove the label after fixing them
label
Aug 4, 2020
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.The text was updated successfully, but these errors were encountered: