diff --git a/implot.cpp b/implot.cpp index f97e08c..9e0ac12 100644 --- a/implot.cpp +++ b/implot.cpp @@ -827,8 +827,8 @@ ImPlotTime MkGmtTime(struct tm *ptm) { #else t.S = timegm(ptm); #endif - if (t.S < 0) - t.S = 0; + // if (t.S < 0) + // t.S = 0; return t; } @@ -847,8 +847,8 @@ tm* GetGmtTime(const ImPlotTime& t, tm* ptm) ImPlotTime MkLocTime(struct tm *ptm) { ImPlotTime t; t.S = mktime(ptm); - if (t.S < 0) - t.S = 0; + // if (t.S < 0) + // t.S = 0; return t; } @@ -881,8 +881,8 @@ ImPlotTime MakeTime(int year, int month, int day, int hour, int min, int sec, in tm& Tm = GImPlot->Tm; int yr = year - 1900; - if (yr < 0) - yr = 0; + // if (yr < 0) + // yr = 0; sec = sec + us / 1000000; us = us % 1000000; diff --git a/implot_internal.h b/implot_internal.h index 3c0d1d5..a345d8e 100644 --- a/implot_internal.h +++ b/implot_internal.h @@ -53,10 +53,10 @@ #define IMPLOT_Y_AXES 3 // Zoom rate for scroll (e.g. 0.1f = 10% plot range every scroll click) #define IMPLOT_ZOOM_RATE 0.1f -// Mimimum allowable timestamp value 01/01/1970 @ 12:00am (UTC) (DO NOT DECREASE THIS) -#define IMPLOT_MIN_TIME 0 -// Maximum allowable timestamp value 01/01/3000 @ 12:00am (UTC) (DO NOT INCREASE THIS) -#define IMPLOT_MAX_TIME 32503680000 +// Mimimum allowable timestamp value, default = 01/01/1900 @ 12:00am (UTC) +#define IMPLOT_MIN_TIME -2208988800.0 +// Maximum allowable timestamp value, default = 01/01/3000 @ 12:00am (UTC) +#define IMPLOT_MAX_TIME 32503680000.0 // Default label format for axis labels #define IMPLOT_LABEL_FMT "%g" @@ -92,6 +92,28 @@ extern IMPLOT_API ImPlotContext* GImPlot; // Current implicit context pointer // [SECTION] Generic Helpers //----------------------------------------------------------------------------- +// Numeric limits for integral types +template +struct ImNumericLimits { static const T Min; static const T Max; }; + +template <> const short ImNumericLimits::Min = SHRT_MIN; +template <> const short ImNumericLimits::Max = SHRT_MAX; +template <> const int ImNumericLimits::Min = INT_MIN; +template <> const int ImNumericLimits::Max = INT_MAX; +template <> const long ImNumericLimits::Min = LONG_MIN; +template <> const long ImNumericLimits::Max = LONG_MAX; +template <> const long long ImNumericLimits::Min = LLONG_MIN; +template <> const long long ImNumericLimits::Max = LLONG_MAX; + +template <> const unsigned short ImNumericLimits::Min = 0; +template <> const unsigned short ImNumericLimits::Max = USHRT_MAX; +template <> const unsigned int ImNumericLimits::Min = 0; +template <> const unsigned int ImNumericLimits::Max = UINT_MAX; +template <> const unsigned long ImNumericLimits::Min = 0; +template <> const unsigned long ImNumericLimits::Max = ULONG_MAX; +template <> const unsigned long long ImNumericLimits::Min = 0; +template <> const unsigned long long ImNumericLimits::Max = ULLONG_MAX; + // Computes the common (base-10) logarithm static inline float ImLog10(float x) { return log10f(x); } static inline double ImLog10(double x) { return log10(x); } diff --git a/implot_items.cpp b/implot_items.cpp index 9f94492..a9f460a 100644 --- a/implot_items.cpp +++ b/implot_items.cpp @@ -685,12 +685,6 @@ struct ShadedRenderer { static const int VtxConsumed = 5; }; -// Stupid way of calculating maximum index size of ImDrawIdx without integer overflow issues -template -struct MaxIdx { static const unsigned int Value; }; -template <> const unsigned int MaxIdx::Value = 65535; -template <> const unsigned int MaxIdx::Value = 4294967295; - /// Renders primitive shapes in bulk as efficiently as possible. template inline void RenderPrimitives(const Renderer& renderer, ImDrawList& DrawList, const ImRect& cull_rect) { @@ -700,7 +694,7 @@ inline void RenderPrimitives(const Renderer& renderer, ImDrawList& DrawList, con const ImVec2 uv = DrawList._Data->TexUvWhitePixel; while (prims) { // find how many can be reserved up to end of current draw command's limit - unsigned int cnt = ImMin(prims, (MaxIdx::Value - DrawList._VtxCurrentIdx) / Renderer::VtxConsumed); + unsigned int cnt = ImMin(prims, (ImNumericLimits::Max - DrawList._VtxCurrentIdx) / Renderer::VtxConsumed); // make sure at least this many elements can be rendered to avoid situations where at the end of buffer this slow path is not taken all the time if (cnt >= ImMin(64u, prims)) { if (prims_culled >= cnt) @@ -716,7 +710,7 @@ inline void RenderPrimitives(const Renderer& renderer, ImDrawList& DrawList, con DrawList.PrimUnreserve(prims_culled * Renderer::IdxConsumed, prims_culled * Renderer::VtxConsumed); prims_culled = 0; } - cnt = ImMin(prims, (MaxIdx::Value - 0/*DrawList._VtxCurrentIdx*/) / Renderer::VtxConsumed); + cnt = ImMin(prims, (ImNumericLimits::Max - 0/*DrawList._VtxCurrentIdx*/) / Renderer::VtxConsumed); DrawList.PrimReserve(cnt * Renderer::IdxConsumed, cnt * Renderer::VtxConsumed); // reserve new draw command } prims -= cnt;