Skip to content

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

Copy link
Contributor

@omckeon omckeon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@matt439 I've updated some of the unit tests that were failing (such as the line_intersects_rect call that was aiming to be true when the line didn't actually intersect with the rectangle border, which is what the function is checking). :)

@omckeon omckeon merged commit f72a893 into splashkit:develop Feb 25, 2025
3 checks passed
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.

2 participants