Index: src/OFFloatVector.h ================================================================== --- src/OFFloatVector.h +++ src/OFFloatVector.h @@ -94,10 +94,20 @@ * * \return The dimension of the vector */ - (size_t)dimension; +/** + * \brief Changes the dimension of the vector. + * + * If the new dimension is smaller, elements will be cut off. + * If the new dimension is bigger, new elements will be filled with zeros. + * + * \param dimension The new dimension for the vector + */ +- (void)setDimension: (size_t)dimension; + /** * \brief Returns an array of floats with the contents of the vector. * * Modifying the returned array directly is allowed and will change the vector. * Index: src/OFFloatVector.m ================================================================== --- src/OFFloatVector.m +++ src/OFFloatVector.m @@ -157,10 +157,28 @@ - (size_t)dimension { return dimension; } + +- (void)setDimension: (size_t)dimension_ +{ + float *newData; + size_t i; + + if ((newData = realloc(data, dimension_ * sizeof(float))) == NULL) + @throw [OFOutOfMemoryException newWithClass: isa + requestedSize: dimension_ * + sizeof(float)]; + + data = newData; + + for (i = dimension; i < dimension_; i++) + data[i] = 0; + + dimension = dimension_; +} - (BOOL)isEqual: (id)object { OFFloatVector *otherVector;