11#ifndef JAU_GAMP_GRAPH_OUTLINESHAPE_HPP_
12#define JAU_GAMP_GRAPH_OUTLINESHAPE_HPP_
27 using namespace jau::math;
28 using namespace jau::math::geom;
29 using namespace jau::enums;
30 using jau::math::geom::plane::AffineTransform;
128 mutable bool m_complexShape;
138 : m_outlineVertCapacity(capacity),
140 m_outlines(m_outlineVertCapacity),
143 m_addedVertexCount(0),
144 m_complexShape(false),
148 m_outlines.emplace_back(outlineVertCapacity);
153 constexpr const Vec3f&
normal() const noexcept {
return m_normal; }
165 constexpr float sharpness() const noexcept {
return m_sharpness; }
169 if( m_sharpness != s ) {
178 m_outlines.emplace_back(m_outlineVertCapacity);
183 m_addedVertexCount = 0;
184 m_complexShape =
false;
203 void validateBoundingBox() const noexcept {
206 for (
const auto & m_outline : m_outlines) {
207 m_bbox.
resize(m_outline.bounds());
214 validateBoundingBox();
219 bool empty() const noexcept {
return m_outlines.empty(); }
223 return m_outlines.size();
229 for(
const Outline& o : m_outlines) {
230 res += o.vertexCount();
247 return m_outlines[m_outlines.size()-1];
255 return m_outlines[m_outlines.size()-1];
288 m_complexShape =
false;
290 for(
size_type i=0; i<sz && !m_complexShape; ++i) {
295 return m_complexShape;
327 m_outlines.emplace_back(m_outlineVertCapacity);
358 if( m_outlines.size() == position ) {
364 m_outlines[position-1] =
outline;
366 m_bbox.resize(
outline.bounds());
373 m_outlines.insert(position,
outline);
375 m_bbox.resize(
outline.bounds());
405 m_outlines.insert(position,
outline);
418 m_outlines.erase(position);
434 m_bbox.resize(v.
coord());
451 m_bbox.resize(v.
coord());
466 void addVertex(
float x,
float y,
float z,
bool onCurve) {
565 void quadTo(
float x1,
float y1,
float z1,
float x2,
float y2,
float z2) {
586 void cubicTo(
float x1,
float y1,
float z1,
float x2,
float y2,
float z2,
float x3,
float y3,
float z3) {
643 return newOutlineShape;
652 for(
Vertex& v : o.vertices()) {
653 v.coord().z = ( v.coord().z * -1.0f ) + zoffset;
666 const float otherSize = other.bounds().size();
669 }
else if(thisSize < otherSize){
689 if(
bounds() != o.bounds() ) {
693 if(
outline(i) != o.outline(i) ) {
716 void checkOverlaps();
718 void cleanupOutlines();
719 uint32_t generateVertexIds();
727 void triangulateImpl();
757 std::string r(
"OutlineShape[");
758 r.append(
"dirty ").append(
to_string(m_dirtyBits))
759 .append(
", outlines ").append(std::to_string(
outlineCount()))
760 .append(
", vertices ").append(std::to_string(
vertexCount()))
constexpr size_type addedVertexCount() const noexcept
Return the number of newly added vertices during getTriangles(VerticesState) while transforming the o...
const VertexList & getVertices()
Return list of concatenated vertices associated with all Outlines of this object.
size_type outlineCount() const noexcept
Returns the number of Outlines.
JAU_MAKE_BITFIELD_ENUM_STRING_MEMBER(DirtyBits, bounds, vertices, triangles, convex, convexOverride)
void addVertex(size_type position, float x, float y, float z, bool onCurve)
Add a 3D Vertex to the last open outline to the shape at position.
void addVertex(float x, float y, float z, bool onCurve)
Add a 3D Vertex to the last open outline to the shape's tail.
const AABBox3f & bounds() const noexcept
void setSharpness(float s) noexcept
Sets sharpness, defaults to DEFAULT_SHARPNESS.
void clearCache() noexcept
Clears cached triangulated data, i.e.
static constexpr size_type max_elements
byte-size uint32_t limit: 1'073'741'823 (FIXME: Adjust to actual type, i.e. Vertex = 2x Vec3f?...
VertexState outlineState() const noexcept
void setOverrideConvex(bool convex) noexcept
Overrides isComplex() using the given value instead of computing via Outline#isComplex().
bool isComplex() const noexcept
Returns cached or computed result if at least one polyline outline(size_type) is a complex shape,...
int compareTo(const OutlineShape &other) const noexcept
Compare two outline shape's Bounding Box size.
OutlineList & outlines() noexcept
Winding windingOfLastOutline() const noexcept
Compute the Winding of the getLastOutline() using the VectorUtil#area(ArrayList) function over all of...
@ triangles
<Modified shape, requires to update the vertices and triangles, here: vertices
@ convexOverride
<Modified shape, requires to update the convex determination
@ convex
<Modified shape, requires to update the vertices and triangles, here: triangulation.
JAU_MAKE_ENUM_STRING_MEMBER(VertexState, quadratic_nurbs)
void cubicTo(float x1, float y1, float z1, float x2, float y2, float z2, float x3, float y3, float z3)
Add a cubic Bézier curve segment, intersecting the last point and the second given point x3/y3 (P3).
void removeOutline(size_type position)
Removes the Outline element at the given position.
void addVertex(float x, float y, bool onCurve)
Add a 2D Vertex to the last open outline to the shape's tail.
const Outline & lastOutline() const noexcept
Get the last added outline to the list of outlines that define the shape.
const OutlineList & outlines() const noexcept
void addVertex(const Vec2f &v, bool onCurve)
Add a 2D Vertex to the last open outline to the shape's tail.
size_type vertexCount() const noexcept
Returns the total vertex number of all Outlines.
const Outline & outline(size_type i) const noexcept
std::string toString() const noexcept
void addVertex(const Vec3f &v, bool onCurve)
Add a 3D Vertex to the last open outline to the shape's tail.
constexpr Vec3f & normal() noexcept
Writing the normal vector, optionally used by tesselator to add (interleaved) normals.
void closeLastOutline(bool closeTail)
Closes the last outline in the shape.
OutlineShape(size_type capacity, size_type outlineVertCapacity)
constexpr bool verticesDirty() const noexcept
void addOutline(size_type position, const Outline &outline)
Insert the Outline element at the given position.
void setWindingOfLastOutline(Winding enforced)
Sets the enforced Winding of the getLastOutline().
constexpr void reserve(size_type newCapacity)
void setIsQuadraticNurbs() noexcept
Claim this outline's vertices are all VertexState::quadratic_nurbs, hence no cubic transformations wi...
constexpr bool operator==(const OutlineShape &o) const noexcept
void clear()
Clears all data and reset all states as if this instance was newly created.
bool empty() const noexcept
void quadTo(float x1, float y1, float z1, float x2, float y2, float z2)
Add a quadratic curve segment, intersecting the last point and the second given point x2/y2 (P2).
void markClean(DirtyBits flags) noexcept
void addOutlineShape(const OutlineShape &outlineShape)
Insert the OutlineShape elements of type Outline, .
constexpr const Vec3f & normal() const noexcept
Normal vector, optionally used by tesselator to add (interleaved) normals.
void moveTo(float x, float y, float z)
Start a new position for the next line segment at given point x/y (P1).
void clearOverrideConvex() noexcept
Clears the isComplex() override done by setOverrideConvex(boolean).
void closePath()
Closes the current sub-path segment by drawing a straight line back to the coordinates of the last mo...
void addVertex(size_type position, const Vertex &v)
Adds a vertex to the last open outline to the shape at position @endiliteral.
static constexpr float DEFAULT_SHARPNESS
Initial sharpness() value, which can be modified via setSharpness(float).
const TriangleRefList & getTriangles(VertexState destinationType=VertexState::quadratic_nurbs)
Triangulate the OutlineShape generating a list of triangles, while transformOutlines(VerticesState) b...
constexpr float sharpness() const noexcept
Sharpness value, defaults to DEFAULT_SHARPNESS.
constexpr bool trianglesDirty() const noexcept
Outline & lastOutline() noexcept
Get the last added outline to the list of outlines that define the shape.
OutlineShape transform(const AffineTransform &t) const
Return a transformed instance with all Outlines are copied and transformed.
Outline & outline(size_type i) noexcept
OutlineShape flipFace(float zoffset=0) const
Returns a copy of this instance with normal() and all outlines() vertices()'s z-axis sign-flipped,...
void lineTo(float x, float y, float z)
Add a line segment, intersecting the last point and the given point x/y (P1).
void addEmptyOutline()
Add a new empty Outline to the end of this shape's outline list.
void setOutline(size_type position, const Outline &outline)
Replaces the Outline element at the given position.
void addOutline(const Outline &outline)
Appends the Outline element to the end, ensuring a clean tail.
void addVertex(const Vertex &v)
Adds a vertex to the last open outline to the shape's tail.
constexpr DirtyBits dirtyBits() const noexcept
Define a single continuous stroke by control vertices.
void addVertex(const Vertex &vertex)
Appends a vertex to the outline loop/strip.
bool isComplex() const noexcept
Returns cached or computed result if whether this Outlines polyline is a complex shape.
constexpr bool empty() const noexcept
void setWinding(Winding enforce)
Sets Winding to this outline.
Winding getWinding() const noexcept
Returns the cached or computed winding of this Outlines polyline using VectorUtil#area(ArrayList).
constexpr const Vec3f & coord() const noexcept
Axis Aligned Bounding Box.
constexpr AABBox3f & reset() noexcept
Reset this box to the inverse low/high, allowing the next resize(float, float, float) command to hit.
constexpr float size() const noexcept
Get the size of this aabbox3f where the size is represented by the length of the vector between low a...
AABBox3f & resize(const AABBox3f &o) noexcept
Resize the aabbox3f to encapsulate another AABox.
constexpr bool is_set(const E mask, const E bits) noexcept
constexpr bool equals2(const T &a, const T &b, const T &epsilon=std::numeric_limits< T >::epsilon()) noexcept
Returns true if both values are equal, i.e.
jau::darray< Vertex, uint32_t > VertexList
jau::darray< Outline, uint32_t > OutlineList
jau::darray< TriangleRef, uint32_t > TriangleRefList
std::string to_string(const math_error_t v) noexcept
Returns std::string representation of math_error_t.