Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unit tests and fix bugs for geometry #196

Open
wants to merge 10 commits into
base: develop
Choose a base branch
from

Conversation

matt439
Copy link
Contributor

@matt439 matt439 commented Dec 13, 2024

Note regarding failed build checks

Running skunit_tests will produce two failed test cases. The errors occur due to point_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, and triangle_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 uses float for its intermediary calculations. This leads to a loss of precision as dot_product operates at double precision. All floats have been changed to double.

Circle Methods Ambiguous Description

If closest_point_on_circle is called when from_pt is equal to c's center position, then c's center is returned. This is not made clear in the documentation which only mentions c'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 the from_pt. This bug has been rectified and now works as intended. I added a real-time graphical test in sktest's geometry suite to more easily appreciate how the function operates.

Rectangle Type Changes

rectangle_top, rectangle_bottom, rectangle_left, and rectangle_right return float when the underlying type is double. This results in a loss of precision. The functions now return double.

Triangle-Rectangle Intersect Test

I added a real-time graphical test to sktest's geometry suite to check the operation of triangle_rectangle_intersect. The function works as intended without any need for changes.

Set Quad Point Bug Fix

set_quad_point incorrectly checks whether idx 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

  • Breaking change (fix or feature that would cause existing functionality to not work as
    expected)
  • Documentation (update or new)

How Has This Been Tested?

Adding the new tests was achieved by running cmake -G "Unix Makefiles" . followed by make when in the /splashkit-core/projects/cmake directory.

Testing Checklist

  • Tested with sktest
  • Tested with skunit_tests

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant