Skip to content

Commit

Permalink
feat: Polygon movements. #1597
Browse files Browse the repository at this point in the history
  • Loading branch information
mturoci committed Sep 29, 2022
1 parent 78e7451 commit 2822f05
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 25 deletions.
35 changes: 13 additions & 22 deletions ui/src/image_annotator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,31 +129,22 @@ const

return cursor
},
mapShapesToWaveArgs = (shapes: DrawnShape[], aspectRatio: F) => {
return shapes.map(({ shape, tag }) => {
if (shape.rect) return {
tag,
shape: {
rect: {
x1: shape.rect.x1 * aspectRatio,
x2: shape.rect.x2 * aspectRatio,
y1: shape.rect.y1 * aspectRatio,
y2: shape.rect.y2 * aspectRatio,
}
}
}
else if (shape.polygon) return {
tag,
shape: {
polygon: {
items: shape.polygon.items.map(i => ({ x: i.x * aspectRatio, y: i.y * aspectRatio }))
}
mapShapesToWaveArgs = (shapes: DrawnShape[], aspectRatio: F) => shapes.map(({ shape, tag }) => {
if (shape.rect) return {
tag,
shape: {
rect: {
x1: shape.rect.x1 * aspectRatio,
x2: shape.rect.x2 * aspectRatio,
y1: shape.rect.y1 * aspectRatio,
y2: shape.rect.y2 * aspectRatio,
}
}
return { tag, shape }
})
}
else if (shape.polygon) return { tag, shape: { polygon: { items: shape.polygon.items.map(i => ({ x: i.x * aspectRatio, y: i.y * aspectRatio })) } } }
return { tag, shape }
})

}

export const XImageAnnotator = ({ model }: { model: ImageAnnotator }) => {
const
Expand Down
8 changes: 5 additions & 3 deletions ui/src/image_annotator_polygon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,13 @@ export class PolygonAnnotator {
this.draggedPoint.y += cursor_y - this.draggedPoint.y
}
else if (intersected == focused || this.draggedShape) {
this.draggedShape = intersected || this.draggedShape
this.draggedShape = intersected?.shape.polygon && intersected.isFocused ? intersected : this.draggedShape
this.draggedShape?.shape.polygon?.items.forEach(p => {
p.x += cursor_x - p.x
p.y += cursor_y - p.y
p.x += cursor_x - clickStartPosition!.x
p.y += cursor_y - clickStartPosition!.y
})
clickStartPosition.x = cursor_x
clickStartPosition.y = cursor_y
}
}

Expand Down

0 comments on commit 2822f05

Please sign in to comment.