~ubuntu-branches/ubuntu/vivid/grass/vivid-proposed

« back to all changes in this revision

Viewing changes to imagery/i.ortho.photo/i.ortho.rectify/nearest.c

  • Committer: Package Import Robot
  • Author(s): Bas Couwenberg
  • Date: 2015-02-20 23:12:08 UTC
  • mfrom: (8.2.6 experimental)
  • Revision ID: package-import@ubuntu.com-20150220231208-1u6qvqm84v430b10
Tags: 7.0.0-1~exp1
* New upstream release.
* Update python-ctypes-ternary.patch to use if/else instead of and/or.
* Drop check4dev patch, rely on upstream check.
* Add build dependency on libpq-dev to grass-dev for libpq-fe.h.
* Drop patches applied upstream, refresh remaining patches.
* Update symlinks for images switched from jpg to png.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *      nearest.c - returns the nearest neighbor to a given
 
3
 *                  x,y position
 
4
 */
 
5
 
 
6
#include <math.h>
 
7
#include "global.h"
 
8
 
 
9
void p_nearest(struct cache *ibuffer,    /* input buffer                  */
 
10
               void *obufptr,            /* ptr in output buffer          */
 
11
               int cell_type,            /* raster map type of obufptr    */
 
12
               double *row_idx,          /* row index in input matrix     */
 
13
               double *col_idx,          /* column index in input matrix  */
 
14
               struct Cell_head *cellhd  /* cell header of input layer    */
 
15
    )
 
16
{
 
17
    int row, col;               /* row/col of nearest neighbor   */
 
18
    DCELL *cellp;
 
19
 
 
20
    /* cut indices to integer and get nearest cell */
 
21
    /* the row_idx, col_idx correction for bilinear/bicubic does not apply here */
 
22
    row = (int)floor(*row_idx);
 
23
    col = (int)floor(*col_idx);
 
24
 
 
25
    /* check for out of bounds - if out of bounds set NULL value     */
 
26
    if (row < 0 || row >= cellhd->rows || col < 0 || col >= cellhd->cols) {
 
27
        Rast_set_null_value(obufptr, 1, cell_type);
 
28
        return;
 
29
    }
 
30
 
 
31
    cellp = CPTR(ibuffer, row, col);
 
32
 
 
33
    if (Rast_is_d_null_value(cellp)) {
 
34
        Rast_set_null_value(obufptr, 1, cell_type);
 
35
        return;
 
36
    }
 
37
 
 
38
    Rast_set_d_value(obufptr, *cellp, cell_type);
 
39
}