-
Notifications
You must be signed in to change notification settings - Fork 0
Feat/ref distances #11
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?
Conversation
… and its implementation plan
…tionality for setting reference distances and measuring
…ion and interaction improvements
…s for centroid calculation
…ith weight influence
…tric properties and edge cases
…r improved accuracy
… null for coincident pixel points
…e over GPS calibration
… and unit selection
Summary of ChangesHello @cs-util, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces the foundational mathematical and calibration logic for a new 'Manual Reference Distance' feature. This feature will allow users to define a known distance on an image, enabling accurate measurements even without GPS data, and will integrate with existing GPS calibration by prioritizing manual input. The current changes complete the backend implementation, with UI/UX planned for a subsequent phase. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
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.
Code Review
This pull request implements the backend mathematical components for a new feature that allows users to define a reference distance on a map. This includes adding a new fitSimilarityFixedScale function to compute a similarity transform with a fixed scale and integrating it into the calibration pipeline. The changes are well-implemented and accompanied by a very comprehensive suite of unit tests. I've also reviewed the detailed design document for the feature.
My feedback is mainly on the design document (docs/feat-reference-distances.md), where I've identified a couple of logical issues in the proposed implementation details for helper functions. The core mathematical changes in the code are solid and look great.
| function getMetersPerPixelFromCalibration(calibrationResult) { | ||
| if (!calibrationResult || !calibrationResult.matrix) return null; | ||
| const { a, b } = calibrationResult.matrix; | ||
| const geoUnitsPerPixel = Math.sqrt(a * a + b * b); | ||
| // Convert degrees to meters (approximate, using center latitude) | ||
| // 1 degree ≈ 111,320 meters at equator, adjusted by cos(lat) | ||
| const centerLat = calibrationResult.centerLat || 0; | ||
| const metersPerDegree = 111320 * Math.cos(centerLat * Math.PI / 180); | ||
| return geoUnitsPerPixel * metersPerDegree; | ||
| } |
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.
The proposed implementation of getMetersPerPixelFromCalibration seems to be based on a misunderstanding of the data structure returned by calibrateMap.
- It accesses
calibrationResult.matrix, butcalibrateMapreturns amodelobject inside the result, so it should becalibrationResult.model. - For a
similaritytransform, themodelobject contains ascaleproperty directly. There is nomatrixproperty. The function should just usemodel.scale. - The code
const { a, b } = calibrationResult.matrix;andMath.sqrt(a * a + b * b)seems to assume a similarity matrix format[a, b, tx; -b, a, ty], but this is not whatfitSimilarityreturns. - For
affineandhomographytransforms, the scale is not uniform across the image. A single scale value can be approximated by calculating the Jacobian at a reference point (e.g., image center) and usingaverageScaleFromJacobian, but this function as written does not account for this.
I recommend redesigning this function to correctly handle the different model types returned by calibrateMap. For example:
function getMetersPerPixelFromCalibration(calibrationResult) {
if (!calibrationResult || !calibrationResult.model) return null;
const { model, origin } = calibrationResult;
let geoUnitsPerPixel;
if (model.type === 'similarity') {
geoUnitsPerPixel = model.scale;
} else {
// For non-uniform scales, we need a reference point.
// The center of the image is a reasonable default, but image dimensions are not available here.
// An alternative is to use the centroid of the pixel pairs, which would need to be passed in or stored.
// For now, let's use {x: 0, y: 0} as a placeholder reference.
const jacobian = jacobianForTransform(model, { x: 0, y: 0 });
geoUnitsPerPixel = averageScaleFromJacobian(jacobian);
}
if (!geoUnitsPerPixel) return null;
// The rest of the lat/lon to meters conversion is correct.
const centerLat = origin?.lat || 0;
const metersPerDegree = 111320 * Math.cos(centerLat * Math.PI / 180);
return geoUnitsPerPixel * metersPerDegree;
}This is a significant logic error in the design document that should be addressed before implementation.
| const totalInches = meters * METERS_TO_FEET * 12; | ||
| const feet = Math.floor(totalInches / 12); | ||
| const inches = Math.round(totalInches % 12); | ||
| return `${feet}' ${inches}"`; |
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.
The logic for converting to feet and inches can lead to incorrect output, for example 5' 12". The issue is with Math.round(totalInches % 12). When totalInches is 71.6 (which is 5' 11.6"), totalInches % 12 is 11.6, and Math.round(11.6) is 12, resulting in 5' 12".
A more robust approach is to round the total number of inches first, and then calculate feet and inches from that.
| const totalInches = meters * METERS_TO_FEET * 12; | |
| const feet = Math.floor(totalInches / 12); | |
| const inches = Math.round(totalInches % 12); | |
| return `${feet}' ${inches}"`; | |
| const totalInches = Math.round(meters * METERS_TO_FEET * 12); | |
| const feet = Math.floor(totalInches / 12); | |
| const inches = totalInches % 12; | |
| return `${feet}' ${inches}"`; |
No description provided.