On Wed, 9 Apr 2008 09:49:48 0700 (PDT), pereges <(EMail Removed)>
wrote:
>in my program i have a piece of code like this 
>
>int left_count, right_count;
>left_count = right_count = 0;
>for all triangles
>{
>
>a = condition that x coordinates of all vertices are <= split.x
>b = condition that x coordinates of all vertices that are >= split.x
>
>if(a is true)
>left_count++;
>else
This else does not exist in either set of code below. Fortunately it
makes no difference (except for a pathological case) but you need to
be precise in your descriptions.
>if(b is true)
>right_count++;
>else
>if(!a && !b)
>{
> left_count++;
> right_count++;
>}
>
>}
>
>Now with the above code, I get left_count as 1200 and right_count 619
>
>When I did not have the else if(!a && !b), I was getting 581 and 581
>which is 1162 i.e. triangles which are only in left box and only in
>right box . Not the ones that belong to both left and right boxes. So
>that means triangles which are on both sides totals to about 38. I
>believe 619 for right_count is correct but theres something fishy
>about lefT_count which should also be 619 or so in my opinion. Prior
>to changing the code in the above manner i had if cases like below 
>
>if(a is true)
>left_count++;
>
>if(b is true)
>right_count++;
>
>else
>{
> left_count++;
> right_count++;
>}
>
>And I was getting left_count and right_count as 1200 and 1200 which
>was quite surprising to see.
Given your description of what a and b represent, both should not be
true except for a pathological case I will ignore for the moment.
However, both can be false.
If a is true, b must be false. You increment left_count twice, once
in the first if and one in the else. You also increment right_count
once in the else. Let a be true A times.
If b is true, a must be false. You increment right_count only once in
the second if and never increment left_count. Let b be true B times.
If both a and b are false, your increment both left_ and right_count
in the else. Let this condition occur C times.
left_count must equal 2*A+C.
right_count must equal A+B+C
The only way left_count can equal right_count is if A == B.
>
>
>**actual code **
>
>for(i=0; i<(*kd)>maxtriangles; i++)
>{
>
> a = (*kd)>v[(*kd)>t[i].v0].x <=(*kd)>split.x && (*kd)>v[(*kd)
>>t[i].v1].x <= (*kd)>split.x &&(*kd)>v[(*kd)>t[i].v2].x <= (*kd)
>>split.x;
>
> b = (*kd)>v[(*kd)>t[i].v0].x <=(*kd)>split.x && (*kd)>v[(*kd)
>>t[i].v1].x <= (*kd)>split.x &&(*kd)>v[(*kd)>t[i].v2].x <= (*kd)
>>split.x;
And here is the error that forces A to be equal to B. Your
comparisons for b should be >=, not <=. One might also argue that the
comparisons should be < and > without the =.
>
> if(a)
> left_count++;
> if(b)
> right_count++;
> else
> if(!a && !b)
> {
> left_count++;
> right_count++;
> }
If you indented more than one space and did so consistently, tit would
be much easier for you to tell what went with what.
>
>}
Remove del for email
