data structures - C# BSP Splitting Algorithm Logical or Calculation Error -


i need advice.

okay, having problem algorithm. i'm using recursive method of adding , maintaining binary tree program, when split once done 3 times, code breaks.

for sake of example, lets we're going force algorithm's methods perform vertical splits , vertical splits, , calls vertisplit method have. method follows. doing memory, there may thing or 2 wrong... going simplest way possible this.

public void vertisplit(node curnode) //the node called method passed in. {  int vratio = curnode.height / curnode.width;  //if( vratio <=2) // commented out never horizontal split.  //{      //calculate split point data parent node called method.      curnode.splitx = curnode.xcoor + (curnode.width / 2);      curnode.splity = curnode.ycoor;      curnode.splitw = 1; // 1 because passed draw call line.      curnode.splith = curnode.height;      // calculate data children...      curnode.child1.xcoor = curnode.xcoor;      curnode.child2.xcoor = curnode.splitx;      curnode.child1.ycoor = curnode.ycoor;      curnode.child2.ycoor = curnode.ycoor;      curnode.child1.width = curnode.splitx;      curnode.child2.width = curnode.splitx;      curnode.child1.height = curnode.height;      curnode.child2.height = curnode.height; //at point, calculations , assignment of children's variables completed. i'll stop writing code here.. 

assume below point report method, closing bracket, , else statement false condition of above if statement calls horizontal split (horisplit) method. going through logically. calculations should go this. dungeon size 512 x 512 square. split x object of interest here.

1st iteration: node id: 0 split x: 256

2nd iteration: node id: 1 split x: 128 node id: 2 split x: 384

3rd iteration: node id: 3 split x: 64 node id: 4 split x: 192 node id: 5 split x: 320 node id: 6 split x: 448

however, iteration #3, instead this:

3rd iteration: node id: 3 split x: 64 node id: 4 split x: 192 node id: 5 split x: 448 node id: 6 split x: 448

the way code written, it should not doing this. yet why node #5 broken, while others okay? don't know @ point, , @ wit's end it. me?

also, there's thing isn't working. trying convert temp string variable 32-bit integer use method called splitcreateall takes value of numsplits (which supposed integer) assigned value of temp, controlled textbox in the gui unity. reason, every time try have temp parsed numsplits can assigned it's value, after changing 0 typing in textbox, error occurs says temp not in correct format. can tell me went wrong there too?

edit:

public void growbranches(node curnode) {   int randomval = randnum.next();    if(curnode.child1 != null)      {        findleaves(curnode.child1);        findleaves(curnode.child2);      }   if(curnode.child1 == null)     {       curnode.child1 = new node();       curnode.child2 = new node();       curnode.child1.parent = curnode;       curnode.child2.parent = curnode;       curnode.child1.sister = curnode.child2;       curnode.child2.sister = curnode.child1;     }     if(randomval % 2 == 0)     {      vertisplit(curnode);     }     else     {       horisplit(curnode);     } 

there growbranches method. split methods called in recursion chain. growbranches called methods splitcreateonce , splitcreateall, latter non-functional due above stated reason involving parsing error.

if had guess i'd these 2 lines:

 curnode.child1.width = curnode.splitx;  curnode.child2.width = curnode.splitx; 

looking @ node xcoord=256, width=256, splitx 386 (xcoord + 256/2) that's not width of child node, width 256/2. code above have child xcoord 386, width 386.

as second part of question text error, if using unity text box it's when clear existing value start typing end passing empty string convert.toint32. use try/catch , ignore error.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -