Skip to content

Commit

Permalink
Fix from Alex for issue theproadam#5
Browse files Browse the repository at this point in the history
  • Loading branch information
kf6kjg committed Aug 2, 2021
1 parent d4a9ea1 commit b23cae8
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 41 deletions.
75 changes: 45 additions & 30 deletions source/renderxf/GeometryPath/GeometryPath.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
Expand Down Expand Up @@ -471,7 +471,7 @@ unsafe bool ScanLineDATA(int Line, float* TRIS_DATA, int TRIS_SIZE, float* Inter
else return false;
}

const float SCANLINE_EPSILON = 1E-2f;
const float SCANLINE_EPSILON = 1E-3f;
bool BiggerOrEqual(float Value, float Line)
{
if (Value > Line) return true;
Expand Down Expand Up @@ -543,42 +543,57 @@ unsafe bool ScanLinePLUS_OLD(int Line, float* TRIS_DATA, int TRIS_SIZE, float* I
unsafe bool ScanLinePLUS(int Line, float* TRIS_DATA, int TRIS_SIZE, float* Intersects)
{
int IC = 0;
for (int i = 0; i < TRIS_SIZE; i++)
for (int i = 0; i < TRIS_SIZE - 1; i++)
{
if (TRIS_DATA[i * Stride + 1] <= Line)
{
if (i == 0 && BiggerOrEqual(TRIS_DATA[(TRIS_SIZE - 1) * Stride + 1], Line))
{
LIPA_PLUS(Intersects, IC, TRIS_DATA, TRIS_SIZE - 1, i, Line);
IC++;
float y1 = TRIS_DATA[i * Stride + 1];
float y2 = TRIS_DATA[(i + 1) * Stride + 1];

if (IC >= 2) break;
}
else if (i > 0 && BiggerOrEqual(TRIS_DATA[(i - 1) * Stride + 1], Line))
{
LIPA_PLUS(Intersects, IC, TRIS_DATA, i - 1, i, Line);
IC++;
if (y2 == y1 && Line == y2)
{
LIPA_PLUS(Intersects, 0, TRIS_DATA, i, i + 1, Line);
LIPA_PLUS(Intersects, 1, TRIS_DATA, i + 1, i, Line);
return true;
}

if (IC >= 2) break;
}
if (y2 < y1)
{
float t = y2;
y2 = y1;
y1 = t;
}
else if (TRIS_DATA[i * Stride + 1] > Line)

if (Line <= y2 && Line > y1)
{
if (i == 0 && SmallerOrEqual(TRIS_DATA[(TRIS_SIZE - 1) * Stride + 1], Line))
{
LIPA_PLUS(Intersects, IC, TRIS_DATA, TRIS_SIZE - 1, i, Line);
IC++;
LIPA_PLUS(Intersects, IC, TRIS_DATA, i, i + 1, Line);
IC++;
}

if (IC >= 2) break;
}
else if (i > 0 && SmallerOrEqual(TRIS_DATA[(i - 1) * Stride + 1], Line))
{
LIPA_PLUS(Intersects, IC, TRIS_DATA, i - 1, i, Line);
IC++;
if (IC >= 2) return true;
}

if (IC >= 2) break;
}
if (IC < 2)
{
float y1 = TRIS_DATA[0 * Stride + 1];
float y2 = TRIS_DATA[(TRIS_SIZE - 1) * Stride + 1];

if (y2 == y1 && Line == y2)
{
LIPA_PLUS(Intersects, 0, TRIS_DATA, 0, (TRIS_SIZE - 1), Line);
LIPA_PLUS(Intersects, 1, TRIS_DATA, (TRIS_SIZE - 1), 0, Line);
return true;
}

if (y2 < y1)
{
float t = y2;
y2 = y1;
y1 = t;
}

if (Line <= y2 && Line > y1)
{
LIPA_PLUS(Intersects, IC, TRIS_DATA, 0, TRIS_SIZE - 1, Line);
IC++;
}
}

Expand Down
21 changes: 10 additions & 11 deletions source/renderxf/GeometryPath/GeometryPath_Fill.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
Expand Down Expand Up @@ -3556,9 +3556,9 @@ public void FillFull(int index)
else if (matrixlerpv == 1)
for (int im = 0; im < BUFFER_SIZE; im++)
{
VERTEX_DATA[im * Stride + 0] = (rw + VERTEX_DATA[im * Stride + 0] * iox);
VERTEX_DATA[im * Stride + 1] = (rh + VERTEX_DATA[im * Stride + 1] * ioy);
VERTEX_DATA[im * Stride + 0] = roundf(rw + VERTEX_DATA[im * Stride + 0] * iox);
VERTEX_DATA[im * Stride + 1] = roundf(rh + VERTEX_DATA[im * Stride + 1] * ioy);

if (VERTEX_DATA[im * Stride + 1] > yMaxValue) yMaxValue = VERTEX_DATA[im * Stride + 1];
if (VERTEX_DATA[im * Stride + 1] < yMinValue) yMinValue = VERTEX_DATA[im * Stride + 1];
}
Expand Down Expand Up @@ -3634,18 +3634,17 @@ public void FillFull(int index)
TO = Intersects + (Stride - 1);
}

// FromX = (int)((int)FROM[0] == 0 ? 0 : FROM[0] + 1);
// ToX = (int)TO[0];
FROM[0] = roundf(FROM[0]);
TO[0] = roundf(TO[0]);

FromX = (int)FROM[0] == 0 ? 0 : (int)FROM[0] + 1;
ToX = (int)TO[0];

slopeZ = (FROM[1] - TO[1]) / (FROM[0] - TO[0]);
bZ = -slopeZ * FROM[0] + FROM[1];

FromX = (int)FROM[0];
ToX = (int)TO[0];

if (ToX >= renderWidth) TO[0] = renderWidth - 1;
if (FromX < 0) FROM[0] = 0;
if (ToX >= renderWidth) ToX = renderWidth - 1;
if (FromX < 0) FromX = 0;

float ZDIFF = 1f / FROM[1] - 1f / TO[1];
bool usingZ = ZDIFF != 0;
Expand Down

0 comments on commit b23cae8

Please sign in to comment.