Hi Mario,

I have been trying to track down the reason why some densities are
> negative. A few questions I have ended up asking myself:
>
> - Is it possible for MAGNITUDE() to return a negative number? It would
> make no sense to me, but I suspect it's happening.
>

No, MAGNITUDE() is the square root of a (necessarily)  positive value.  You
can safely assume it to be not negative.

- In my little function intersection I noticed that I am returning a
> pointer to a local variable, that could be destroyed in any moment after
> the call ends. Instead of that, I want to return a safe variable. How do I
> do that in this case?
>
> I don't understand why it doesn't let me return directly the variable
> point_t. It's a pointer, because it's an array, right? As it didn't let me
> return the point, I decided to return a pointer to the point instead,
> however as I mentioned this is not safe, so I have to change it now. Any
> explanation on why I can't return the point, and what I should do to make
> it safe?
>

Well, there is a standard solution for this kind of issue: Putting the data
on the heap, e.g.
    point_t *intersect = (point_t *) bu_malloc(sizeof(point_t),
"intersection");
with the disadvantage that the caller has explicitly to free the memory
with bu_free().

It's true that C functions can't return arrays (because of historic
reason).  But, returning an array wouldn't help you here as you are using
the function's return as a flag for intersection too.  On the other hand,
structs can be returned:
    struct intersection_t {
        int intersect;
        point_t intersection_point;
    };

    struct  intersection_t intersection(point_t p0, point_t p1, point_t
p_co, vect_t p_no) {
    ....
should work.


> Finally, I think I could need some help regarding the negative values
> issue, at least once I'm sure the two points above aren't the cause.
>

Feel free to ask ;)


Regards,
    Daniel
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
BRL-CAD Developer mailing list
brlcad-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/brlcad-devel

Reply via email to