-
Notifications
You must be signed in to change notification settings - Fork 0
Create MarinerGuidance.java #7
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,23 @@ | ||||||||||||||||||||||||||||||||||
| public class MarinerGuidance { | ||||||||||||||||||||||||||||||||||
| public static double getRawDerivative(double[] radius, int n) { | ||||||||||||||||||||||||||||||||||
| if (n == 0) return 0.0; | ||||||||||||||||||||||||||||||||||
| return radius[n] - radius[n - 1]; | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+2
to
+5
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add comprehensive bounds checking and null safety. The method lacks proper validation which could lead to runtime exceptions:
Apply this diff to add proper validation: public static double getRawDerivative(double[] radius, int n) {
+ if (radius == null) {
+ throw new IllegalArgumentException("Radius array cannot be null");
+ }
+ if (n < 0 || n >= radius.length) {
+ throw new IllegalArgumentException("Index n must be within array bounds: 0 <= n < " + radius.length);
+ }
if (n == 0) return 0.0;
return radius[n] - radius[n - 1];
}🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| public static double computeGuidance(double[] radius, int n) { | ||||||||||||||||||||||||||||||||||
| double rawDerivative = getRawDerivative(radius, n); | ||||||||||||||||||||||||||||||||||
| return someControlLaw(radius[n], rawDerivative); | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| public static double someControlLaw(double radius, double derivative) { | ||||||||||||||||||||||||||||||||||
| return -0.5 * radius + 2.0 * derivative; | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+12
to
+14
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Improve naming and eliminate magic numbers. The method has several maintainability issues:
Apply this diff to improve clarity and maintainability: +// Control gains for the linear guidance law
+private static final double RADIUS_GAIN = -0.5;
+private static final double DERIVATIVE_GAIN = 2.0;
+
-public static double someControlLaw(double radius, double derivative) {
- return -0.5 * radius + 2.0 * derivative;
+/**
+ * Applies a linear control law for mariner guidance.
+ * @param radius current radius value
+ * @param derivative rate of change of radius
+ * @return guidance control output
+ */
+public static double applyLinearControlLaw(double radius, double derivative) {
+ return RADIUS_GAIN * radius + DERIVATIVE_GAIN * derivative;
}Don't forget to update the method call in 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| public static void main(String[] args) { | ||||||||||||||||||||||||||||||||||
| double[] radius = {100, 99.5, 99.2, 99.1, 100.5, 102.0, 98.0}; | ||||||||||||||||||||||||||||||||||
| for (int n = 1; n < radius.length; n++) { | ||||||||||||||||||||||||||||||||||
| double guidance = computeGuidance(radius, n); | ||||||||||||||||||||||||||||||||||
| System.out.printf("Step %d: Guidance = %.2f%n", n, guidance); | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Add comprehensive class documentation.
The class lacks documentation explaining its purpose and usage. Consider adding JavaDoc to improve maintainability and usability.
Apply this diff to add proper class documentation:
📝 Committable suggestion
🤖 Prompt for AI Agents