Skip to content

Commit 6dbbd5c

Browse files
committed
fixup remove vertex
1 parent 26def59 commit 6dbbd5c

File tree

1 file changed

+16
-9
lines changed
  • src/components/shapes/draw_newshape

1 file changed

+16
-9
lines changed

src/components/shapes/draw_newshape/draw.js

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -159,29 +159,36 @@ function displayOutlines(polygons, outlines, dragOptions, nCalls) {
159159

160160
function removeVertex() {
161161
if(!polygons.length) return;
162-
var len = polygons[indexI].length;
163-
if(len < 3) return;
162+
if(!polygons[indexI]) return;
163+
if(!polygons[indexI].length) return;
164164

165165
var newPolygon = [];
166-
for(var j = 0; j < len; j++) {
166+
for(var j = 0; j < polygons[indexI].length; j++) {
167167
if(j !== indexJ) {
168168
newPolygon.push(
169169
polygons[indexI][j]
170170
);
171171
}
172172
}
173173

174-
if(indexJ === 0) {
175-
newPolygon[indexI][0] = 'M';
176-
}
174+
if(newPolygon.length > 1 && !(
175+
newPolygon.length === 2 && newPolygon[1][0] === 'Z')
176+
) {
177+
if(indexJ === 0) {
178+
newPolygon[0][0] = 'M';
179+
}
177180

178-
polygons[indexI] = newPolygon;
181+
polygons[indexI] = newPolygon;
179182

180-
redraw();
183+
redraw();
184+
}
181185
}
182186

183-
function clickVertexController(numClicks) {
187+
function clickVertexController(numClicks, evt) {
184188
if(numClicks === 2) {
189+
indexI = +evt.srcElement.getAttribute('data-i');
190+
indexJ = +evt.srcElement.getAttribute('data-j');
191+
185192
var cell = polygons[indexI];
186193
if(
187194
!pointsShapeRectangle(cell) &&

0 commit comments

Comments
 (0)