ObjFW  Check-in [5e9d6fea1c]

Overview
Comment:Add -[multiplyWithMatrix:] to OFFloatVector.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 5e9d6fea1c1e58076dfa86dd74fa6de4f02ff5864d46413076016c9144af1809
User & Date: js on 2011-06-13 03:08:42
Other Links: manifest | tags
Context
2011-06-13
03:47
Fix -[conformsToProtocol:] for the old GNU runtime. check-in: a1769f0105 user: js tags: trunk
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
Changes

Modified src/OFFloatVector.h from [0573d05fbc] to [a8920f92ed].

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 vectors of floats.
 */
@interface OFFloatVector: OFObject <OFCopying>
{
	size_t dimension;
	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 OFFloatMatrix;

/**
 * \brief A class for storing and manipulating vectors of floats.
 */
@interface OFFloatVector: OFObject <OFCopying>
{
	size_t dimension;
	float *data;
160
161
162
163
164
165
166








167
 */
- (float)magnitude;

/**
 * \brief Normalizes the vector.
 */
- (void)normalize;








@end







>
>
>
>
>
>
>
>

162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
 */
- (float)magnitude;

/**
 * \brief Normalizes the vector.
 */
- (void)normalize;

/**
 * \brief Multiplies the receiver with the specified matrix on the left side and
 *	  the receiver on the right side.
 *
 * \param matrix The matrix to multiply the receiver with
 */
- (void)multiplyWithMatrix: (OFFloatMatrix*)matrix;
@end

Modified src/OFFloatVector.m from [3b46b56f41] to [5ca73ec320].

16
17
18
19
20
21
22

23
24
25
26
27
28
29

#include "config.h"

#include <string.h>
#include <math.h>

#import "OFFloatVector.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 "OFFloatVector.h"
#import "OFFloatMatrix.h"
#import "OFString.h"

#import "OFInvalidArgumentException.h"
#import "OFNotImplementedException.h"
#import "OFOutOfRangeException.h"

#import "macros.h"
313
314
315
316
317
318
319


































320
	size_t i;

	magnitude = [self magnitude];

	for (i = 0; i < dimension; i++)
		data[i] /= magnitude;
}


































@end







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
	size_t i;

	magnitude = [self magnitude];

	for (i = 0; i < dimension; i++)
		data[i] /= magnitude;
}

- (void)multiplyWithMatrix: (OFFloatMatrix*)matrix
{
	size_t rows, columns;
	float *cArray, *newData;
	size_t i, j, k;

	columns = [matrix columns];

	if (dimension != columns)
		@throw [OFInvalidArgumentException newWithClass: isa
						       selector: _cmd];

	rows = [matrix rows];
	cArray = [matrix cArray];

	newData = [self allocMemoryForNItems: rows
				    withSize: sizeof(float)];
	memset(newData, 0, rows * sizeof(float));

	for (i = j = k = 0; i < rows * columns; i++) {
		newData[j] += cArray[i] * data[k];

		if (++j == rows) {
			k++;
			j = 0;
		}
	}

	[self freeMemory: data];
	data = newData;

	dimension = rows;
}
@end