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;
* @author hoelzl
* @author $Author$
* @version $Rev$
* @ConQAT.Rating YELLOW Hash: 118735F6573C95F19DDFBB5B6CFAE4A1
* @ConQAT.Rating YELLOW Hash: A26EFF7CA9FF0409292A918FCEED5947
*/
public class RectangleLayoutUtils {
......@@ -69,32 +69,26 @@ public class RectangleLayoutUtils {
*/
public static OffsetOrientation calculateRectangleBorderOrientation(Point source,
Dimension rectangleSize, int inset) {
int offset = 0;
EOrientation orientation = NORTH;
int distToNorth = source.y;
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
Rectangle bounds = new Rectangle(0, 0, rectangleSize.width, rectangleSize.height);
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) {
int offset;
EOrientation orientation;
if(minDist == distToNorth) {
orientation = NORTH;
offset = (int)(source.x * (1 - (2 * inset) / (double)bounds.width));
} else if(minDistance == distanceToWest) {
offset = source.x;
} else if(minDist == distToWest) {
orientation = WEST;
offset = (int)(source.y * (1 - (2 * inset) / (double)bounds.height));
} else if(minDistance == distanceToSouth) {
offset = source.y;
} else if(minDist == distToSouth) {
orientation = SOUTH;
offset = (int)(source.x * (1 - (2 * inset) / (double)bounds.width));
offset = source.x;
} else {
orientation = EAST;
offset = (int)(source.y * (1 - (2 * inset) / (double)bounds.height));
offset = source.y;
}
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