diff --git a/src/tools/trackeditor/gui/EditorFrame.java b/src/tools/trackeditor/gui/EditorFrame.java index fff86202f..abbe2e6d5 100644 --- a/src/tools/trackeditor/gui/EditorFrame.java +++ b/src/tools/trackeditor/gui/EditorFrame.java @@ -2435,7 +2435,7 @@ public class EditorFrame extends JFrame int type = JOptionPane.PLAIN_MESSAGE; String msg = Editor.getProperties().title + " " + Editor.getProperties().version + "\n\n" + "Copyright Charalampos Alexopoulos\n" - + "Copyright (2022) Robert Reif\n"; + + "Copyright (2022-2023) Robert Reif\n"; JOptionPane.showMessageDialog(null,msg,"About",type); } } diff --git a/src/tools/trackeditor/gui/view/CircuitView.java b/src/tools/trackeditor/gui/view/CircuitView.java index f35745ee4..b030f999b 100644 --- a/src/tools/trackeditor/gui/view/CircuitView.java +++ b/src/tools/trackeditor/gui/view/CircuitView.java @@ -433,7 +433,7 @@ public class CircuitView extends JComponent implements KeyListener, MouseListene oldShape.setArcDeg(tmpAngle); oldShape.setRadiusEnd(tmpRadius - deltaRadiusStep); redrawCircuit(); - if (oldShape.contains(mousePoint.x, mousePoint.y)) + if (oldShape.contains(mousePoint)) { splitPoint = curStep / nbSteps; break; @@ -489,7 +489,7 @@ public class CircuitView extends JComponent implements KeyListener, MouseListene oldShape.setArcDeg(tmpAngle); oldShape.setRadiusEnd(tmpRadius - deltaRadiusStep); redrawCircuit(); - if (oldShape.contains(mousePoint.x, mousePoint.y)) + if (oldShape.contains(mousePoint)) { splitPoint = curStep / nbSteps; break; @@ -528,7 +528,7 @@ public class CircuitView extends JComponent implements KeyListener, MouseListene newShape3.setLength(length * (1.0 - splitPoint)); oldShape.setLength(length * splitPoint); redrawCircuit(); - if (oldShape.contains(mousePoint.x, mousePoint.y)) + if (oldShape.contains(mousePoint)) { break; } @@ -1132,7 +1132,7 @@ public class CircuitView extends JComponent implements KeyListener, MouseListene Segment obj = i.next(); if (Class.forName("utils.circuit.Segment").isAssignableFrom(obj.getClass()) - && obj.contains(mousePoint.getX(), mousePoint.getY())) + && obj.contains(mousePoint)) { // object found ! out = obj; @@ -1162,7 +1162,7 @@ public class CircuitView extends JComponent implements KeyListener, MouseListene try { if (Class.forName("utils.circuit.Segment").isAssignableFrom(object.getClass()) - && object.contains(mousePoint.getX(), mousePoint.getY())) + && object.contains(mousePoint)) { // object found ! out = object; diff --git a/src/tools/trackeditor/utils/Properties.java b/src/tools/trackeditor/utils/Properties.java index 0107ab5c3..cbb3139d2 100644 --- a/src/tools/trackeditor/utils/Properties.java +++ b/src/tools/trackeditor/utils/Properties.java @@ -34,7 +34,7 @@ public class Properties private static Properties instance = new Properties(); private Vector propertiesListeners = new Vector(); public final String title = "sd2-trackeditor"; - public final String version = "1.0.0"; + public final String version = "1.0.1"; private String path; private double imageScale = 1; diff --git a/src/tools/trackeditor/utils/circuit/Segment.java b/src/tools/trackeditor/utils/circuit/Segment.java index a5d26a57c..47cf85206 100644 --- a/src/tools/trackeditor/utils/circuit/Segment.java +++ b/src/tools/trackeditor/utils/circuit/Segment.java @@ -199,56 +199,43 @@ public class Segment implements Cloneable return shape; } - public boolean contains(double x, double y) + // adapted from: https://web.archive.org/web/20130126163405/http://geomalgorithms.com/a03-_inclusion.html + // Copyright 2000 softSurfer, 2012 Dan Sunday + private double isLeft(Point2D.Double P0, Point2D.Double P1, Point2D.Double P2) + { + return ((P1.x - P0.x) * (P2.y - P0.y) - (P2.x - P0.x) * (P1.y - P0.y)); + } + + public boolean contains(Point2D.Double point) { for (int i = 0; i < points.length; i += 4) { - boolean found = true; + int count = 0; for (int j = 0; j < 4; j++) { - int idxA = i + j; - int idxB = i + (j + 1) % 4; - int idxC = i + (j + 2) % 4; - int idxD = i + (j + 3) % 4; + int start = i + j; + int next = i + ((j + 1) % 4); - if (points[idxA].equals(points[idxB]) || points[idxB].equals(points[idxC]) - || points[idxC].equals(points[idxD]) || points[idxD].equals(points[idxA])) + if (points[start].y <= point.y) { - found = false; - break; - } - - if (points[idxA].x == points[idxB].x) - { - // vertical line - int localSign = (x > points[idxA].x ? 1 : -1); - int localSign2 = (points[idxC].x > points[idxA].x ? 1 : -1); - - if (localSign != localSign2) + if (points[next].y > point.y) { - found = false; - break; + if (isLeft(points[start], points[next], point) > 0) + ++count; } - } else + } + else { - double a, b; - - a = (points[idxB].y - points[idxA].y) / (points[idxB].x - points[idxA].x); - b = points[idxA].y - a * points[idxA].x; - - int localSign = (y > a * x + b ? 1 : -1); - int localSign2 = (points[idxC].y > a * points[idxC].x + b ? 1 : -1); - - if (localSign != localSign2) + if (points[next].y <= point.y) { - found = false; - break; + if (isLeft(points[start], points[next], point) < 0) + --count; } } } - if (found) + if (count != 0) return true; }