Differences From Artifact [ca289ecb6a]:
- File
src/OFFloatVector.m
— part of check-in
[f3db074478]
at
2011-09-17 19:18:09
on branch trunk
— Make hashes independant of endianess in OF{Float,Double}{Vector,Matrix}.
Also removes unnecessary OF_HASH_ADD_INT* macros (except
OF_HASH_ADD_INT32 which was often used to hash hashes and is now called
OF_HASH_ADD_HASH). (user: js, size: 8328) [annotate] [blame] [check-ins using]
To Artifact [0c98a1d7e8]:
- File
src/OFFloatVector.m
— part of check-in
[e1e7ffa903]
at
2011-09-22 23:25:42
on branch trunk
— Exceptions are now autoreleased.
This is safe as an "exception loop" can't happen, since if allocating
an exception fails, it throws an OFAllocFailedException which is
preallocated and can always be thrown.So, the worst case would be that an autorelease of an exception fails,
triggering an OFOutOfMemoryException for which there is no memory,
resulting in an OFAllocFailedException to be thrown. (user: js, size: 8405) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
60 61 62 63 64 65 66 | return ret; } - init { Class c = isa; [self release]; | | | | | | | 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | return ret; } - init { Class c = isa; [self release]; @throw [OFNotImplementedException exceptionWithClass: c selector: _cmd]; } - initWithDimension: (size_t)dimension_ { self = [super init]; @try { dimension = dimension_; if (SIZE_MAX / dimension < sizeof(float)) @throw [OFOutOfRangeException exceptionWithClass: isa]; if ((data = malloc(dimension * sizeof(float))) == NULL) @throw [OFOutOfMemoryException exceptionWithClass: isa requestedSize: dimension * sizeof(float)]; memset(data, 0, dimension * sizeof(float)); } @catch (id e) { [self release]; @throw e; } |
︙ | ︙ | |||
115 116 117 118 119 120 121 | @try { size_t i; dimension = dimension_; if (SIZE_MAX / dimension < sizeof(float)) | | | | | 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 | @try { size_t i; dimension = dimension_; if (SIZE_MAX / dimension < sizeof(float)) @throw [OFOutOfRangeException exceptionWithClass: isa]; if ((data = malloc(dimension * sizeof(float))) == NULL) @throw [OFOutOfMemoryException exceptionWithClass: isa requestedSize: dimension * sizeof(float)]; data[0] = data_; for (i = 1; i < dimension; i++) data[i] = (float)va_arg(arguments, double); } @catch (id e) { [self release]; @throw e; |
︙ | ︙ | |||
144 145 146 147 148 149 150 | [super dealloc]; } - (void)setValue: (float)value atIndex: (size_t)index { if (index >= dimension) | | | | > | < | 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 | [super dealloc]; } - (void)setValue: (float)value atIndex: (size_t)index { if (index >= dimension) @throw [OFOutOfRangeException exceptionWithClass: isa]; data[index] = value; } - (float)valueAtIndex: (size_t)index { if (index >= dimension) @throw [OFOutOfRangeException exceptionWithClass: isa]; return data[index]; } - (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 exceptionWithClass: isa requestedSize: dimension_ * sizeof(float)]; data = newData; for (i = dimension; i < dimension_; i++) data[i] = 0; dimension = dimension_; |
︙ | ︙ | |||
293 294 295 296 297 298 299 | } - (void)addVector: (OFFloatVector*)vector { size_t i; if (vector->isa != isa || vector->dimension != dimension) | | | | | | 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 | } - (void)addVector: (OFFloatVector*)vector { size_t i; if (vector->isa != isa || vector->dimension != dimension) @throw [OFInvalidArgumentException exceptionWithClass: isa selector: _cmd]; for (i = 0; i < dimension; i++) data[i] += vector->data[i]; } - (void)subtractVector: (OFFloatVector*)vector { size_t i; if (vector->isa != isa || vector->dimension != dimension) @throw [OFInvalidArgumentException exceptionWithClass: isa selector: _cmd]; for (i = 0; i < dimension; i++) data[i] -= vector->data[i]; } - (void)multiplyWithScalar: (float)scalar { |
︙ | ︙ | |||
333 334 335 336 337 338 339 | } - (void)multiplyWithComponentsOfVector: (OFFloatVector*)vector { size_t i; if (vector->isa != isa || vector->dimension != dimension) | | | | | | | | | | | | | | | | 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 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 | } - (void)multiplyWithComponentsOfVector: (OFFloatVector*)vector { size_t i; if (vector->isa != isa || vector->dimension != dimension) @throw [OFInvalidArgumentException exceptionWithClass: isa selector: _cmd]; for (i = 0; i < dimension; i++) data[i] *= vector->data[i]; } - (void)divideByComponentsOfVector: (OFFloatVector*)vector { size_t i; if (vector->isa != isa || vector->dimension != dimension) @throw [OFInvalidArgumentException exceptionWithClass: isa selector: _cmd]; for (i = 0; i < dimension; i++) data[i] /= vector->data[i]; } - (float)dotProductWithVector: (OFFloatVector*)vector { float dotProduct; size_t i; if (vector->isa != isa || vector->dimension != dimension) @throw [OFInvalidArgumentException exceptionWithClass: isa selector: _cmd]; dotProduct = 0.0f; for (i = 0; i < dimension; i++) dotProduct += data[i] * vector->data[i]; return dotProduct; } - (OFFloatVector*)crossProductWithVector: (OFFloatVector*)vector { OFFloatVector *crossProduct; if (dimension != 3) @throw [OFNotImplementedException exceptionWithClass: isa selector: _cmd]; if (vector->dimension != dimension) @throw [OFInvalidArgumentException exceptionWithClass: isa selector: _cmd]; crossProduct = [OFFloatVector vectorWithDimension: 3]; crossProduct->data[0] = data[1] * vector->data[2] - data[2] * vector->data[1]; crossProduct->data[1] = data[2] * vector->data[0] - data[0] * vector->data[2]; crossProduct->data[2] = data[0] * vector->data[1] - data[1] * vector->data[0]; return crossProduct; } - (void)multiplyWithMatrix: (OFFloatMatrix*)matrix { float *newData; size_t i, j, k; if (matrix->isa != floatMatrix || dimension != matrix->columns) @throw [OFInvalidArgumentException exceptionWithClass: isa selector: _cmd]; if ((newData = malloc(matrix->rows * sizeof(float))) == NULL) @throw [OFOutOfMemoryException exceptionWithClass: isa requestedSize: matrix->rows * sizeof(float)]; memset(newData, 0, matrix->rows * sizeof(float)); for (i = j = k = 0; i < matrix->rows * matrix->columns; i++) { newData[j] += matrix->data[i] * data[k]; if (++j == matrix->rows) { |
︙ | ︙ |