Skip to content
Snippets Groups Projects
Commit f552ded1 authored by Bastien Abadie's avatar Bastien Abadie
Browse files

Merge branch 'restrict-polygon-element' into 'master'

Restrict a polygon to the element's bounding box

Closes #750

See merge request !1041
parents 84d95ab8 fd62a392
No related branches found
No related tags found
1 merge request!1041Restrict a polygon to the element's bounding box
......@@ -393,6 +393,7 @@ export default {
},
editPolygon (position, action) {
const polygon = this.selectedElement && [...this.selectedElement.zone.polygon]
const point = this.elementLimits(position)
if (action === 'up') {
// Create a temporary edited element with drawn polygon first and last point
if (!polygon) {
......@@ -400,7 +401,7 @@ export default {
id: 'created-polygon',
zone: {
image: { ...this.element.zone.image },
polygon: [position, position]
polygon: [point, point]
}
})
return
......@@ -411,12 +412,12 @@ export default {
} else if (magnetized && polygon.some(pt => pointsEqual(position, pt))) {
// Do not allow to reuse an existing point
} else {
polygon.push(position)
polygon.push(point)
}
} else if (this.selectedElement && action === 'move') {
this.magnetize(position, polygon)
// Add a segment between the last polygon point and the current cursor position
polygon.splice(-1, 1, this.elementLimits(position))
polygon.splice(-1, 1, point)
} else if (this.selectedElement && action === 'dbClick') {
polygon.push(polygon[0])
if (this.selectedElement) return this.create()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment