From 81c980e95641550f6fd5a58ce6bcd0a2bf50b9e9 Mon Sep 17 00:00:00 2001 From: ketmar Date: Tue, 30 Nov 2021 00:43:45 +0000 Subject: [PATCH] egra: agg mini cosmetix FossilOrigin-Name: a38cd09177ed48114cc50d6be886597ab6664eab17c00d4188a2615c0c3e1b08 --- egra/gfx/aggmini/core.d | 13 ++---- egra/gfx/aggmini/stroker.d | 27 +++-------- egra/gfx/aggmini/supmath.d | 111 +++++++++++++++++++++------------------------ 3 files changed, 63 insertions(+), 88 deletions(-) diff --git a/egra/gfx/aggmini/core.d b/egra/gfx/aggmini/core.d index b235801..69ddc1a 100644 --- a/egra/gfx/aggmini/core.d +++ b/egra/gfx/aggmini/core.d @@ -446,7 +446,7 @@ public: if (isLineTo(cmd)) { rast.lineTo(x, y); continue; } //if (isEndPoly(cmd)) {} } - vs.reset(); + vs.removeAll(); return this; } @@ -465,7 +465,7 @@ public: vtxcount = drw.vtxcount; } - void reset () { + void removeAll () { vidx = 0; sendClose = 0; } @@ -583,11 +583,6 @@ public: flushdg = aflushdg; } - void reset () { - vs.reset(); - removeAll(); - } - // Generator interface void removeAll () { vs.removeAll(); @@ -628,7 +623,7 @@ public: } private ref AGGDrawer convertPathToPath(VS0, VS1) (ref VS0 vsrc, ref VS1 vdest) { - vdest.reset(); + vdest.removeAll(); float x = 0.0f, y = 0.0f; vsrc.rewind(); bool wasStop = false; @@ -640,7 +635,7 @@ public: if (isStop(cmd)) { wasStop = true; break; } } if (!wasStop) vdest.addVertex(x, y, PathCommand.Stop); - vsrc.reset(); + vsrc.removeAll(); return this; } diff --git a/egra/gfx/aggmini/stroker.d b/egra/gfx/aggmini/stroker.d index 7a8e899..e71f078 100644 --- a/egra/gfx/aggmini/stroker.d +++ b/egra/gfx/aggmini/stroker.d @@ -446,19 +446,14 @@ public: @property void shorten (float s) { pragma(inline, true); mShorten = s; } @property float shorten () const pure { pragma(inline, true); return mShorten; } - void reset () { - removeAll(); - mOutVertices.removeAll(); - mOutVertex = 0; - mStatus = mPrevStatus = State.Initial; - } - // Generator interface void removeAll () { mSrcVertices.removeAll(); mSrcVertex = 0; + mOutVertices.removeAll(); + mOutVertex = 0; mClosed = 0; - mStatus = State.Initial; + mStatus = mPrevStatus = State.Initial; } void addVertex (float x, float y, uint cmd) { @@ -635,16 +630,12 @@ public: @property void autoDetectOrientation (bool v) { pragma(inline, true); mAutoDetect = v; } @property bool autoDetectOrientation () const pure { pragma(inline, true); return mAutoDetect; } - void reset () { - removeAll(); - mOutVertices.removeAll(); - mOutVertex = 0; - } - // Generator interface void removeAll () { mSrcVertices.removeAll(); mSrcVertex = 0; + mOutVertices.removeAll(); + mOutVertex = 0; mClosed = 0; mOrientation = 0; mStatus = State.Initial; @@ -793,18 +784,14 @@ public: calcDashStart(fabsf(ds)); } - void reset () { - removeAll(); - calcDashStart(mDashStart); - mCurrRest = 0; - } - // Vertex Generator Interface void removeAll () { mStatus = State.Initial; mSrcVertices.removeAll(); mSrcVertex = 0; mClosed = 0; + calcDashStart(mDashStart); + mCurrRest = 0; } void addVertex (float x, float y, uint cmd) { diff --git a/egra/gfx/aggmini/supmath.d b/egra/gfx/aggmini/supmath.d index 018f04c..8262377 100644 --- a/egra/gfx/aggmini/supmath.d +++ b/egra/gfx/aggmini/supmath.d @@ -49,7 +49,7 @@ package(iv.egra.gfx.aggmini): nothrow @trusted @nogc: //enum PI = 3.14159265358979323846; -//enum DBL_PI = cast(double)(0x1.921fb54442d18p+1); +enum DBL_PI = cast(double)(0x1.921fb54442d18p+1); enum FLT_PI = cast(float)(0x1.921fb54442d18p+1); enum DEG2RAD_MULT_D = cast(double)(0x1.1df46a2529d39p-6); @@ -58,6 +58,8 @@ enum RAD2DEG_MULT_D = cast(double)(0x1.ca5dc1a63c1f8p+5); enum DEG2RAD_MULT_F = cast(float)(0x1.1df46ap-6f); enum RAD2DEG_MULT_F = cast(float)(0x1.ca5dc2p+5f); + +// ////////////////////////////////////////////////////////////////////////// // //float deg2rad (in float deg) pure nothrow @safe @nogc { pragma(inline, true); return deg*cast(float)(PI/180.0f); } //float rad2deg (in float rad) pure nothrow @safe @nogc { pragma(inline, true); return rad*cast(float)(180.0f/PI); } public T deg2rad(T) (in T deg) if (__traits(isFloating, T) && (T.sizeof == 4 || T.sizeof == 8)) { @@ -79,51 +81,6 @@ public T rad2deg(T) (in T rad) if (__traits(isFloating, T) && (T.sizeof == 4 || } -float calcPolygonArea(Storage) (in ref Storage st) { - float sum = 0; - float x = st[0].x; - float y = st[0].y; - float xs = x; - float ys = y; - foreach (immutable uint i; 1..st.length) { - auto v = &st[i]; - sum += x*v.y-y*v.x; - x = v.x; - y = v.y; - } - return (sum+x*ys-y*xs)*0.5f; -} - - -void shortenPath(VertexSequence) (ref VertexSequence vs, float s, in uint closed=0) { - alias VertexType = VertexSequence.ValueType; - if (s > 0.0f && vs.length > 1) { - int n = cast(int)(vs.length-2); - while (n) { - immutable float d = vs[n].dist; - if (d > s) break; - vs.removeLast(); - s -= d; - --n; - } - if (vs.length < 2) { - vs.removeAll(); - } else { - n = vs.length-1; - VertexType* prev = &vs[n-1]; - VertexType* last = &vs[n]; - immutable float d = (prev.dist-s)/prev.dist; - immutable float x = prev.x+(last.x-prev.x)*d; - immutable float y = prev.y+(last.y-prev.y)*d; - last.x = x; - last.y = y; - if (!(*prev)(*last)) vs.removeLast(); - vs.close(closed != 0); - } - } -} - - // ////////////////////////////////////////////////////////////////////////// // // Vertex (x, y) with the distance to the next one. The last vertex has // distance between the last and the first points if the polygon is closed @@ -137,8 +94,8 @@ public nothrow @trusted @nogc: this (in float ax, in float ay) pure { x = ax; y = ay; /*dist = 0.0f;*/ } bool opCall() (in auto ref VertexDist val) { - //enum VertexDistEPS = cast(double)1e-14; // Coinciding points maximal distance (Epsilon) - enum VertexDistEPS = cast(float)0.00001f; // Coinciding points maximal distance (Epsilon) + //enum VertexDistEPS = cast(double)1e-14; // coinciding points maximal distance (epsilon) + enum VertexDistEPS = cast(float)0.00001f; // coinciding points maximal distance (epsilon) immutable bool ret = (dist = distance(x, y, val.x, val.y)) > VertexDistEPS; if (!ret) dist = 1.0f/VertexDistEPS; return ret; @@ -150,9 +107,11 @@ public nothrow @trusted @nogc: struct SimpleVector(T) { public nothrow @trusted @nogc: alias ValueType = T; +private: T* pvec; uint pvecAllot, pvecSize; +public: mixin(DisableCopyingMixin); ~this () { @@ -183,13 +142,13 @@ public nothrow @trusted @nogc: void add() (in auto ref T val) { import core.stdc.stdlib : realloc; import core.stdc.string : memcpy; - if (pvecSize+1 > pvecAllot) { + if (pvecSize == pvecAllot) { uint newsz = (pvecAllot|0xff)+1; pvec = cast(T*)realloc(pvec, T.sizeof*newsz); if (pvec is null) assert(0, "out of memory"); pvecAllot = newsz; + assert(pvecSize < pvecAllot); } - assert(pvecSize < pvecAllot); memcpy(pvec+pvecSize, &val, T.sizeof); ++pvecSize; } @@ -203,6 +162,7 @@ public nothrow @trusted @nogc: alias me this; alias ValueType = T; +public: mixin(DisableCopyingMixin); void add() (in auto ref T val) { @@ -236,15 +196,48 @@ public nothrow @trusted @nogc: // ////////////////////////////////////////////////////////////////////////// // -// process vertex source [src] with generator [dest] -void feedWith(VSD, VSS) (ref VSD dest, ref VSS src) { - dest.removeAll(); - src.rewind(); - float x, y; - for (;;) { - immutable cmd = src.vertex(&x, &y); - dest.addVertex(x, y, cmd); - if (isStop(cmd)) break; +float calcPolygonArea(Storage) (in ref Storage st) { + float sum = 0; + float x = st[0].x; + float y = st[0].y; + float xs = x; + float ys = y; + foreach (immutable uint i; 1..st.length) { + auto v = &st[i]; + sum += x*v.y-y*v.x; + x = v.x; + y = v.y; + } + return (sum+x*ys-y*xs)*0.5f; +} + + +// ////////////////////////////////////////////////////////////////////////// // +void shortenPath(VertexSequence) (ref VertexSequence vs, float s, in uint closed=0) { + alias VertexType = VertexSequence.ValueType; + if (s > 0.0f && vs.length > 1) { + int n = cast(int)(vs.length-2); + while (n) { + immutable float d = vs[n].dist; + if (d > s) break; + vs.removeLast(); + s -= d; + --n; + } + if (vs.length < 2) { + vs.removeAll(); + } else { + n = vs.length-1; + VertexType* prev = &vs[n-1]; + VertexType* last = &vs[n]; + immutable float d = (prev.dist-s)/prev.dist; + immutable float x = prev.x+(last.x-prev.x)*d; + immutable float y = prev.y+(last.y-prev.y)*d; + last.x = x; + last.y = y; + if (!(*prev)(*last)) vs.removeLast(); + vs.close(closed != 0); + } } } -- 2.11.4.GIT