本文整理汇总了Java中java.awt.geom.CubicCurve2D.subdivide方法的典型用法代码示例。如果您正苦于以下问题:Java CubicCurve2D.subdivide方法的具体用法?Java CubicCurve2D.subdivide怎么用?Java CubicCurve2D.subdivide使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.geom.CubicCurve2D
的用法示例。
在下文中一共展示了CubicCurve2D.subdivide方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: curveTo
import java.awt.geom.CubicCurve2D; //导入方法依赖的package包/类
public void curveTo(CubicCurve2D curve) {
final double flatness = curve.getFlatness();
final double dist = curve.getP1().distance(curve.getP2());
if (flatness > 0.1 && dist > 20) {
final CubicCurve2D left = new CubicCurve2D.Double();
final CubicCurve2D right = new CubicCurve2D.Double();
curve.subdivide(left, right);
curveTo(left);
curveTo(right);
return;
}
lineTo(curve.getP2());
}
示例2: subdivide2D
import java.awt.geom.CubicCurve2D; //导入方法依赖的package包/类
private GeneralPath subdivide2D (Point2D b0, Point2D b1, Point2D b2, Point2D b3) {
//set 2nd intermediate point to endpoint
//we could actually use another "better" point if we like to have a smoother curve
double cutDistance = getTargetAnchorShape().getCutDistance();
double minDistance = cutDistance - ENDPOINT_DEVIATION;
/**
* if the cutDistance is valid the last segment of the curve
* gets reduced by subdivision until the distance of the endpoint(epDistance)
* satisfys the condition (cutDistance > epDistance > (cutDistance - ENDPOINT-DEVIATION)
*/
if(cutDistance > minDistance && minDistance > 0 ) {
GeneralPath path = new GeneralPath();
path.moveTo(b0.getX(), b0.getY());
CubicCurve2D.Double curve = new CubicCurve2D.Double(
b0.getX(), b0.getY(),
b1.getX(), b1.getY(),
b2.getX(), b2.getY(),
b3.getX(), b3.getY());
CubicCurve2D right=new CubicCurve2D.Double();
CubicCurve2D left=new CubicCurve2D.Double();
curve.subdivide(left, right);
double distance = b3.distance(left.getP2());
//if the distance is bigger as the cutDistance the left segment is added
//and the right segment is divided again
while(distance>cutDistance){
path.append(left, true);
right.subdivide(left, right);
distance = b3.distance(left.getP2());
//if the devision removed to much the left segment is divided
while(distance < minDistance) {
//changes the distance to ~ (distance+distance/2)
left.subdivide(left, right);
distance = b3.distance(left.getP2());
}
}
//append the last segment with (minDistance < distance < cutDistance)
path.append(left, true);
return path;
}
return null;
}
示例3: isHitAt
import java.awt.geom.CubicCurve2D; //导入方法依赖的package包/类
/**
* Returns whether a specified local point pL is a part of the connection
* widget.
* First it make a rough bounds check
* for Line Segments => use Super call (ConnectionWidget.isHitAt(pL)).
* for self-edges => its sufficent to return getBounds.contains(pL).
* for Splines => Interate over all Partitial segments of the curve and make
* a minmax check with the bezier points. If pL is inside the minmax
* rectangle of one segment the curve is constructed and subdivided until
* the distance d between center point pC (of the bounding rectangle)
* and pL is below HIT_DISTANCE_SQUARE, in this case it returns true.
* If no no minmax check was successful or the subdivision lead to an
* rectangle witch doesn`t contain pL return false.
* @param localLocation the local location
* @return true, if the location is a part of the connection widget
*/
@Override
public boolean isHitAt(Point localLocation) {
if(!isVisible() || !getBounds ().contains (localLocation))
return false;
List<Point> controlPoints = getControlPoints ();
if(controlPoints.size() <=2){
if(isReflexive()) return true;
return super.isHitAt(localLocation);
}
if(bezierPoints != null) {
for (int i = 0; i < bezierPoints.length-1; i+=3) {
Point2D b0 = bezierPoints[i];
Point2D b1 = bezierPoints[i+1];
Point2D b2 = bezierPoints[i+2];
Point2D b3 = bezierPoints[i+3];
CubicCurve2D left = new CubicCurve2D.Double(
b0.getX(), b0.getY(),
b1.getX(), b1.getY(),
b2.getX(), b2.getY(),
b3.getX(), b3.getY());
Rectangle2D bounds = left.getBounds2D();
while(bounds.contains(localLocation)) {
//calculate the center and use HIT_DISTANCE_SQUARE for a range check
Point2D test = new Point2D.Double(bounds.getCenterX(),bounds.getCenterY());
if(test.distance(localLocation) < HIT_DISTANCE_SQUARE){
return true;
}
CubicCurve2D right = new CubicCurve2D.Double();
left.subdivide(left, right);
Rectangle2D lb2d = left.getBounds2D();
Rectangle2D rb2d = right.getBounds2D();
if( lb2d.contains(localLocation)){
bounds = lb2d;
} else if (rb2d.contains(localLocation)) {
left = right;
bounds = rb2d;
} else {
return false;
}
}//end while
}//end for
}
return false;
}
示例4: subdivide
import java.awt.geom.CubicCurve2D; //导入方法依赖的package包/类
private GeneralPath subdivide (Point b0, Point b1, Point b2, Point b3) {
double cutDistance = getTargetAnchorShape().getCutDistance();
double minDistance = cutDistance - ENDPOINT_DEVIATION;
/**
* if the cutDistance is valid the last segment of the curve
* gets reduced by subdivision until the distance of the endpoint(epDistance)
* satisfys the condition (cutDistance > epDistance > (cutDistance - ENDPOINT-DEVIATION)
*/
if(cutDistance > minDistance && minDistance > 0 ) {
GeneralPath path = new GeneralPath();
path.moveTo(b0.x, b0.y);
CubicCurve2D.Double left = new CubicCurve2D.Double(
b0.x, b0.y,
b1.x, b1.y,
b2.x, b2.y,
b3.x, b3.y);
CubicCurve2D right=new CubicCurve2D.Double();
left.subdivide(left, right);
double distance = b3.distance(left.getP2());
//if the distance is bigger as the cutDistance the left segment is added
//and the right segment is divided again
while(distance>cutDistance){
path.append(left, true);
right.subdivide(left, right);
distance = b3.distance(left.getP2());
//if the devision removed to much the left segment is divided
while(distance < minDistance) {
//changes the distance to ~ (distance+distance/2)
left.subdivide(left, right);
distance = b3.distance(left.getP2());
}
}
//append the last segment with (minDistance < distance < cutDistance)
//actually we should check if the a division happend, but this is very unlikly
path.append(left, true);
return path;
}
return null;
}