Overview
Comment: | Add -[translateWithVector:] and -[scaleWithVector:] to OFFloatMatrix. |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
a07cf9ee161ac3ccbb461dd7dc29e7f2 |
User & Date: | js 2011-06-13 02:30:53 |
Context
2011-06-13
| ||
03:08 | Add -[multiplyWithMatrix:] to OFFloatVector. check-in: 5e9d6fea1c user: js tags: trunk | |
02:30 | Add -[translateWithVector:] and -[scaleWithVector:] to OFFloatMatrix. check-in: a07cf9ee16 user: js tags: trunk | |
00:59 | Add a note about -[OFDataArray cArray]. check-in: 32660bf70f user: js tags: trunk | |
Changes
Changes to src/OFFloatMatrix.h.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 | * file. */ #include <stdarg.h> #import "OFObject.h" /** * \brief A class for storing and manipulating matrices of floats. */ @interface OFFloatMatrix: OFObject <OFCopying> { size_t rows, columns; float *data; | > > | 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | * file. */ #include <stdarg.h> #import "OFObject.h" @class OFFloatVector; /** * \brief A class for storing and manipulating matrices of floats. */ @interface OFFloatMatrix: OFObject <OFCopying> { size_t rows, columns; float *data; |
166 167 168 169 170 171 172 173 | */ - (void)multiplyWithMatrix: (OFFloatMatrix*)matrix; /** * \brief Transposes the receiver. */ - (void)transpose; @end | > > > > > > > > > > > > > > | 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 | */ - (void)multiplyWithMatrix: (OFFloatMatrix*)matrix; /** * \brief Transposes the receiver. */ - (void)transpose; /** * \brief Translates the nxn matrix of the receiver with an n-1 vector. * * \param vector The vector to translate with */ - (void)translateWithVector: (OFFloatVector*)vector; /** * \brief Scales the nxn matrix of the receiver with an n-1 vector. * * \param scale The vector to scale with */ - (void)scaleWithVector: (OFFloatVector*)vector; @end |
Changes to src/OFFloatMatrix.m.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 | #include "config.h" #include <string.h> #include <math.h> #import "OFFloatMatrix.h" #import "OFString.h" #import "OFInvalidArgumentException.h" #import "OFNotImplementedException.h" #import "OFOutOfRangeException.h" #import "macros.h" | > | 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | #include "config.h" #include <string.h> #include <math.h> #import "OFFloatMatrix.h" #import "OFFloatVector.h" #import "OFString.h" #import "OFInvalidArgumentException.h" #import "OFNotImplementedException.h" #import "OFOutOfRangeException.h" #import "macros.h" |
365 366 367 368 369 370 371 372 | for (j = i; j < rows * columns; j += rows) newData[j] = data[k++]; } [self freeMemory: data]; data = newData; } @end | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 | for (j = i; j < rows * columns; j += rows) newData[j] = data[k++]; } [self freeMemory: data]; data = newData; } - (void)translateWithVector: (OFFloatVector*)vector { OFFloatMatrix *translation; float *cArray; if (rows != columns || [vector dimension] != rows - 1) @throw [OFInvalidArgumentException newWithClass: isa selector: _cmd]; cArray = [vector cArray]; translation = [[OFFloatMatrix alloc] initWithRows: rows columns: columns]; memcpy(translation->data + (columns - 1) * rows, cArray, (rows - 1) * sizeof(float)); @try { [self multiplyWithMatrix: translation]; } @finally { [translation release]; } } - (void)scaleWithVector: (OFFloatVector*)vector { OFFloatMatrix *scale; float *cArray; size_t i, j; if (rows != columns || [vector dimension] != rows - 1) @throw [OFInvalidArgumentException newWithClass: isa selector: _cmd]; cArray = [vector cArray]; scale = [[OFFloatMatrix alloc] initWithRows: rows columns: columns]; for (i = j = 0; i < ((rows - 1) * columns) - 1; i += rows + 1) scale->data[i] = cArray[j++]; @try { [self multiplyWithMatrix: scale]; } @finally { [scale release]; } } @end |