EBGeometry
Compact, header-only C++ library for fast evaluation of signed distance functions
Loading...
Searching...
No Matches
Classes | Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | List of all members
EBGeometry::Profile< T > Class Template Reference

A closed outline in a plane, of straight edges, circular arcs and quadratic Bezier curves, for ProfileSDF to turn about an axis or extrude. Host only; not a shape. More...

#include <EBGeometry_Profile.hpp>

Collaboration diagram for EBGeometry::Profile< T >:
Collaboration graph
[legend]

Classes

struct  Edge
 One edge of the outline. More...
 

Public Member Functions

 Profile (const Vec2T< T > &a_start)
 Starts an outline at a point.
 
Profile & lineTo (const Vec2T< T > &a_point)
 Draws a straight edge.
 
Profile & arcTo (const Vec2T< T > &a_point, T a_radius)
 Draws a circular arc, the shorter of the two of its radius between its ends (at most a half circle).
 
Profile & quadTo (const Vec2T< T > &a_control, const Vec2T< T > &a_point)
 Draws a quadratic Bezier curve. One whose control point lies on the line between its ends, halfway, is a straight edge, and drawn as one.
 
Profile & cubicTo (const Vec2T< T > &a_control1, const Vec2T< T > &a_control2, const Vec2T< T > &a_point, T a_tolerance)
 Draws a cubic Bezier curve, as quadratic ones that stay within a distance of it.
 
std::vector< Edge > closedEdges () const
 The outline's edges, closed: with the closing edge, when the outline does not end where it started.
 
const Vec2T< T > & getCurrentPoint () const noexcept
 Where the outline is now: where the last edge ended.
 

Static Public Attributes

static constexpr uint32_t MaxEdges = 96U
 The most edges a profile can have, a cubic's pieces and the closing edge included. It keeps a ProfileSDF small enough to pass to a kernel by value, in both precisions.
 

Protected Member Functions

void checkEnd (const Vec2T< T > &a_point, const char *a_who, uint32_t a_count) const
 Checks a point an edge ends at, and that the outline has room for more edges.
 

Protected Attributes

Vec2T< T > m_start
 The first point.
 
Vec2T< T > m_current
 Where the last edge ended.
 
std::vector< Edge > m_edges
 The edges drawn.
 
uint32_t m_parts = 0U
 How many parts the edges drawn belong to.
 

Detailed Description

template<class T>
class EBGeometry::Profile< T >

A closed outline in a plane, of straight edges, circular arcs and quadratic Bezier curves, for ProfileSDF to turn about an axis or extrude. Host only; not a shape.

The outline is drawn from a first point, one edge at a time, each from where the last ended, and closes itself with a straight edge back to the first point (none when the last edge ends there). A cubic Bezier curve is drawn as quadratic ones that stay within a given distance of it. The outline may be drawn in either direction, but must not cross or touch itself, which is not checked: the surface's outward normals are taken from the direction the outline runs in, overall, and on an outline that crosses itself they point inward on part of it.

Edge k is the k-th edge drawn (a cubic's pieces in order), the closing edge last, and each edge belongs to a part: the k-th call that drew it, the closing edge being the last part. A cubic's pieces are one part, so that a curve drawn as one is picked as one surface.

Template Parameters
TFloating-point precision.

Constructor & Destructor Documentation

◆ Profile()

template<class T >
EBGeometry::Profile< T >::Profile ( const Vec2T< T > &  a_start)
explicit

Starts an outline at a point.

Parameters
[in]a_startThe first point; finite.

Member Function Documentation

◆ arcTo()

template<class T >
Profile & EBGeometry::Profile< T >::arcTo ( const Vec2T< T > &  a_point,
T  a_radius 
)

Draws a circular arc, the shorter of the two of its radius between its ends (at most a half circle).

Parameters
[in]a_pointWhere it ends; finite, and not where the outline is now.
[in]a_radiusIts radius, signed: positive turns left (counterclockwise about the center), negative right. Its size must be at least half the distance between the ends; half of it draws a half circle.
Returns
This outline.

◆ checkEnd()

template<class T >
void EBGeometry::Profile< T >::checkEnd ( const Vec2T< T > &  a_point,
const char *  a_who,
uint32_t  a_count 
) const
protected

Checks a point an edge ends at, and that the outline has room for more edges.

Parameters
[in]a_pointThe point.
[in]a_whoThe function, for the messages.
[in]a_countHow many edges are to be added.

◆ closedEdges()

template<class T >
std::vector< Edge > EBGeometry::Profile< T >::closedEdges ( ) const

The outline's edges, closed: with the closing edge, when the outline does not end where it started.

Returns
The edges.

◆ cubicTo()

template<class T >
Profile & EBGeometry::Profile< T >::cubicTo ( const Vec2T< T > &  a_control1,
const Vec2T< T > &  a_control2,
const Vec2T< T > &  a_point,
T  a_tolerance 
)

Draws a cubic Bezier curve, as quadratic ones that stay within a distance of it.

The curve is split into equal stretches of its parameter, as few as keep each stretch's quadratic within the tolerance: the distance between a cubic and the quadratic that matches its ends and its tangents there shrinks with the cube of the stretch. All of them are one part.

Parameters
[in]a_control1Its first control point; finite.
[in]a_control2Its second control point; finite.
[in]a_pointWhere it ends; finite, and not where the outline is now.
[in]a_toleranceHow far the quadratic curves may stray from the cubic; finite and positive. The pieces it takes must fit within MaxEdges.
Returns
This outline.

◆ getCurrentPoint()

template<class T >
const Vec2T< T > & EBGeometry::Profile< T >::getCurrentPoint ( ) const
inlinenoexcept

Where the outline is now: where the last edge ended.

Returns
The point.

◆ lineTo()

template<class T >
Profile & EBGeometry::Profile< T >::lineTo ( const Vec2T< T > &  a_point)

Draws a straight edge.

Parameters
[in]a_pointWhere it ends; finite, and not where the outline is now.
Returns
This outline.

◆ quadTo()

template<class T >
Profile & EBGeometry::Profile< T >::quadTo ( const Vec2T< T > &  a_control,
const Vec2T< T > &  a_point 
)

Draws a quadratic Bezier curve. One whose control point lies on the line between its ends, halfway, is a straight edge, and drawn as one.

Parameters
[in]a_controlIts control point; finite.
[in]a_pointWhere it ends; finite, and not where the outline is now.
Returns
This outline.

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