URL: https://graphicscomputing.fr/cgp/reference/vec2/
Description: 2D vector of floats.

# vec2

C++ type: `numarray_stack<float,2>`.
2D vector of floats.

Fields:

- `T x` - First coordinate of the vector.
- `T y` - Second coordinate of the vector.

Functions taking it:

- `void check_index_bounds(INDEX_TYPE index, numarray_stack<T,2> const& data)` - Raises an error if the index is outside [0, 1]; no-op when CGP_NO_DEBUG is defined.
- `T const& get(numarray_stack<T,2> const& data)` - Component idx with the index checked at compile time (static_assert).
- `std::string type_str(numarray_stack<T,2> const&)` - Type name as a string, e.g. "numarray_stack2<int>".
- `std::string type_str(vec2 const&)` - Type name as a string: "vec2".
- `vec2 orthogonal_vector(vec2 const& v)` - Unit vector orthogonal to v (v rotated by -90 degrees and normalized); returns (1,0) for a zero vector.
- `mat2 tensor_product(vec2 const& a, vec2 const& b)` - Outer product a * transpose(b), as a 2x2 matrix.
- `float noise_perlin(vec2 const& p, int octave = 5, float persistency = 0.3f, float frequency_gain = 2.0f)` - Fractal 2D noise in [0,1] summing octave layers of simplex noise, each layer scaled in amplitude by persistency and in frequency by frequency_gain (defaults 5, 0.3, 2).
- `vec3 camera_ray_direction(mat4 const& camera_frame, mat4 const& perspective_inverse, vec2 const& screen_position)` - Unit world-space direction of the ray through a screen position given in normalized device coordinates [-1,1]^2, from the camera frame and the inverse projection matrix.
- `vec3 translation_in_plane(vec2 const& translation, rotation_transform const& plane_orientation)` - 3D vector of a 2D translation expressed in the xy plane of the given orientation.
- `rotation_transform trackball_rotation(vec2 const& p0, vec2 const& p1)` - Rotation moving the trackball projection of p0 onto that of p1, identity if the two points are closer than 1e-4.
- `void opengl_uniform(opengl_shader_structure const& shader, std::string const& name, vec2 const& value, bool expected = true)` - Send a vec2 uniform to the shader; warns if the uniform is not found and expected is true.
- `intersection_structure picking_plane_orthogonal_to_camera(vec2 const& screen_position, vec3 const& plane_position, camera_generic_base const& camera, camera_projection_perspective const& projection)` - Intersects the camera ray through the screen position (relative coordinates) with the plane through plane_position orthogonal to the front direction of the camera.
- `picking_structure picking_spheres(vec2 const& screen_click, numarray<vec3> const& spheres_centers, float spheres_radius, camera_generic_base const& camera, camera_projection_perspective const& projection)` - Cast a ray through a screen position (normalized device coordinates) and return the closest hit among spheres of common radius, with its index, position and normal.
- `picking_structure picking_mesh_vertex_as_sphere(vec2 const& screen_click, numarray<vec3> const& vertex_position, numarray<vec3> const& vertex_normal, float picking_distance, camera_generic_base const& camera, camera_projection_perspective const& projection)` - Casts the camera ray through the screen position and returns the closest vertex whose sphere of radius picking_distance it hits, with the hit point, the vertex normal and the vertex index (active is false if none).

Functions returning it:

- `numarray_stack<T,N2> const& get(matrix_stack<T,N1,N2> const& data)` - Row idx1 as a vector, with the index checked at compile time (static_assert).
