* Changed the profile of the line draw procedure

This commit is contained in:
Vovanium 2023-01-19 00:50:39 +03:00
parent 5d3c912cd0
commit 0b61b7a60b
2 changed files with 22 additions and 14 deletions

View file

@ -2,42 +2,46 @@ with Video.Integer_Geometry;
use type Video.Integer_Geometry.Point;
procedure Video.Algorithms.Generic_Line (
A, B : in Integer_Geometry.Point;
Offset : in Integer := 0)
A, B : in Integer_Geometry.Point;
A_Clip, B_Clip : in Integer_Geometry.Point)
is
D : constant Integer_Geometry.Point := B - A;
D : constant Integer_Geometry.Point := B - A; -- Direction vector
S : constant Integer_Geometry.Point := (
X => (if D.X >= 0 then 1 else -1),
Y => (if D.Y >= 0 then 1 else -1));
N, M : Integer;
Y => (if D.Y >= 0 then 1 else -1)); -- Signs of directions
N, M : Integer; -- Denominator and numerator
NC : Integer; -- Number of steps
E : Integer;
P : Integer_Geometry.Point := A;
P : Integer_Geometry.Point := A_Clip;
begin
if abs D.X > abs D.Y then -- Nearly horizontal
N := abs D.X;
M := abs D.Y;
E := -N / 2 + Offset;
for I in 1 .. N loop
E := -N / 2 + M * abs (A_Clip.X - A.X) - N * abs (A_Clip.Y - A.Y);
-- May need extended precision here
NC := abs (B_Clip.X - A_Clip.X);
for I in 0 .. NC loop
Put_Pixel (P);
E := E + M;
if E >= 0 then
E := E - N;
P.Y := P.Y + S.Y;
end if;
P.X := P.X + S.X;
Put_Pixel (P);
end loop;
else -- Nearly vertical
N := abs D.Y;
M := abs D.X;
E := -N / 2 + Offset;
for I in 1 .. N loop
E := -N / 2 + M * abs (A_Clip.Y - A.Y) - N * abs (A_Clip.X - A.X);
NC := abs (B_Clip.Y - A_Clip.Y);
for I in 0 .. NC loop
Put_Pixel (P);
E := E + M;
if E >= 0 then
E := E - N;
P.X := P.X + S.X;
end if;
P.Y := P.Y + S.Y;
Put_Pixel (P);
end loop;
end if;

View file

@ -2,5 +2,9 @@ with Video.Integer_Geometry;
generic
with procedure Put_Pixel (Location : Integer_Geometry.Point);
procedure Video.Algorithms.Generic_Line (
A, B : in Integer_Geometry.Point;
Offset : in Integer := 0);
A, B : in Integer_Geometry.Point; -- Virtual line ends (possibly out of clip area)
A_Clip, B_Clip : in Integer_Geometry.Point); -- Actual first and last points to draw
-- A_Clip and B_Clip could be the same as A and B when no clipping is done
-- A_Clip is the closest to A and B_Clip is the closest to B to draw.
-- If order is not met algorighm could refuse to draw