Add unit tests and fix bugs for geometry #196
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Note regarding failed build checks
Running
skunit_tests
will produce two failed test cases. The errors occur due topoint_point_distance
returning a float, reducing its precision. This bug is fixed in the following pull request: #195.Description
There are currently only a handful of unit tests covering geometry methods. A comprehensive set of tests have been added which cover all geometry methods in
circle_geometry
,geometry
,line_geometry
,point_geometry
,quad_geometry
,rectangle_geometry
, andtriangle_geometry
; with the exception of those which rely on a window. In the process of creating the tests, I discovered multiple bugs and ambiguous documentation which have been also been rectified.Point Method Type Changes
point_in_triangle
usesfloat
for its intermediary calculations. This leads to a loss of precision asdot_product
operates atdouble
precision. Allfloats
have been changed todouble
.Circle Methods Ambiguous Description
If
closest_point_on_circle
is called whenfrom_pt
is equal toc
's center position, thenc
's center is returned. This is not made clear in the documentation which only mentionsc
's circumference. This edge case has been added to the description.closest_point_on_rect_from_circle
strictly returns points on the rectangle's perimeter, even if the rectangle encases the circle. This is not made clear in the description so it has been updated to reduce ambiguity.Tangent Points Bug Fix.
A bug in
tangent_points
was producing tangent points on the far side of the circle relative to thefrom_pt
. This bug has been rectified and now works as intended. I added a real-time graphical test insktest
's geometry suite to more easily appreciate how the function operates.Rectangle Type Changes
rectangle_top
,rectangle_bottom
,rectangle_left
, andrectangle_right
returnfloat
when the underlying type isdouble
. This results in a loss of precision. The functions now returndouble
.Triangle-Rectangle Intersect Test
I added a real-time graphical test to
sktest
's geometry suite to check the operation oftriangle_rectangle_intersect
. The function works as intended without any need for changes.Set Quad Point Bug Fix
set_quad_point
incorrectly checks whetheridx
is between the bounds of 0 and 3 and does not allow for points to be altered. The bug has been fixed.Type of change
expected)
How Has This Been Tested?
Adding the new tests was achieved by running
cmake -G "Unix Makefiles" .
followed bymake
when in the/splashkit-core/projects/cmake
directory.Testing Checklist
Checklist