Skip to content
Snippets Groups Projects
Commit f15ecf9a authored by Vincent Aravantinos's avatar Vincent Aravantinos
Browse files

even better now

refs 2021
parent f29e3c81
No related branches found
No related tags found
No related merge requests found
...@@ -51,7 +51,7 @@ import org.fortiss.tooling.base.ui.dnd.gef.ElementDropContext; ...@@ -51,7 +51,7 @@ import org.fortiss.tooling.base.ui.dnd.gef.ElementDropContext;
* @author hoelzl * @author hoelzl
* @author $Author$ * @author $Author$
* @version $Rev$ * @version $Rev$
* @ConQAT.Rating YELLOW Hash: 118735F6573C95F19DDFBB5B6CFAE4A1 * @ConQAT.Rating YELLOW Hash: A26EFF7CA9FF0409292A918FCEED5947
*/ */
public class RectangleLayoutUtils { public class RectangleLayoutUtils {
...@@ -69,32 +69,26 @@ public class RectangleLayoutUtils { ...@@ -69,32 +69,26 @@ public class RectangleLayoutUtils {
*/ */
public static OffsetOrientation calculateRectangleBorderOrientation(Point source, public static OffsetOrientation calculateRectangleBorderOrientation(Point source,
Dimension rectangleSize, int inset) { Dimension rectangleSize, int inset) {
int offset = 0; int distToNorth = source.y;
EOrientation orientation = NORTH; int distToSouth = rectangleSize.height - source.y - 2 * inset;
int distToWest = source.x;
int distToEast = rectangleSize.width - source.x - 2 * inset;
int minDist = min(min(min(distToEast, distToNorth), distToWest), distToSouth);
// The figure bounds int offset;
Rectangle bounds = new Rectangle(0, 0, rectangleSize.width, rectangleSize.height); EOrientation orientation;
if(minDist == distToNorth) {
int distanceToNorth = source.y;
int distanceToSouth = bounds.height - source.y;
int distanceToWest = source.x;
int distanceToEast = bounds.width - source.x;
int minDistance =
min(min(min(distanceToEast, distanceToNorth), distanceToWest), distanceToSouth);
// Determine in which sector we are and clamp the position accordingly
if(minDistance == distanceToNorth) {
orientation = NORTH; orientation = NORTH;
offset = (int)(source.x * (1 - (2 * inset) / (double)bounds.width)); offset = source.x;
} else if(minDistance == distanceToWest) { } else if(minDist == distToWest) {
orientation = WEST; orientation = WEST;
offset = (int)(source.y * (1 - (2 * inset) / (double)bounds.height)); offset = source.y;
} else if(minDistance == distanceToSouth) { } else if(minDist == distToSouth) {
orientation = SOUTH; orientation = SOUTH;
offset = (int)(source.x * (1 - (2 * inset) / (double)bounds.width)); offset = source.x;
} else { } else {
orientation = EAST; orientation = EAST;
offset = (int)(source.y * (1 - (2 * inset) / (double)bounds.height)); offset = source.y;
} }
return createOffsetOrientation(offset, orientation, null); return createOffsetOrientation(offset, orientation, null);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment