V
for Vector is a simple implementation of a 3-vector in C++. It is restricted to the type double
as it is primarily intended for scientific computing use. The aim of this library is to provide a set of diverse operations that are quite trivial in its nature but their error free implementation is essential for many problems in scientific computing.
The library is published as a stand-alone entity as it finds ubiquitous use in many projects (except for use of STL headers). At the same time, it needs to be reliably maintained and expanded for needs of newer projects.
The library is also a personal project and primarily caters to my own use. However, for the same reason — comprehensibility, efficiency, and accuracy are a primary concern. That said, the library is under continuous development and might be intrinsically broken.
Thedev
directory contains the new developments.
vforvector
is compiling without errors.- Add "New Ideas" & compile.
- Complete
Mesh
modue. - Complete
Lattice
module.
X //-> x-component
Y //-> y-component
Z //-> z-component
static V::tolerance //-> Tolerance used in floating point comparisions (allowed error)
static V::floatfield //-> Output formatting for string representation
static V::precision //-> Precision used for formatting string output
-
Constructors
-
Info functions
-
Component Accessors
-
Const Operators
-
Size functions
-
Norm functions
-
Negative functions
-
Check functions
-
Product functions
-
Scalar functions
-
Templates and Generators
-
Non-const operators (mutating)
-
Line (linear geometry) functions
-
Component-wise mutating operations (same operation performed for each component)
New Ideas ↓
-
Random Orthogonal functions
-
Random Unit Generators
-
Rotation functions
-
Comparator functions
-
Projection functions
-
Linear algebra functions
-
V-Set Generators
-
Generic Summations and Multiplication functions
-
Inverse functions
-
From string construction
-
Single header file include library. [DONE]
-
Explicit Vectorization (this is a perfect use case for trivial vectorization, pun intended).
-
Has a consistent library grammar (clear syntactic separation between accessors and modifiers).
-
Has unit tests.
-
Experiments and implements all accessor forms ↓
V vec(1.0, 2.0, 3.0); std::cout << vec.x(); //working std::cout << vec.X; //working std::cout << vec[0]; //working std::cout << vec[xx]; //working std::cout << vec['x']; //working //All statements output ==> 1.0
-
The library has 3 members x, y, z for the three vector components. It also has some other static members like
V::tolerance
. -
All operations on the object usually returns a new
V
object (const
operations). -
Methods that start with "comp_xxx()," example :
V::comp_square()
— modify the current object. The suffix "comp" stands for component and performs the same operation on all components.V eg_square(0.5, 0, 4); eg_square.comp_square(); std::cout << eg_square.info(); ==> Output : (0.25, 0, 16)
-
Any Boolean operations that check a particular condition either start with the suffix
is_
orhas_
. Example:V::is_null()
checks if the given object is a null vector. -
Any function with the suffix
f
as inV::fdot()
, whose counterpart isV::dot()
, represents fast and implies that it is the optimized version of its counterpart and lacks certain functionality (e.g. tolerance based decisions).
DONE. Change info()
to str()
.
DONE. Compile and test struct:
typedef struct
{
double X, Y, Z = 0.0;
}__attribute__((packed, aligned)) vec;
class V : vec
{
V(double x, double y, double z)
{
X = x; Y = y; Z = z;
}
// Other definations
}
// In another function
V eg(1.1, 2.2, 3.3);
double x_ = eg[0];
double y_ = eg[1];
double z_ = eg[2];
DONE. Introduce Secondary classes:
-
Q
for Quat (Quaternions) -
C
orCi
for Complex Numbers -
Generic Summations and Multiplication functions
V V::Sum(const Container<V> &c) { //Returns the component-wise sum of the container of vectors } V V::Multiply(const Container<V> &c) { //Returns the component-wide product of the container of vectors }
-
Float locale memeber that defines string representation → std::fixed, std::scientific, etc...
- The templates and generator functions modify the current member function.
- All minor operations return a modified vector.
str()
: 1-space separated values.rep()
: Representation - comma separated values in appropriate brackets.expand()
: Components added with literals. C(1.0, 2.0) → 1.0 + i2.0 .format()
: Returns a custom formatted output (only available forV
class.)
Mesh module provides a set of objects that can be used to generate specific meshes. Mesh
object defines a virtual interface for all mesh implementations. BlankMesh
object can be used to import coordinates from a file (BlankMesh::import()
). Mesh objects follow a Generating Function like interface.
Spiral2DMesh<1000, 1500> mesh;
mesh.generate(); //Compute mesh values and store.
std::vector<V> coordinates = mesh.get_mesh(); //Read the coordiantes all at once -> same as "mesh.mesh".
V coord = mesh.next(); //Read coordinates successively.
2D rectangular meshes can be used to generate 1D meshes by setting the Y
component/count to zero.
Raster2DMesh
Spiral2DMesh
Circular2DMesh
CuboidalMesh
(Can be generated using aRaster2DMesh
or aSpiral2DMesh
object)SphericalMesh
Lattice
module provides a set of objects to generate standard Bravais lattice fields.
** Planned for stage 3**