Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add property to automatically set minimal paddings for rounded rectangles #165

Merged
merged 3 commits into from
Jul 18, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
remove magic numbers and update documentation
Signed-off-by: Max Kasperowski <[email protected]>
  • Loading branch information
Eddykasp committed Jul 18, 2023
commit 6ef6809a7d3f0c7c5e26e660700b6791c7621402
Original file line number Diff line number Diff line change
Expand Up @@ -384,13 +384,15 @@ private void createNode(final LayoutMapping mapping, final KNode node,
if (node.getProperty(KlighdProperties.ROUNDED_RECTANGLE_AUTOPADDING) != null) {
KVector radii = node.getProperty(KlighdProperties.ROUNDED_RECTANGLE_AUTOPADDING);
double padding = 0;
// threshold to check for almost zero-ness
double EPSILON = 0.00001;
// x and y cannot be zero, if one of the two is zero use the larger value
if (radii.x < 0.00001 && radii.y >= 0.00001) {
radii.x = 0.00001;
} else if (radii.x >= 0.00001 && radii.y < 0.00001) {
radii.y = 0.00001;
if (radii.x < EPSILON && radii.y >= EPSILON) {
radii.x = EPSILON;
} else if (radii.x >= EPSILON && radii.y < EPSILON) {
radii.y = EPSILON;
}
if (!(radii.x < 0.00001 && radii.y < 0.00001)) {
if (!(radii.x < EPSILON && radii.y < EPSILON)) {
// computes a padding x such that the corners of the inner rectangle fit exactly within the rounded rectangle
double numerator = radii.x * radii.y * (-Math.sqrt(2) * Math.sqrt(radii.x * radii.y) + radii.x + radii.y);
double denominator = radii.x * radii.x + radii.y * radii.y;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,9 @@ public static boolean isSelectable(final EObject viewElement) {

/**
* Automatically computes the padding required to fit the content of a node within the bounds of a
* rounded rectangle. The x and y corner radii are specified as x and y of a KVector.
* rounded rectangle. The x and y corner radii are specified as x and y of a KVector. If this property
* is set, the ElkPadding set on the graph will be overridden internally. This property should only be
* used if no padding is manually set on the graph element.
*/
public static final IProperty<KVector> ROUNDED_RECTANGLE_AUTOPADDING =
new Property<KVector>("klighd.roundedRectangle.autopadding", null);
Expand Down