本文整理汇总了Java中java.awt.geom.CubicCurve2D类的典型用法代码示例。如果您正苦于以下问题:Java CubicCurve2D类的具体用法?Java CubicCurve2D怎么用?Java CubicCurve2D使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CubicCurve2D类属于java.awt.geom包,在下文中一共展示了CubicCurve2D类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: paintMatcher
import java.awt.geom.CubicCurve2D; //导入依赖的package包/类
private void paintMatcher(Graphics2D g, Color fillClr,
int leftX, int rightX, int upL, int upR, int doR, int doL) {
int topY = Math.min(upL, upR), bottomY = Math.max(doL, doR);
// try rendering only curves in viewable area
if (!g.hitClip(leftX, topY, rightX - leftX, bottomY - topY)) {
return;
}
CubicCurve2D upper = new CubicCurve2D.Float(leftX, upL,
(rightX -leftX)*.3f, upL,
(rightX -leftX)*.7f, upR,
rightX, upR);
CubicCurve2D bottom = new CubicCurve2D.Float(rightX, doR,
(rightX - leftX)*.7f, doR,
(rightX -leftX)*.3f, doL,
leftX, doL);
GeneralPath path = new GeneralPath();
path.append(upper, false);
path.append(bottom, true);
path.closePath();
g.setColor(fillClr);
g.fill(path);
g.setColor(master.getColorLines());
g.draw(upper);
g.draw(bottom);
}
示例2: chopStart
import java.awt.geom.CubicCurve2D; //导入依赖的package包/类
/** Chop the start of this curve. */
public void chopStart(double t) {
int n = list.size();
t = t * n;
double di = StrictMath.floor(t);
int i = (int) di;
//
if (i < 0)
return;
if (i >= n)
list.clear();
while (i > 0 && !list.isEmpty()) {
list.remove(0);
i--;
}
if (list.isEmpty()) {
list.add(new CubicCurve2D.Double(startX = endX, startY = endY, endX, endY, endX, endY, endX, endY));
return;
}
CubicCurve2D.Double tmp = new CubicCurve2D.Double();
divide(t - di, list.get(0), new CubicCurve2D.Double(), tmp);
list.get(0).setCurve(tmp);
startX = tmp.x1;
startY = tmp.y1;
}
示例3: chopEnd
import java.awt.geom.CubicCurve2D; //导入依赖的package包/类
/** Chop the end of this curve. */
public void chopEnd(double t) {
int n = list.size();
t = t * n;
double di = StrictMath.floor(t);
int i = (int) di;
//
if (i < 0)
list.clear();
if (i >= n)
return;
while (i + 1 < list.size())
list.remove(i + 1);
if (list.isEmpty()) {
endX = startX;
endY = startY;
list.add(new CubicCurve2D.Double(endX, endY, endX, endY, endX, endY, endX, endY));
return;
}
CubicCurve2D.Double tmp = new CubicCurve2D.Double();
divide(t - di, list.get(i), tmp, new CubicCurve2D.Double());
list.get(i).setCurve(tmp);
endX = tmp.x2;
endY = tmp.y2;
}
示例4: divide
import java.awt.geom.CubicCurve2D; //导入依赖的package包/类
/**
* Given 0<=t<=1 and an existing curve, divide it into two chunks and store
* the two chunks into "first" and "second"
*/
public static void divide(double t, CubicCurve2D.Double curve, CubicCurve2D.Double first,
CubicCurve2D.Double second) {
// This algorithm uses de Casteljau's algorithm for chopping one bezier
// curve into two bezier curves
first.x1 = curve.x1;
second.x2 = curve.x2;
first.ctrlx1 = (1 - t) * curve.x1 + t * curve.ctrlx1;
double x = (1 - t) * curve.ctrlx1 + t * curve.ctrlx2;
second.ctrlx2 = (1 - t) * curve.ctrlx2 + t * curve.x2;
first.ctrlx2 = (1 - t) * first.ctrlx1 + t * x;
second.ctrlx1 = (1 - t) * x + t * second.ctrlx2;
second.x1 = first.x2 = (1 - t) * first.ctrlx2 + t * second.ctrlx1;
// now that we've computed the x coordinates, we now compute the y
// coordinates
first.y1 = curve.y1;
second.y2 = curve.y2;
first.ctrly1 = (1 - t) * curve.y1 + t * curve.ctrly1;
double y = (1 - t) * curve.ctrly1 + t * curve.ctrly2;
second.ctrly2 = (1 - t) * curve.ctrly2 + t * curve.y2;
first.ctrly2 = (1 - t) * first.ctrly1 + t * y;
second.ctrly1 = (1 - t) * y + t * second.ctrly2;
second.y1 = first.y2 = (1 - t) * first.ctrly2 + t * second.ctrly1;
}
示例5: drawSmoothly
import java.awt.geom.CubicCurve2D; //导入依赖的package包/类
/** Draws the given curve smoothly (assuming the curve is monotonic vertically) */
public void drawSmoothly(Curve curve) {
final int smooth=15;
double cx=0, cy=0, slope;
for(int n=curve.list.size(), i=0; i<n; i++) {
CubicCurve2D.Double c=new CubicCurve2D.Double(), c2=(i+1<n)?curve.list.get(i+1):null;
c.setCurve(curve.list.get(i));
if (i>0) { c.ctrlx1=cx; c.ctrly1=cy; }
if (c2==null) { draw(c,false); return; }
if ((c.x1<c.x2 && c2.x2<c2.x1) || (c.x1>c.x2 && c2.x2>c2.x1)) slope=0; else slope=(c2.x2-c.x1)/(c2.y2-c.y1);
double tmp=c.y2-smooth, tmpx=c.x2-smooth*slope;
if (tmp>c.ctrly1 && tmp<c.y2 && in(c.x1, tmpx, c.x2)) { c.ctrly2=tmp; c.ctrlx2=tmpx; }
double tmp2=c2.y1+smooth, tmp2x=c2.x1+smooth*slope;
if (tmp2>c2.y1 && tmp2<c2.ctrly2 && in(c2.x1, tmp2x, c2.x2)) { cy=tmp2; cx=tmp2x; } else { cy=c2.ctrly1; cx=c2.ctrlx1; }
draw(c,false);
}
}
示例6: chopStart
import java.awt.geom.CubicCurve2D; //导入依赖的package包/类
/** Chop the start of this curve. */
public void chopStart(double t) {
int n=list.size();
t=t*n;
double di=StrictMath.floor(t);
int i=(int)di;
//
if (i<0) return;
if (i>=n) list.clear();
while(i>0 && !list.isEmpty()) { list.remove(0); i--; }
if (list.isEmpty()) { list.add(new CubicCurve2D.Double(startX=endX, startY=endY, endX,endY, endX,endY, endX,endY)); return; }
CubicCurve2D.Double tmp=new CubicCurve2D.Double();
divide(t-di, list.get(0), new CubicCurve2D.Double(), tmp);
list.get(0).setCurve(tmp);
startX=tmp.x1;
startY=tmp.y1;
}
示例7: chopEnd
import java.awt.geom.CubicCurve2D; //导入依赖的package包/类
/** Chop the end of this curve. */
public void chopEnd(double t) {
int n=list.size();
t=t*n;
double di=StrictMath.floor(t);
int i=(int)di;
//
if (i<0) list.clear();
if (i>=n) return;
while(i+1<list.size()) list.remove(i+1);
if (list.isEmpty()) { endX=startX; endY=startY; list.add(new CubicCurve2D.Double(endX,endY, endX,endY, endX,endY, endX,endY)); return; }
CubicCurve2D.Double tmp=new CubicCurve2D.Double();
divide(t-di, list.get(i), tmp, new CubicCurve2D.Double());
list.get(i).setCurve(tmp);
endX=tmp.x2;
endY=tmp.y2;
}
示例8: divide
import java.awt.geom.CubicCurve2D; //导入依赖的package包/类
/** Given 0<=t<=1 and an existing curve, divide it into two chunks and store the two chunks into "first" and "second" */
public static void divide(double t, CubicCurve2D.Double curve, CubicCurve2D.Double first, CubicCurve2D.Double second) {
// This algorithm uses de Casteljau's algorithm for chopping one bezier curve into two bezier curves
first.x1 = curve.x1;
second.x2 = curve.x2;
first.ctrlx1 = (1-t)*curve.x1 + t*curve.ctrlx1;
double x = (1-t)*curve.ctrlx1 + t*curve.ctrlx2;
second.ctrlx2 = (1-t)*curve.ctrlx2 + t*curve.x2;
first.ctrlx2 = (1-t)*first.ctrlx1 + t*x;
second.ctrlx1 = (1-t)*x + t*second.ctrlx2;
second.x1 = first.x2 = (1-t)*first.ctrlx2 + t*second.ctrlx1;
// now that we've computed the x coordinates, we now compute the y coordinates
first.y1 = curve.y1;
second.y2 = curve.y2;
first.ctrly1 = (1-t)*curve.y1 + t*curve.ctrly1;
double y = (1-t)*curve.ctrly1 + t*curve.ctrly2;
second.ctrly2 = (1-t)*curve.ctrly2 + t*curve.y2;
first.ctrly2 = (1-t)*first.ctrly1 + t*y;
second.ctrly1 = (1-t)*y + t*second.ctrly2;
second.y1 = first.y2 = (1-t)*first.ctrly2 + t*second.ctrly1;
}
示例9: getRegiaoDocumento
import java.awt.geom.CubicCurve2D; //导入依赖的package包/类
public Shape getRegiaoDocumento() {
if (Regiao == null) {
final int v1 = getHeight() / 3;
final int h1 = getWidth() / 2;
final int repo = v1 / 3;
final int L = getLeft();
final int T = getTop();
final int TH = T + getHeight() - repo;
final int LW = L + getWidth();
CubicCurve2D c = new CubicCurve2D.Double();
c.setCurve(L, TH, L + h1, TH + v1, LW - h1, TH - v1, LW, TH);
GeneralPath pa = new GeneralPath();
pa.moveTo(LW, TH);
pa.lineTo(LW, T);
pa.lineTo(L, T);
pa.lineTo(L, TH);
pa.append(c, true);
Regiao = pa;
final int ptToMove = 3;
this.reposicionePonto[ptToMove] = new Point(0, -repo);
ptsToMove[ptToMove] = 1;
}
return Regiao;
}
示例10: getRegiao
import java.awt.geom.CubicCurve2D; //导入依赖的package包/类
@Override
public Shape getRegiao() {
if (Regiao == null) {
final int v1 = getHeight() / 3;
final int h1 = getWidth() / 2;
final int repo = v1 / 3;
final int L = getLeft();
final int T = getTop();
final int TH = T + getHeight() - repo;
final int LW = L + getWidth();
CubicCurve2D c = new CubicCurve2D.Double();
c.setCurve(L, TH, L + h1, TH + v1, LW - h1, TH - v1, LW, TH);
GeneralPath pa = new GeneralPath();
pa.moveTo(LW, TH);
pa.lineTo(LW, T);
pa.lineTo(L, T);
pa.lineTo(L, TH);
pa.append(c, true);
Regiao = pa;
setReposicionePontoAbaixo(new Point(0, -repo));
ptsToMove[ptToMove] = 1;
}
return Regiao;
}
示例11: paint
import java.awt.geom.CubicCurve2D; //导入依赖的package包/类
@Override
protected void paint (Graphics2D g,
Params p,
Point location,
Alignment alignment)
{
Point loc = alignment.translatedPoint(TOP_LEFT, p.rect, location);
CubicCurve2D curve = new CubicCurve2D.Double(
loc.x,
loc.y + p.rect.height,
loc.x + ((3 * p.rect.width) / 10),
loc.y + (p.rect.height / 5),
loc.x + (p.rect.width / 2),
loc.y,
loc.x + p.rect.width,
loc.y);
// Slur
g.draw(curve);
}
示例12: drawRoute
import java.awt.geom.CubicCurve2D; //导入依赖的package包/类
public void drawRoute(Graphics2D g, double lon1, double lat1, double lon2, double lat2, boolean straight, boolean dashed) {
int x1 = translateLongitudeToX(lon1);
int y1 = translateLatitudeToY(lat1);
int x2 = translateLongitudeToX(lon2);
int y2 = translateLatitudeToY(lat2);
if (dashed) {
g.setStroke(TangoColorFactory.FAT_DASHED_STROKE);
}
if (straight) {
g.drawLine(x1, y1, x2, y2);
} else {
double xDistPart = (x2 - x1) / 3.0;
double yDistPart = (y2 - y1) / 3.0;
double ctrlx1 = x1 + xDistPart + yDistPart;
double ctrly1 = y1 - xDistPart + yDistPart;
double ctrlx2 = x2 - xDistPart - yDistPart;
double ctrly2 = y2 + xDistPart - yDistPart;
g.draw(new CubicCurve2D.Double(x1, y1, ctrlx1, ctrly1, ctrlx2, ctrly2, x2, y2));
}
if (dashed) {
g.setStroke(TangoColorFactory.NORMAL_STROKE);
}
}
示例13: draw
import java.awt.geom.CubicCurve2D; //导入依赖的package包/类
@Override
public void draw(DrawRequest r) {
Graphics2D g = r.getGraphics();
PartialCurveInfo curveInfo = getCurveInfo();
CubicCurve2D visibleCurve = getVisibleCurve();
Color color = Coloriser.colorise(connectionInfo.getDrawColor(), r.getDecoration().getColorisation());
g.setColor(color);
g.setStroke(connectionInfo.getStroke());
g.draw(visibleCurve);
if (connectionInfo.hasArrow()) {
DrawHelper.drawArrowHead(g, curveInfo.headPosition, curveInfo.headOrientation,
connectionInfo.getArrowLength(), connectionInfo.getArrowWidth(), color);
}
if (connectionInfo.hasBubble()) {
DrawHelper.drawBubbleHead(g, curveInfo.headPosition, curveInfo.headOrientation,
connectionInfo.getBubbleSize(), color, connectionInfo.getStroke());
}
}
示例14: getNearestPointOnCurve
import java.awt.geom.CubicCurve2D; //导入依赖的package包/类
@Override
public Point2D getNearestPointOnCurve(Point2D pt) {
// FIXME: should be done using some proper algorithm
CubicCurve2D curve = getCurve();
Point2D nearest = new Point2D.Double(curve.getX1(), curve.getY1());
double nearestDist = Double.MAX_VALUE;
for (double t = 0.01; t <= 1.0; t += 0.01) {
Point2D samplePoint = Geometry.getPointOnCubicCurve(curve, t);
double distance = pt.distance(samplePoint);
if (distance < nearestDist) {
nearestDist = distance;
nearest = samplePoint;
}
}
return nearest;
}
示例15: test_drawCubicCurve
import java.awt.geom.CubicCurve2D; //导入依赖的package包/类
/**
* Draws random cubic curves within the given dimensions.
*
* @param g The Graphics2D object that is used to paint.
* @param size The size of the canvas.
*/
private void test_drawCubicCurve(Graphics2D g, Dimension size)
{
int maxTests = testSize;
int minSize = 10;
long startTime = System.currentTimeMillis();
for (int i = 0; i < maxTests; i += 1)
{
setRandom(g, size);
int x1 = (int) (Math.random() * (size.width - minSize));
int y1 = (int) (Math.random() * (size.height - minSize));
int xc1 = (int) (Math.random() * (size.width - minSize));
int yc1 = (int) (Math.random() * (size.height - minSize));
int xc2 = (int) (Math.random() * (size.width - minSize));
int yc2 = (int) (Math.random() * (size.height - minSize));
int x2 = (int) (Math.random() * (size.width - minSize));
int y2 = (int) (Math.random() * (size.height - minSize));
CubicCurve2D curve = new CubicCurve2D.Double(x1, y1, xc1, yc1, xc2,
yc2, x2, y2);
g.draw(curve);
}
long endTime = System.currentTimeMillis();
recordTest("draw(CubicCurve2D.Double) " + maxTests + " times",
(endTime - startTime));
}