From 0b61b7a60bf014c60261f50e581fcffbe8ba3d38 Mon Sep 17 00:00:00 2001 From: Vovanium Date: Thu, 19 Jan 2023 00:50:39 +0300 Subject: [PATCH] * Changed the profile of the line draw procedure --- source/video-algorithms-generic_line.adb | 28 ++++++++++++++---------- source/video-algorithms-generic_line.ads | 8 +++++-- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/source/video-algorithms-generic_line.adb b/source/video-algorithms-generic_line.adb index b511fd5..c41c089 100644 --- a/source/video-algorithms-generic_line.adb +++ b/source/video-algorithms-generic_line.adb @@ -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; diff --git a/source/video-algorithms-generic_line.ads b/source/video-algorithms-generic_line.ads index d4b8774..24894a9 100644 --- a/source/video-algorithms-generic_line.ads +++ b/source/video-algorithms-generic_line.ads @@ -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 \ No newline at end of file