numerics 0.1.0
Loading...
Searching...
No Matches
num::Vec2View Struct Reference

Non-owning view of a flat Vector as an array of 2D points. More...

#include <vector.hpp>

Public Member Functions

idx size () const noexcept
 Number of 2D points (= v.size() / 2).
 
realx (idx i) noexcept
 
real x (idx i) const noexcept
 
realy (idx i) noexcept
 
real y (idx i) const noexcept
 

Public Attributes

Vectorv
 

Detailed Description

Non-owning view of a flat Vector as an array of 2D points.

Many physics simulations pack 2D positions or velocities into a flat Vector with stride 2: element i has x = v[2i], y = v[2i+1]. Vec2View provides named accessors that eliminate the raw index arithmetic without copying or reshaping the data.

Example:

num::Vector q(2 * N); // flat storage: [x0,y0, x1,y1, ...]
pos.x(i) = 1.0; // writes q[2*i]
pos.y(i) = 2.0; // writes q[2*i+1]
idx n = pos.size(); // = N
std::size_t idx
Definition types.hpp:11
Non-owning view of a flat Vector as an array of 2D points.
Definition vector.hpp:170
real & x(idx i) noexcept
Definition vector.hpp:176

Definition at line 170 of file vector.hpp.

Member Function Documentation

◆ size()

idx num::Vec2View::size ( ) const
inlinenoexcept

Number of 2D points (= v.size() / 2).

Definition at line 174 of file vector.hpp.

References num::BasicVector< T >::size(), and v.

◆ x() [1/2]

real num::Vec2View::x ( idx  i) const
inlinenoexcept

Definition at line 177 of file vector.hpp.

References v.

◆ x() [2/2]

real & num::Vec2View::x ( idx  i)
inlinenoexcept

Definition at line 176 of file vector.hpp.

References v.

◆ y() [1/2]

real num::Vec2View::y ( idx  i) const
inlinenoexcept

Definition at line 179 of file vector.hpp.

References v.

◆ y() [2/2]

real & num::Vec2View::y ( idx  i)
inlinenoexcept

Definition at line 178 of file vector.hpp.

References v.

Member Data Documentation

◆ v

Vector& num::Vec2View::v

Definition at line 171 of file vector.hpp.

Referenced by size(), x(), x(), y(), and y().


The documentation for this struct was generated from the following file: