Skip to content

Commit

Permalink
chore: enhanced conflation logic
Browse files Browse the repository at this point in the history
  • Loading branch information
jeafreezy committed Dec 5, 2024
1 parent bdc179a commit e1a8996
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 25 deletions.
2 changes: 1 addition & 1 deletion frontend/src/app/routes/start-mapping.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ export const StartMappingPage = () => {
<BackButton />

<div className="min-h-screen md:h-[90vh] flex mt-8 flex-col mb-20">
<div>
<div className="sticky top-0 bg-white z-10">
{renderModelHeader}
<div className="hidden md:block w-full">
<Divider />
Expand Down
45 changes: 21 additions & 24 deletions frontend/src/utils/geometry-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,29 +314,16 @@ export const snapGeoJSONGeometryToClosestTile = (geometry: Geometry) => {

/*
Logic.
------------------------------------------------------
| Same area | New area |
------------------------------------------------------
| 1 - Purple | Will be replaced with new feature |
| 2 - Red | No touch |
| 3 - Green | No touch |
------------------------------------------------------
Handling Purple i.e all features:
------------------------------------------------------
| 1 - Purple | |
| | Check if they intersect with previous purple |
| | - Yes: Replace with new feature |
| | - No: Keep the purple as it is |
------------------------------------------------------
| 1 - Purple: Will be replaced with new feature if it intersects with new features, otherwise, it'll be appended.
| 2 - Red: No touch
| 3 - Green: No touch
*/

export const handleConflation = (
existingPredictions: TModelPredictions,
newFeatures: Feature[],
): TModelPredictions => {
const updatedAll = [...existingPredictions.all];

let updatedAll = [...existingPredictions.all];

newFeatures.forEach((newFeature) => {
const intersectsWithAccepted = existingPredictions.accepted.some(
Expand All @@ -345,21 +332,31 @@ export const handleConflation = (
const intersectsWithRejected = existingPredictions.rejected.some(
(rejectedFeature) => booleanIntersects(newFeature, rejectedFeature),
);
const intersectsWithAll = updatedAll.some((existingFeature) =>


const intersectingIndex = updatedAll.findIndex((existingFeature) =>
booleanIntersects(newFeature, existingFeature),
);

// If it doesn't intersect with any of the accepted, rejected, or all features, add it to all
if (
if (intersectingIndex !== -1) {

updatedAll[intersectingIndex] = {
...newFeature,
properties: {
...newFeature.properties,
id: updatedAll[intersectingIndex].properties?.id || uuid4(),
},
};
} else if (
!intersectsWithAccepted &&
!intersectsWithRejected &&
!intersectsWithAll
!intersectsWithRejected
) {

updatedAll.push({
...newFeature,
properties: {
...newFeature.properties,
id: uuid4(), // Add unique ID for tracking
id: uuid4(),
},
});
}
Expand Down

0 comments on commit e1a8996

Please sign in to comment.