HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
Files | Data Structures | Enumerations | Functions
Geometry

Files

file  aarectangle.hpp
 
file  alignment.hpp
 types and utilities for alignment.
 
file  corner_radii.hpp
 Defined the corner_radii type.
 
file  extent2.hpp
 Defined the geo::extent, extent2 and extent3 types.
 
file  extent3.hpp
 Defined the geo::extent, extent2 and extent3 types.
 
file  line_end_cap.hpp
 Defined line_end_cap.
 
file  line_join_style.hpp
 Defines line_join_style.
 
file  line_segment.hpp
 Defines line_segment.
 
file  lookat.hpp
 Defines lookat.
 

Data Structures

class  hi::v1::aarectangle
 Class which represents an axis-aligned rectangle. More...
 
class  hi::v1::alignment
 Horizontal/Vertical alignment combination. More...
 
class  hi::v1::corner_radii
 The 4 radii of the corners of a quad or rectangle. More...
 
class  hi::v1::extent2
 A high-level geometric extent. More...
 
class  hi::v1::extent3
 A high-level geometric extent. More...
 
class  hi::v1::line_segment
 Line segment. More...
 
class  hi::v1::lookat
 Perspective transform. More...
 
class  hi::v1::margins
 The left, bottom, right and top margins. More...
 
class  hi::v1::perspective
 Perspective transform. More...
 
struct  hi::v1::box_constraints
 2D constraints. More...
 

Enumerations

enum class  hi::v1::vertical_alignment : uint8_t { hi::v1::vertical_alignment::none = 0 , hi::v1::vertical_alignment::top = 1 , hi::v1::vertical_alignment::middle = 2 , hi::v1::vertical_alignment::bottom = 3 }
 Vertical alignment. More...
 
enum class  hi::v1::horizontal_alignment : uint8_t {
  hi::v1::horizontal_alignment::none = 0 , hi::v1::horizontal_alignment::flush = 1 , hi::v1::horizontal_alignment::left = 2 , hi::v1::horizontal_alignment::center = 3 ,
  hi::v1::horizontal_alignment::justified = 4 , hi::v1::horizontal_alignment::right = 5
}
 Horizontal alignment. More...
 
enum class  hi::v1::axis : unsigned char {
  none = 0 , x = 1 , y = 2 , z = 4 ,
  both = x | y , all = x | y | z , horizontal = x , vertical = y
}
 An enumeration of the 3 axis for 3D geometry. More...
 
enum class  hi::v1::line_end_cap { hi::v1::line_end_cap::flat , hi::v1::line_end_cap::round }
 The way two lines should be joined. More...
 
enum class  hi::v1::line_join_style { hi::v1::line_join_style::none , hi::v1::line_join_style::bevel , hi::v1::line_join_style::miter , hi::v1::line_join_style::round }
 The way two lines should be joined. More...
 

Functions

constexpr std::optional< float > hi::v1::make_guideline (vertical_alignment alignment, float bottom, float top, float guideline_width)
 Create a guideline between two points.
 
constexpr std::optional< float > hi::v1::make_guideline (horizontal_alignment alignment, float left, float right, float guideline_width=0.0f)
 Create a guideline between two points.
 
constexpr axis hi::v1::operator& (axis const &lhs, axis const &rhs) noexcept
 AND the axis.
 
constexpr axis hi::v1::operator| (axis const &lhs, axis const &rhs) noexcept
 OR the axis.
 
constexpr bool hi::v1::to_bool (axis const &rhs) noexcept
 Check if any of the axis are set.
 
 hi_export_module (hikogui.geometry :margins)
 geometry/margins.hpp
 
std::pair< std::size_t, std::size_tv1::parse_spreadsheet_address (std::string_view address, std::size_t start_column_nr=0, std::size_t start_row_nr=0)
 Parse a spreadsheet address.
 
std::tuple< std::size_t, std::size_t, std::size_t, std::size_tv1::parse_spreadsheet_range (std::string_view address, std::size_t start_column_nr=0, std::size_t start_row_nr=0)
 Parse a spreadsheet range.
 

Detailed Description

Low level geometry types

numeric_array<T,N>

The simd is an array of numbers, with many mathematical operations on the array of numbers. The simd is designed to be useable in constexpr and easily to vectorize by the optimizer.

f32x4

The f32x4 is an simd<float,4>.

Many of the operations on a f32x4 are hand optimized using the intel intrinsics on SSE registers.

