Changeset 66459


Ignore:
Timestamp:
Oct 9, 2015, 4:51:11 PM (9 years ago)
Author:
wenzeslaus
Message:

vlib: add 2D version of point in box function

Include also ctypes-based test and documentation of both the 2D and the original 3D version.

The 2D version has suffix _2d. There are some functions in the lib already which are using this style.
The 3D version has same name for compatibility reasons. There are some other functions which are just 2D
these might need _3d versions one day.

Alternative or an additional solution would be one function which would either use additional variable
like with_z or it would accept coordinates as pointers so that z could be NULL pointer.
This could make some caller code shorter.

Location:
grass/trunk/lib/vector/Vlib
Files:
2 added
1 edited

Legend:

Unmodified
Added
Removed
  • grass/trunk/lib/vector/Vlib/box.c

    r55580 r66459  
    66   Higher level functions for reading/writing/manipulating vectors.
    77
    8    (C) 2001-2009 by the GRASS Development Team
     8   (C) 2001-2015 by the GRASS Development Team
    99
    1010   This program is free software under the
     
    2121
    2222/*!
    23    \brief Tests for point in box
    24 
    25    \param x,y,z coordinates
    26    \param Box boundary box
    27 
    28    \return 1 point is in box
    29    \return 0 point is not in box
     23    \brief Tests if point is in 3D box
     24
     25    This function considers 3D point and 3D bounding box.
     26
     27    \par Example
     28
     29    \verbatim
     30    struct bound_box bbox;
     31    bbox.N = 135;
     32    bbox.S = 125;
     33    bbox.E = 220;
     34    bbox.W = 215;
     35    bbox.T = 340;
     36    bbox.B = 330;
     37    Vect_point_in_box(217, 130, 335, &bbox);
     38    \endverbatim
     39
     40    \param x coordinate (W-E direction)
     41    \param y coordinate (S-N direction)
     42    \param z coordinate (B-T direction)
     43    \param Box boundary box
     44
     45    \returns 1 if point is in box
     46    \returns 0 if point is not in box
    3047 */
    3148int Vect_point_in_box(double x, double y, double z, const struct bound_box *Box)
     
    3552            y >= Box->S && y <= Box->N &&
    3653            z >= Box->B && z <= Box->T);
     54}
     55
     56/*!
     57    \brief Tests if point is in 2D box
     58
     59    Only x and y are tested. Top and bottom of the bounding box are ignored.
     60
     61    \param x coordinate (W-E direction)
     62    \param y coordinate (S-N direction)
     63    \param Box boundary box (only W, E, S, N are used)
     64
     65    \returns 1 if point is in box
     66    \returns 0 if point is not in box
     67 */
     68int Vect_point_in_box_2d(double x, double y, const struct bound_box *Box)
     69{
     70
     71    return (x >= Box->W && x <= Box->E &&
     72            y >= Box->S && y <= Box->N);
    3773}
    3874
Note: See TracChangeset for help on using the changeset viewer.