2022-11-13 00:15:17 +00:00
|
|
|
/// <reference path="../../../udbscript.d.ts" />
|
|
|
|
|
2022-01-06 17:46:37 +00:00
|
|
|
`#version 4`;
|
|
|
|
|
2021-11-28 13:00:24 +00:00
|
|
|
`#name Calculate sector area`;
|
|
|
|
|
|
|
|
`#description Calculates the area of the selected sectors.`
|
|
|
|
|
2022-01-06 17:46:37 +00:00
|
|
|
let sectors = UDB.Map.getSelectedSectors();
|
2021-11-28 13:00:24 +00:00
|
|
|
|
|
|
|
if(sectors.length == 0)
|
2022-01-06 17:46:37 +00:00
|
|
|
UDB.die('You need to select at least one sector.');
|
2021-11-28 13:00:24 +00:00
|
|
|
|
|
|
|
let area = 0;
|
|
|
|
|
|
|
|
sectors.forEach(s => {
|
|
|
|
s.getTriangles().forEach(t => {
|
|
|
|
area += 0.5 * Math.abs(t[0].x * (t[1].y - t[2].y) + t[1].x * (t[2].y - t[0].y) + t[2].x * (t[0].y - t[1].y));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-01-06 17:46:37 +00:00
|
|
|
UDB.showMessage('The area of the selected sectors is ' + area + ' mu².');
|