High level geometry type

geo::vector<D>

A vector is a direction and distance.

When transforming a vector, only scale, rotation and shear have effect.

Both vector2 and vector3 are implemented as a f32x4 homogeneous 4D coordinate with w = 0.0.

geo::point<D>

A point is a location in space.

A point can be transformed in the same way as a vector and also be translated.

Both point2 and point3 are implemented as a f32x4 homogeneous 4D coordinate with w = 1.0.

geo::extent<D>

An extent is a width, height and depth.

An extent can be transformed like a vector.

Both extent2 and extent3 are implemented as a f32x4 homogeneous 4D coordinate with w = 0.0.

corner_shapes

Corner shapes are 4 floating point numbers, one for the corner in the left-bottom, right-bottom, left-top and right-top corner. Each number has the following meaning:

color

A 4D red, green, blue and alpha value. A color can be transformed like a vector3. In this case, the alpha value is ignored and copied into the result.

rectangle

A rectangle is a closed plane in three dimensions.

A rectangle can be transformed like a point3.

It should be implemented as a point3 in the left-bottom corner and two vector3s to the upper and right corners. However, it is currently implemented as 4 points, one for each corner.

aarectangle

The aarectangle class is a 2D axis-aligned rectangle.

When transforming an axis aligned rectangle in 3D or with rotation, the result will be a normal rectangle. A rectangle can be converted back to an aarectangle, as a bounding rectangle around the transformed rectangle.

An aarectangle is implemented as a f32x4 where:

Transformation types

geo::translate<D>

geo::scale<D>

geo::rotate<D>

geo::matrix<D>

The mat class is a 4x4 homogeneous transformation matrix in column-major order. Internally, this a vec for each column.

Vector * matrix multiplications are performed as if the vector is a column.

geo::transform

Coordinates

All origins (0, 0, 0) are at the bottom-left-far corner. With the x-axis pointing right, y-axis pointing up, z-axis pointing toward the camera. This is the same coordinate system as OpenGL; a right-handed coordinate system.

+y
| -z (away from camera)
| /
| /
|/
-x ----+---- +x
/|
/ |
/ |
+z |
-y

This is true for:

Window and Widget-surface coordinates

The coordinates in a window and widgets are in pixels.

With the center of the left bottom pixel having the coordinates (0.5, 0.5).

The alignment of borders to pixels is the responsibility of the widget that draws itself. The widget has access to the draw_context::draw_box_including_border() function to position the border's edge to the edge of the given rectangle, if the rectangle is rounded to integer coordinates; the rectangle, border and pixel will share the same edge.

Window depth

Z-coordinate for a window is between 0.0 (far) to 100.0 (near).

For better precision we use a reverse-z method, to combine 1/z together with float with linear precision.

Image coordinates

The coordinates in an image are in pixels. With the center of the left bottom pixel having the coordinates (0.5, 0.5).

Path coordinates

The coordinates in a path are free from scale and origin, when rendering a path to an image, the path should be first be transformed to image coordinates.

Glyph/Font coordinates

Glyph coordinates are in the number of Em units. X-axis pointing right, Y-axis pointing up. The origin (0,0) is on the crossing of the base line and left side bearing. Vertices of front faces are specified in counter clockwise order.

Corners

Corners are enumerated as follows:

When corners are packed in a 4D vector:

Edges

When edges are packed in a 4D vector:

Triangles

A front facing triangle has the vertex ordered in counter-clockwise direction.

Quads

Quads are defined as two front facing triangles.

The vertex index order is: 0, 1, 2, 2, 1, 3.

As illustrated below:

2 <--- 3
| \ ^
| \ B |
| A \ |
v \ |
0 ---> 1

Enumeration Type Documentation

◆ axis

enum class hi::v1::axis : unsigned char
strong

An enumeration of the 3 axis for 3D geometry.

It can be used as flags/mask for a set of axis.

◆ horizontal_alignment

enum class hi::v1::horizontal_alignment : uint8_t
strong

Horizontal alignment.

Enumerator
none 

No alignment.

flush 

Align the text naturally based on the writing direction of each paragraph.

This will act as flush_left if the paragraph is in left-to-right direction, and as flush_right if the paragraph is in right-to-left direction.

left 

Align the text to the left side.

The text will be flush-left independent of the writing direction.

center 

Align the text in the center.

Since the text is centered, the writing direction is unimportant.

justified 

