MPU6050のサンプルプログラム2
Dependencies: ConfigFile SDFileSystem mbed
Fork of LAURUS_program by
Diff: Vector/Vector.cpp
- Revision:
- 23:79cdc1432160
- Parent:
- 13:df1e8a650185
--- a/Vector/Vector.cpp Tue Jun 23 15:23:38 2015 +0000 +++ b/Vector/Vector.cpp Wed Jun 24 16:16:14 2015 +0000 @@ -1,11 +1,10 @@ -#include "mbed.h" #include "myConstants.h" #include "Vector.h" Vector::Vector(int dim) : dim(dim), components(0){ components = new float[dim]; - if (!components) AbortWithMsg("Memory Allocation Error"); + if (!components) error("Memory Allocation Error"); for(int i=0; i<dim; i++) components[i] = 0.0f; } @@ -16,7 +15,7 @@ Vector::Vector(const Vector& v) : dim(v.dim), components(0) { components = new float[dim]; - if (!components) AbortWithMsg("Memory Allocation Error"); + if (!components) error("Memory Allocation Error"); memcpy(components, v.GetpComponents(), sizeof(float)*dim); } @@ -25,7 +24,7 @@ dim = v.dim; delete[] components; components = new float[dim]; - if (!components) AbortWithMsg("Memory Allocation Error"); + if (!components) error("Memory Allocation Error"); memcpy(components, v.GetpComponents(), sizeof(float)*dim); return *this; @@ -50,7 +49,7 @@ } Vector& Vector::operator/=(float c) { - if (fabs(c) < NEARLY_ZERO) AbortWithMsg("Division by Zero"); + if (fabs(c) < NEARLY_ZERO) error("Division by Zero"); for (int i = 0; i < dim; i++) { components[i] /= c; } @@ -59,7 +58,7 @@ } Vector& Vector::operator+=(const Vector& v) { - if (dim != v.dim) AbortWithMsg("failed to add: Irregular Dimention"); + if (dim != v.dim) error("failed to add: Irregular Dimention"); for (int i = 0; i < dim; i++) { components[i] += v.components[i]; } @@ -70,7 +69,7 @@ } Vector& Vector::operator-=(const Vector& v) { - if (dim != v.dim) AbortWithMsg("failed to subtract: Irregular Dimention"); + if (dim != v.dim) error("failed to subtract: Irregular Dimention"); for (int i = 0; i < dim; i++) { components[i] -= v.components[i]; } @@ -81,7 +80,7 @@ } void Vector::SetComp(int dimNo, float val) { - if (dimNo > dim) AbortWithMsg("Index Out of Bounds Error"); + if (dimNo > dim) error("Index Out of Bounds Error"); components[dimNo-1] = val; } @@ -141,8 +140,8 @@ } Vector Cross(const Vector& lhv, const Vector& rhv) { - if (lhv.GetDim() != 3) AbortWithMsg("failed to cross: variable 'dim' must be 3"); - if (lhv.GetDim() != rhv.GetDim()) AbortWithMsg("failed to cross: Irregular Dimention"); + if (lhv.GetDim() != 3) error("failed to cross: variable 'dim' must be 3"); + if (lhv.GetDim() != rhv.GetDim()) error("failed to cross: Irregular Dimention"); Vector retVec(lhv.GetDim()); @@ -167,7 +166,7 @@ } float operator*(const Vector& lhv, const Vector& rhv) { - if (lhv.GetDim() != rhv.GetDim()) AbortWithMsg("Irregular Dimention"); + if (lhv.GetDim() != rhv.GetDim()) error("Irregular Dimention"); float retVal = 0.0f; for (int i = 1; i <= lhv.GetDim(); i++) {