Skip to content

Commit e5865ca

Browse files
committed
reimplement cornerrounding
1 parent 38ac937 commit e5865ca

File tree

6 files changed

+213
-132
lines changed

6 files changed

+213
-132
lines changed

CHANGELOG.md

+11
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,17 @@ All notable changes to PGS will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). Dates are *YYYY-MM-DD*.
77

8+
## **2.1** *(2025-xx-xx)*
9+
10+
### Added
11+
12+
### Changes
13+
14+
### Fixed
15+
Fixed invalid results given by `PGS_Morphology.rounding()`.
16+
17+
### Removed
18+
819
## **2.0** *(2025-01-11)*
920

1021
**NOTE: Beginning at v2.0, PGS is built with Java 17.**

pom.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<modelVersion>4.0.0</modelVersion>
55
<groupId>micycle</groupId>
66
<artifactId>PGS</artifactId>
7-
<version>2.0</version>
7+
<version>2.1-SNAPSHOT</version>
88
<name>Processing Geometry Suite</name>
99
<description>Geometric algorithms for Processing</description>
1010

@@ -88,7 +88,7 @@
8888
<profile>
8989
<id>uber-jar</id>
9090
<build>
91-
<finalName>${fatJarName}</finalName>
91+
<finalName>${fatJarName}</finalName>
9292
<plugins>
9393
<plugin>
9494
<groupId>org.apache.maven.plugins</groupId>

resources/morphology/round.gif

455 KB
Loading

src/main/java/micycle/pgs/PGS_Conversion.java

+9-2
Original file line numberDiff line numberDiff line change
@@ -1486,14 +1486,18 @@ public static PShape fromArray(double[][] shape, boolean close) {
14861486

14871487
/**
14881488
* Flattens a collection of PShapes into a single GROUP PShape which has the
1489-
* input shapes as its children.
1489+
* input shapes as its children. If the collection contains only one shape, it
1490+
* is directly returned.
14901491
*
14911492
* @since 1.2.0
14921493
* @see #flatten(PShape...)
14931494
*/
14941495
public static PShape flatten(Collection<PShape> shapes) {
14951496
PShape group = new PShape(GROUP);
14961497
shapes.forEach(group::addChild);
1498+
if (group.getChildCount() == 1) {
1499+
return group.getChild(0);
1500+
}
14971501
return group;
14981502
}
14991503

@@ -1990,8 +1994,9 @@ public static class PShapeData {
19901994
* Apply this shapedata to a given PShape.
19911995
*
19921996
* @param other
1997+
* @return other (fluent interface)
19931998
*/
1994-
public void applyTo(PShape other) {
1999+
public PShape applyTo(PShape other) {
19952000
if (other.getFamily() == GROUP) {
19962001
getChildren(other).forEach(c -> applyTo(c));
19972002
}
@@ -2000,6 +2005,8 @@ public void applyTo(PShape other) {
20002005
other.setStroke(stroke);
20012006
other.setStroke(strokeColor);
20022007
other.setStrokeWeight(strokeWeight);
2008+
2009+
return other;
20032010
}
20042011

20052012
@Override

src/main/java/micycle/pgs/PGS_Morphology.java

+15-10
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import micycle.pgs.color.Colors;
3838
import micycle.pgs.commons.ChaikinCut;
3939
import micycle.pgs.commons.CornerRounding;
40+
import micycle.pgs.commons.CornerRounding.RoundingStyle;
4041
import micycle.pgs.commons.DiscreteCurveEvolution;
4142
import micycle.pgs.commons.DiscreteCurveEvolution.DCETerminationCallback;
4243
import micycle.pgs.commons.EllipticFourierDesc;
@@ -546,19 +547,23 @@ public static PShape smoothEllipticFourier(PShape shape, int descriptors) {
546547

547548
/**
548549
* Modifies the corners of a specified shape by replacing each angular corner
549-
* with a smooth, circular arc. The radius of each arc is determined
550-
* proportionally to the shorter of the two lines forming the corner.
550+
* with a smooth, circular arc.
551551
*
552-
* @param shape The original PShape object whose corners are to be rounded.
553-
* @param extent Specifies the degree of corner rounding, with a range from 0 to
554-
* 1. A value of 0 corresponds to no rounding, whereas a value of
555-
* 1 yields maximum rounding while still maintaining the validity
556-
* of the shape. Values above 1 are accepted but may produce
557-
* unpredictable results.
552+
* @param shape A polygonal PShape, or GROUP shape having polygonal children.
553+
* @param radius The radius of the circular arc used to round each corner. This
554+
* determines how much a circle of the given radius "cuts into"
555+
* the corner. The effective radius is bounded by the lengths of
556+
* the edges forming the corner: If the radius is larger than half
557+
* the length of either edge, it is clamped to the smaller of the
558+
* two half-lengths to prevent overlapping or invalid geometry.
558559
* @return A new PShape object with corners rounded to the specified extent.
559560
*/
560-
public static PShape round(PShape shape, double extent) {
561-
return CornerRounding.round(shape, extent);
561+
public static PShape round(PShape shape, double radius) {
562+
return PGS_Processing.transform(shape, s -> {
563+
var styling = PGS_Conversion.getShapeStylingData(shape);
564+
var t = CornerRounding.roundCorners(s, radius, RoundingStyle.CIRCLE);
565+
return styling.applyTo(t);
566+
});
562567
}
563568

564569
/**

0 commit comments

Comments
 (0)