Skip to content

Commit 108bc3b

Browse files
memononenocornut
authored andcommitted
DrawList: added explanation for IM_POLYLINE_CONVEX_POLY_MAX_BEVELS.
1 parent a38ce24 commit 108bc3b

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

imgui_draw.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -886,9 +886,20 @@ IM_MSVC_RUNTIME_CHECKS_RESTORE
886886
#define IM_FIXNORMAL2F_MAX_INVLEN2 100.0f // 500.0f (see #4053, #3366)
887887
#define IM_FIXNORMAL2F(VX,VY) { float d2 = VX*VX + VY*VY; if (d2 > 0.000001f) { float inv_len2 = 1.0f / d2; if (inv_len2 > IM_FIXNORMAL2F_MAX_INVLEN2) inv_len2 = IM_FIXNORMAL2F_MAX_INVLEN2; VX *= inv_len2; VY *= inv_len2; } } (void)0
888888

889+
// - The miter limit describes how much the miter cross section can be scaled before we turn it into a bevel instead.
890+
// The minimum value of miter limit is 1.0, which translates to 180 (all corners are bevels), the higher the number,
891+
// the closer to zero the angle is (never bevel a corner). The miter limit angle can be calculated as:
892+
// miter_limit_angle = 2 * acos(1 / miter_limit)
893+
// - We can use the miter limit angle to figure maximum number of beveled corners in a convex polygon,
894+
// to prevent having allocate much extra memory (for a reasonable miter limit).
895+
// (n - 2) * 360 > k * miter_limit_angle + (n - k) * 360
896+
// Where, n = number of corners in a polygon, k = beveled corners. Solved for k, simplifies to:
897+
// k < 360 / (180 - miter_limit_angle)
898+
// To find value strictly less than:
899+
// max_bevels = k = floor(360/(180-miter_limit_angle))
889900
#define IM_POLYLINE_MITER_ANGLE_LIMIT (-0.9999619f) // Safeguard for miter corner calculation to avoid div by zero. cos(179.5)
890-
#define IM_POLYLINE_MITER_LIMIT (4.0f) // How much the miter can be scaled before we turn it into a bevel instead. (equals ~29 deg corner)
891-
#define IM_POLYLINE_CONVEX_POLY_MAX_BEVELS (2) // How many bevels there can be in a convex polygon. (int)(360/floor(180-29))
901+
#define IM_POLYLINE_MITER_LIMIT (4.0f) // (~29 deg corner)
902+
#define IM_POLYLINE_CONVEX_POLY_MAX_BEVELS (2) // For miter value 4.0
892903

893904
// In debug builds the functions are likely not inlined, so inlined check is cheaper.
894905
#if defined(DEBUG) || defined(_DEBUG)

0 commit comments

Comments
 (0)