diff options
author | Lenny Maiorani <lenny@serenityos.org> | 2022-01-27 17:18:49 -0700 |
---|---|---|
committer | Idan Horowitz <idan.horowitz@gmail.com> | 2022-01-28 17:02:04 +0200 |
commit | 899f062673f5bc77bf9ec307c7b4d742326af37d (patch) | |
tree | fcfe22b6318378b44f6c291b943f94063e8e9317 /Userland/Libraries | |
parent | fa016a72fd8f0288de02f3aa8e7834b08b8f2238 (diff) | |
download | serenity-899f062673f5bc77bf9ec307c7b4d742326af37d.zip |
LibSoftGPU: Simplify clipping logic
The clipping logic is not DRY (Don't Repeat Yourself). The same logic
is repeated in multiple parts of an `if-else` statement. This can be
simplified to contain fewer branches and eliminate the redundant code.
Diffstat (limited to 'Userland/Libraries')
-rw-r--r-- | Userland/Libraries/LibSoftGPU/Clipper.cpp | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/Userland/Libraries/LibSoftGPU/Clipper.cpp b/Userland/Libraries/LibSoftGPU/Clipper.cpp index e46d79eedd..e5839b00b7 100644 --- a/Userland/Libraries/LibSoftGPU/Clipper.cpp +++ b/Userland/Libraries/LibSoftGPU/Clipper.cpp @@ -73,16 +73,15 @@ static void clip_plane(Vector<Vertex>& read_list, Vector<Vertex>& write_list, Cl auto const& curr_vec = read_from->at((i + 1) % read_from->size()); auto const& prev_vec = read_from->at(i); - if (point_within_clip_plane(curr_vec.clip_coordinates, plane)) { - if (!point_within_clip_plane(prev_vec.clip_coordinates, plane)) { - auto const intersect = clip_intersection_point(prev_vec, curr_vec, plane); - write_to->append(intersect); - } - write_to->append(curr_vec); - } else if (point_within_clip_plane(prev_vec.clip_coordinates, plane)) { + bool const is_curr_point_within_clip_plane = point_within_clip_plane(curr_vec.clip_coordinates, plane); + bool const is_prev_point_within_clip_plane = point_within_clip_plane(prev_vec.clip_coordinates, plane); + if (is_curr_point_within_clip_plane != is_prev_point_within_clip_plane) { auto const intersect = clip_intersection_point(prev_vec, curr_vec, plane); write_to->append(intersect); } + + if (is_curr_point_within_clip_plane) + write_to->append(curr_vec); } swap(write_list, read_list); } |