Stretch the text to be flush to both sides.

Since the text is flush on both sides, the writing direction is unimportant.

right 

Align the text to the right side.

The text will be flush-left independent of the writing direction.

◆ line_end_cap

enum class hi::v1::line_end_cap
strong

The way two lines should be joined.

Enumerator
flat 

The end cap of the line is flat.

round 

The end cap of the line is round.

◆ line_join_style

enum class hi::v1::line_join_style
strong

The way two lines should be joined.

Enumerator
none 

Both lines have flat caps and are not joined.

bevel 

The outer vertices of both lines are connected and filled in to make a blunt corner.

miter 

The outer edge of both lines are extended until they meet to form a sharp corner.

round 

Both lines have round caps and with a shared mid-point making a round corner.

◆ vertical_alignment

enum class hi::v1::vertical_alignment : uint8_t
strong

Vertical alignment.

Enumerator
none 

No alignment.

top 

Align to the top.

middle 

Align to the vertical-middle.

bottom 

Align to the bottom.

Function Documentation

◆ hi_export_module()

hi_export_module ( hikogui.geometry :margins )

◆ make_guideline() [1/2]

constexpr std::optional< float > hi::v1::make_guideline ( horizontal_alignment alignment,
float left,
float right,
float guideline_width = 0.0f )
constexpr

Create a guideline between two points.

The horizontal guideline is may used to create alignment for text or numerics. The guideline_width should probably be set to zero.

  • aligned-left: The left of the guideline will be flush with the left-padding.
  • aligned-right: The right of the guideline will be flush with the right-padding.
  • aligned-center: The center of the guideline will be in the center between left and right; clamped by the padding.
  • aligned-none: nullopt.
Note
The padding is a soft-constraint and may be ignored if needed.
Parameters
alignmentThe horizontal alignment where to put the guideline.
leftThe x-coordinate of the left.
rightThe x-coordinate of the right.
guideline_widthThe thickness of the guideline
Returns
The x-coordinate of the left of the guideline.
Return values
std::nulloptNo alignment, or guideline does not fit in the space.

◆ make_guideline() [2/2]

constexpr std::optional< float > hi::v1::make_guideline ( vertical_alignment alignment,
float bottom,
float top,
float guideline_width )
constexpr

Create a guideline between two points.

The vertical guideline is mostly used to create a baseline; in this case the guideline_width is set to the cap-height of a font.

  • aligned-top: The top of the guideline will be flush with the top-padding.
  • aligned-bottom: The bottom of the guideline will be flush with the bottom-padding.
  • aligned-middle: The middle of the guideline will be in the middle between bottom and top; clamped by the padding.
  • aligned-none: nullopt.
Parameters
alignmentThe vertical alignment how to place the guideline.
bottomThe y-coordinate of the bottom.
topThe y-coordinate of the top.
guideline_widthThe thickness of the guideline
Returns
The y-coordinate of the bottom of the guideline.
Return values
nulloptNo alignment, or guideline does not fit in the space.

◆ operator&()

constexpr axis hi::v1::operator& ( axis const & lhs,
axis const & rhs )
constexprnoexcept

AND the axis.

◆ operator|()

constexpr axis hi::v1::operator| ( axis const & lhs,
axis const & rhs )
constexprnoexcept

OR the axis.

◆ parse_spreadsheet_address()

std::pair< std::size_t, std::size_t > v1::parse_spreadsheet_address ( std::string_view address,
std::size_t start_column_nr = 0,
std::size_t start_row_nr = 0 )
inline

Parse a spreadsheet address.

Parameters
addressThe address to parse.
start_column_nrA relative column in the address is added to the start-column.
start_row_nrA relative row in the address is added to the start-row.
Returns
The zero-based column and row index.

◆ parse_spreadsheet_range()

std::tuple< std::size_t, std::size_t, std::size_t, std::size_t > v1::parse_spreadsheet_range ( std::string_view address,
std::size_t start_column_nr = 0,
std::size_t start_row_nr = 0 )
inline

Parse a spreadsheet range.

Parameters
addressA spreadsheet address in the form "A1" or "A1:B3"
start_column_nrThe start column for relative column addressing.
start_row_nrThe start row for relative row addressing.
Returns
first_column, first_row, last_column, last_row. last_column and last_row point one beyond the last.

◆ to_bool()

constexpr bool hi::v1::to_bool ( axis const & rhs)
constexprnoexcept

Check if any of the axis are set.