/** Inverses mx. * Returns materr(2) if mx isn't a square, 2x2 matrix, * or materr(1) if the initialization didn't go right. */ matrix MatrixInv(matrix mx) { if (!isValidOp(mx,mx,'i')) { return materr(2); } if(mx.rows == 2) { matrix inv = initialize(mx.rows, mx.columns); if(inv.mx == NULL) { return materr(1); } frac tmp; frac det = fdiv(i2f(1), fsub(fmul(mx.mx[0][0], mx.mx[1][1]), fmul(mx.mx[0][1], mx.mx[1][0]))); tmp = mx.mx[0][0]; inv.mx[0][0] = mx.mx[1][1]; inv.mx[1][1] = tmp; inv.mx[0][1] = fmul(mx.mx[0][1], i2f(-1)); inv.mx[1][0] = fmul(mx.mx[1][0], i2f(-1)); return MatrixSMul(mx, det); } else { return materr(2); } }
/** Adds two matrices. * Returns materr(2) if the two matrices can't * be added, materr(1) if the initialization * didn't go right. */ matrix MatrixAdd(matrix m1, matrix m2) { if (!isValidOp(m1,m2,'a')) { return materr(2); } matrix mx = initialize(m1.rows, m1.columns); if (mx.mx == NULL) { return materr(1); } for(int row = 0; row < mx.rows; row++) for(int col = 0; col < mx.columns; col++) mx.mx[row][col] = fadd(m1.mx[row][col], m2.mx[row][col]); return mx; }
/** Multiplies m1 by m2. * Returns materr(2) if the two matrices can't * be multiplied, materr(1) if the initialization * didn't go right. */ matrix MatrixMul(matrix m1, matrix m2) { if (!isValidOp(m1,m2,'m')) { return materr(2); } matrix mx = initialize(m1.rows, m2.columns); if (mx.mx == NULL) { return materr(1); } for(int row = 0; row < mx.rows; row++) { for(int col = 0; col < mx.columns; col++) { for(int i = 0; i < m1.columns; i++) { mx.mx[row][col] = fadd(mx.mx[row][col], fmul(m1.mx[row][i], m2.mx[i][col])); } } } return mx; }
void object::test<1>() { CoordinateSequence* cs = new CoordinateArraySequence(); cs->add(Coordinate(0.0, 0.0)); cs->add(Coordinate(1.0, DoubleNotANumber)); GeomPtr line ( factory_.createLineString(cs) ); IsValidOp isValidOp(line.get()); bool valid = isValidOp.isValid(); TopologyValidationError* err = isValidOp.getValidationError(); ensure(0 != err); const Coordinate& errCoord = err->getCoordinate(); ensure_equals( err->getErrorType(), TopologyValidationError::eInvalidCoordinate ); ensure(0 != ISNAN(errCoord.y)); ensure_equals(valid, false); }