mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 17:22:09 +10:00
improve curve detection
This commit is contained in:
+3
-5
@@ -50,7 +50,7 @@ import java.util.Map;
|
|||||||
class G2DWrapper extends Graphics2D {
|
class G2DWrapper extends Graphics2D {
|
||||||
|
|
||||||
public static int LINE_SENSITIVITY_MARGIN = 2;
|
public static int LINE_SENSITIVITY_MARGIN = 2;
|
||||||
public static int CURVE_SENSITIVITY = 10;
|
public static int CURVE_SENSITIVITY = 6;
|
||||||
|
|
||||||
private boolean drawingComponent = false;
|
private boolean drawingComponent = false;
|
||||||
|
|
||||||
@@ -189,10 +189,9 @@ class G2DWrapper extends Graphics2D {
|
|||||||
* @param curve
|
* @param curve
|
||||||
*/
|
*/
|
||||||
private void addCubicCurveArea(CubicCurve2D curve) {
|
private void addCubicCurveArea(CubicCurve2D curve) {
|
||||||
double d = curve.getP1().distance(curve.getP2());
|
|
||||||
// When end points are close enough, approximate the curve with a
|
// When end points are close enough, approximate the curve with a
|
||||||
// straight line.
|
// straight line.
|
||||||
if (d < CURVE_SENSITIVITY) {
|
if (curve.getFlatness() < CURVE_SENSITIVITY) {
|
||||||
appendShapeOutline(new Line2D.Double(curve.getP1(), curve.getP2()));
|
appendShapeOutline(new Line2D.Double(curve.getP1(), curve.getP2()));
|
||||||
} else {
|
} else {
|
||||||
CubicCurve2D leftSubcurve = new CubicCurve2D.Double();
|
CubicCurve2D leftSubcurve = new CubicCurve2D.Double();
|
||||||
@@ -210,10 +209,9 @@ class G2DWrapper extends Graphics2D {
|
|||||||
* @param curve
|
* @param curve
|
||||||
*/
|
*/
|
||||||
private void addQuadCurveArea(QuadCurve2D curve) {
|
private void addQuadCurveArea(QuadCurve2D curve) {
|
||||||
double d = curve.getP1().distance(curve.getP2());
|
|
||||||
// When end points are close enough, approximate the curve with a
|
// When end points are close enough, approximate the curve with a
|
||||||
// straight line.
|
// straight line.
|
||||||
if (d < CURVE_SENSITIVITY) {
|
if (curve.getFlatness() < CURVE_SENSITIVITY) {
|
||||||
appendShapeOutline(new Line2D.Double(curve.getP1(), curve.getP2()));
|
appendShapeOutline(new Line2D.Double(curve.getP1(), curve.getP2()));
|
||||||
} else {
|
} else {
|
||||||
QuadCurve2D leftSubcurve = new QuadCurve2D.Double();
|
QuadCurve2D leftSubcurve = new QuadCurve2D.Double();
|
||||||
|
|||||||
Reference in New Issue
Block a user