Skip to content

Commit 6e29629

Browse files
committed
Fix computation of polygon centroid
1 parent cade213 commit 6e29629

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/annotation.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,7 @@ function _getPolygonCentroid (
625625
const offset = graphicIndex[annotationIndex] - 1
626626
let length
627627
if (annotationIndex < (numberOfAnnotations - 1)) {
628-
length = offset - graphicIndex[annotationIndex + 1]
628+
length = graphicIndex[annotationIndex + 1] - offset
629629
} else {
630630
length = graphicData.length
631631
}
@@ -635,10 +635,11 @@ function _getPolygonCentroid (
635635
for (let j = offset; j < offset + length; j++) {
636636
const p0 = _getCoordinates(graphicData, j, commonZCoordinate)
637637
let p1
638-
if (j === (offset + length - numberOfAnnotations)) {
638+
if (j === (offset + length - 1)) {
639639
p1 = _getCoordinates(graphicData, offset, commonZCoordinate)
640640
} else {
641-
p1 = _getCoordinates(graphicData, j + numberOfAnnotations, commonZCoordinate)
641+
const nextOffset = j + coordinateDimensionality
642+
p1 = _getCoordinates(graphicData, nextOffset, commonZCoordinate)
642643
}
643644
const a = p0[0] * p1[1] - p1[0] * p0[1]
644645
area += a

0 commit comments

Comments
 (0)