Skip to content

Commit

Permalink
Fixed issue #1027.
Browse files Browse the repository at this point in the history
  • Loading branch information
nilsschmidt1337 committed Mar 23, 2024
1 parent db9294e commit de95b4d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 14 deletions.
28 changes: 17 additions & 11 deletions src/org/nschmidt/ldparteditor/data/VM01SelectHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -1812,7 +1812,7 @@ private List<GData1> subfilesWithOneVertex() {
.toList();
}

public Vector4f getSelectionCenter() {
public Vector3d getSelectionCenter() {

final Set<Vertex> objectVertices = Collections.newSetFromMap(new ThreadsafeSortedMap<>());
objectVertices.addAll(selectedVertices);
Expand Down Expand Up @@ -1856,18 +1856,24 @@ public Vector4f getSelectionCenter() {
}
}
if (!objectVertices.isEmpty()) {
float x = 0f;
float y = 0f;
float z = 0f;
for (Vertex vertex : objectVertices) {
x = x + vertex.x;
y = y + vertex.y;
z = z + vertex.z;
final int count = objectVertices.size();
if (count == 1) {
final Vertex v = objectVertices.iterator().next();
return new Vector3d(v);
} else {
BigDecimal c = BigDecimal.valueOf(count);
BigDecimal sumX = BigDecimal.ZERO;
BigDecimal sumY = BigDecimal.ZERO;
BigDecimal sumZ = BigDecimal.ZERO;
for (Vertex vertex : objectVertices) {
sumX = sumX.add(vertex.xp);
sumY = sumY.add(vertex.yp);
sumZ = sumZ.add(vertex.zp);
}
return new Vector3d(sumX.divide(c, Threshold.MC), sumY.divide(c, Threshold.MC), sumZ.divide(c, Threshold.MC));
}
float count = objectVertices.size();
return new Vector4f(x / count, y / count, z / count, 1f);
} else {
return new Vector4f(0f, 0f, 0f, 1f);
return new Vector3d();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.nschmidt.ldparteditor.helper.Manipulator;
import org.nschmidt.ldparteditor.helper.WidgetSelectionHelper;
import org.nschmidt.ldparteditor.helper.math.MatrixOperations;
import org.nschmidt.ldparteditor.helper.math.Vector3d;
import org.nschmidt.ldparteditor.i18n.I18n;
import org.nschmidt.ldparteditor.opengl.OpenGLRenderer;
import org.nschmidt.ldparteditor.project.Project;
Expand Down Expand Up @@ -470,12 +471,12 @@ public static void mntmManipulatorCameraToPos() {
@SuppressWarnings("java:S2111")
public static void mntmManipulatorToAverage() {
if (Project.getFileToEdit() != null) {
Vector4f avg = Project.getFileToEdit().getVertexManager().getSelectionCenter();
Vector3d avg = Project.getFileToEdit().getVertexManager().getSelectionCenter();
for (OpenGLRenderer renderer : Editor3DWindow.getRenders()) {
Composite3D c3d = renderer.getC3D();
if (c3d.getLockableDatFileReference().equals(Project.getFileToEdit())) {
c3d.getManipulator().getPosition().set(avg.x, avg.y, avg.z, 1f);
c3d.getManipulator().setAccuratePosition(new BigDecimal(avg.x / 1000f), new BigDecimal(avg.y / 1000f), new BigDecimal(avg.z / 1000f));
c3d.getManipulator().getPosition().set(avg.x.floatValue() * 1000f, avg.y.floatValue() * 1000f, avg.z.floatValue() * 1000f, 1f);
c3d.getManipulator().setAccuratePosition(avg.x, avg.y, avg.z);
}
}
}
Expand Down

0 comments on commit de95b4d

Please sign in to comment.