IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jun 10, 2007, 7:54:05 AM (19 years ago)
Author:
magnier
Message:

adding psRegionAndParityFromString

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/math/psRegion.c

    r10999 r13741  
    88#include "psError.h"
    99#include "psAssert.h"
     10#include "psConstants.h"
    1011#include "psRegion.h"
    1112
     
    8384}
    8485
     86psRegion psRegionAndParityFromString(int *xParity, int *yParity, const char* region)
     87{
     88    PS_ASSERT_PTR_NON_NULL (xParity, psRegionSet(NAN,NAN,NAN,NAN));
     89    PS_ASSERT_PTR_NON_NULL (yParity, psRegionSet(NAN,NAN,NAN,NAN));
     90
     91    psS32 col0;
     92    psS32 col1;
     93    psS32 row0;
     94    psS32 row1;
     95
     96    // unless otherwise detected
     97    *xParity = +1;
     98    *yParity = +1;
     99
     100    // section should be of the form '[col0:col1,row0:row1]'
     101    if (region == NULL) {
     102        return psRegionSet(0,0,0,0);
     103    }
     104
     105    if (sscanf(region,"[%d:%d,%d:%d]",&col0,&col1,&row0,&row1) < 4) {
     106        psError(PS_ERR_BAD_PARAMETER_NULL, true,
     107                _("Specified subsection string, '%s', can not be parsed.  Must be in the form '[x1:x2,y1:y2]'."),
     108                region);
     109        return psRegionSet(NAN,NAN,NAN,NAN);
     110    }
     111
     112    // [0:0,0:0] is complete image region
     113    if ((col0 == 0) && (col1 == 0) && (row0 == 0) && (row1 == 0)) {
     114        return psRegionSet(0,0,0,0);
     115    }
     116
     117    if ((col1 > 0) && (col0 > col1)) {
     118        *xParity = -1;
     119        PS_SWAP (col0, col1);
     120    }
     121
     122    if ((row1 > 0) && (row0 > row1)) {
     123        *yParity = -1;
     124        PS_SWAP (row0, row1);
     125    }
     126
     127    return psRegionSet(col0-1,col1,row0-1,row1);
     128}
     129
    85130psString psRegionToString(const psRegion region)
    86131{
Note: See TracChangeset for help on using the changeset viewer.