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

gm: add geometric calculation functions #218

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

suleyman-kaya
Copy link
Contributor

@suleyman-kaya suleyman-kaya commented Aug 22, 2024

This PR adds several geometric calculation functions to the gm module. These functions implement common geometric theorems and calculations, enhancing the module's capabilities for triangle-related computations.

New functions added:

  1. Pythagorean Theorem:
// pythagorean_theorem calculates the length of the hypotenuse given the lengths of the other two sides
pub fn pythagorean_theorem(a f64, b f64) f64 {
    return math.sqrt(a * a + b * b)
}
  1. Euclidean Theorem:
// euclidean_theorem calculates the lengths of segments created by the altitude to the hypotenuse
pub fn euclidean_theorem(a f64, b f64, c f64) (f64, f64) {
    h := (a * b) / c
    p := (h * h) / a
    q := (h * h) / b
    return p, q
}
  1. Triangle Area using Sine:
// triangle_area_sine calculates the area of a triangle given two sides and the angle between them
pub fn triangle_area_sine(a f64, b f64, angle_rad f64) f64 {
    return 0.5 * a * b * math.sin(angle_rad)
}
  1. Finding absent length of a triangle using Cosine:
// triangle_missing_side calculates the length of the missing side of a triangle
// given two sides and the angle between them
pub fn triangle_missing_side(a f64, b f64, angle_rad f64) f64 {
    return math.sqrt(a * a + b * b - 2 * a * b * math.cos(angle_rad))
}
  1. Triangle Area from Points:
// triangle_area_from_points calculates the area of a triangle given its three vertices
pub fn triangle_area_from_points(p1 &Point, p2 &Point, p3 &Point) f64 {
    a := dist_point_point(p1, p2)
    b := dist_point_point(p2, p3)
    c := dist_point_point(p3, p1)
    s := (a + b + c) / 2  // semi-perimeter
    return math.sqrt(s * (s - a) * (s - b) * (s - c))
}

These functions provide implementations for common geometric calculations, expanding the functionality of the gm module. They utilize existing structures and functions where applicable, such as the Point struct and dist_point_point function.

Important Note:
Currently, there is no test file for this module. Due to time constraints, I haven't been able to create a comprehensive test suite for these new functions. I acknowledge the importance of testing and commit to writing proper tests as soon as my schedule allows. I will submit a follow-up commit with a complete test file, ensuring all tests pass before merging.
This current PR is to get early feedback on the implementations while I work on the test suite.

In the meantime, I've manually verified the functions' basic functionality, but a thorough test suite is pending. I appreciate your understanding and will prioritize creating the tests at my earliest convenience.

Summary by CodeRabbit

  • New Features
    • Introduced new functions for advanced geometric computations, including calculations for triangle area, hypotenuse length, and segments created by altitudes.
    • Enhanced the module's capabilities to support comprehensive geometric analysis for users.

…gle area calculation, and length of missing side of a triangle calculation
Copy link

coderabbitai bot commented Aug 22, 2024

Walkthrough

The changes introduce multiple public functions in the gm/basicgm.v file, enhancing the module's geometric computation capabilities. The new functions cover various aspects of triangle geometry, including calculating areas, hypotenuses, and segment lengths using established mathematical theorems.

Changes

Files Change Summary
gm/basicgm.v Added five public functions: pythagorean_theorem, euclidean_theorem, triangle_area_sine, triangle_missing_side, and triangle_area_from_points for geometric calculations.

Poem

In the meadow where numbers play,
A triangle danced in a bright array.
With sides to measure and angles to gleam,
New functions have come, like a dream!
Hop, skip, and calculate, oh what fun,
Geometry's magic has only begun! 🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between bdb5c39 and bf4d41b.

Files selected for processing (1)
  • gm/basicgm.v (1 hunks)
Additional comments not posted (5)
gm/basicgm.v (5)

167-170: LGTM!

The pythagorean_theorem function correctly implements the Pythagorean theorem to calculate the hypotenuse.


172-178: LGTM!

The euclidean_theorem function correctly calculates the lengths of segments created by the altitude to the hypotenuse.


180-183: LGTM!

The triangle_area_sine function correctly calculates the area of a triangle using the sine formula.


185-189: LGTM!

The triangle_missing_side function correctly implements the law of cosines to calculate the missing side of a triangle.


191-197: LGTM!

The triangle_area_from_points function correctly calculates the area of a triangle using Heron's formula.

@suleyman-kaya
Copy link
Contributor Author

@ulises-jeremias

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