use of java.awt.geom.Point2D in project jdk8u_jdk by JetBrains.
the class CWarningWindow method reposition.
/**
* @param x,y,w,h coordinates of the untrusted window
*/
public void reposition(int x, int y, int w, int h) {
final Point2D point = AWTAccessor.getWindowAccessor().calculateSecurityWarningPosition(ownerWindow, x, y, w, h);
setBounds((int) point.getX(), (int) point.getY(), getWidth(), getHeight());
}
use of java.awt.geom.Point2D in project jdk8u_jdk by JetBrains.
the class BufferedPaints method setLinearGradientPaint.
/********************** LinearGradientPaint support *************************/
/**
* This method uses techniques that are nearly identical to those
* employed in setGradientPaint() above. The primary difference
* is that at the native level we use a fragment shader to manually
* apply the plane equation constants to the current fragment position
* to calculate the gradient position in the range [0,1] (the native
* code for GradientPaint does the same, except that it uses OpenGL's
* automatic texture coordinate generation facilities).
*
* One other minor difference worth mentioning is that
* setGradientPaint() calculates the plane equation constants
* such that the gradient end points are positioned at 0.25 and 0.75
* (for reasons discussed in the comments for that method). In
* contrast, for LinearGradientPaint we setup the equation constants
* such that the gradient end points fall at 0.0 and 1.0. The
* reason for this difference is that in the fragment shader we
* have more control over how the gradient values are interpreted
* (depending on the paint's CycleMethod).
*/
private static void setLinearGradientPaint(RenderQueue rq, SunGraphics2D sg2d, LinearGradientPaint paint, boolean useMask) {
boolean linear = (paint.getColorSpace() == ColorSpaceType.LINEAR_RGB);
Color[] colors = paint.getColors();
int numStops = colors.length;
Point2D pt1 = paint.getStartPoint();
Point2D pt2 = paint.getEndPoint();
AffineTransform at = paint.getTransform();
at.preConcatenate(sg2d.transform);
if (!linear && numStops == 2 && paint.getCycleMethod() != CycleMethod.REPEAT) {
// delegate to the optimized two-color gradient codepath
boolean isCyclic = (paint.getCycleMethod() != CycleMethod.NO_CYCLE);
setGradientPaint(rq, at, colors[0], colors[1], pt1, pt2, isCyclic, useMask);
return;
}
int cycleMethod = paint.getCycleMethod().ordinal();
float[] fractions = paint.getFractions();
int[] pixels = convertToIntArgbPrePixels(colors, linear);
// calculate plane equation constants
double x = pt1.getX();
double y = pt1.getY();
at.translate(x, y);
// now gradient point 1 is at the origin
x = pt2.getX() - x;
y = pt2.getY() - y;
double len = Math.sqrt(x * x + y * y);
at.rotate(x, y);
// now gradient point 2 is on the positive x-axis
at.scale(len, 1);
// now gradient point 1 is at (0.0, 0), point 2 is at (1.0, 0)
float p0, p1, p3;
try {
at.invert();
p0 = (float) at.getScaleX();
p1 = (float) at.getShearX();
p3 = (float) at.getTranslateX();
} catch (java.awt.geom.NoninvertibleTransformException e) {
p0 = p1 = p3 = 0.0f;
}
// assert rq.lock.isHeldByCurrentThread();
rq.ensureCapacity(20 + 12 + (numStops * 4 * 2));
RenderBuffer buf = rq.getBuffer();
buf.putInt(SET_LINEAR_GRADIENT_PAINT);
buf.putInt(useMask ? 1 : 0);
buf.putInt(linear ? 1 : 0);
buf.putInt(cycleMethod);
buf.putInt(numStops);
buf.putFloat(p0);
buf.putFloat(p1);
buf.putFloat(p3);
buf.put(fractions);
buf.put(pixels);
}
use of java.awt.geom.Point2D in project JMRI by JMRI.
the class MathUtil method drawBezier.
// recursive routine to draw a cubic Bezier...
// (also returns distance!)
private static double drawBezier(Graphics2D g2, Point2D p0, Point2D p1, Point2D p2, Point2D p3, int depth) {
double result = 0;
// calculate flatness to determine if we need to recurse...
double l01 = distance(p0, p1);
double l12 = distance(p1, p2);
double l23 = distance(p2, p3);
double l03 = distance(p0, p3);
double flatness = (l01 + l12 + l23) / l03;
// (I just kept moving it closer to 1 until I got good results. ;-)
if ((depth > 12) || (flatness <= 1.001)) {
g2.draw(new Line2D.Double(p0, p3));
result = l03;
} else {
// first order midpoints
Point2D q0 = midPoint(p0, p1);
Point2D q1 = midPoint(p1, p2);
Point2D q2 = midPoint(p2, p3);
// second order midpoints
Point2D r0 = midPoint(q0, q1);
Point2D r1 = midPoint(q1, q2);
// oneThirdPoint order midPoint
Point2D s = midPoint(r0, r1);
// draw left side Bezier
result = drawBezier(g2, p0, q0, r0, s, depth + 1);
// draw right side Bezier
result += drawBezier(g2, s, r1, q2, p3, depth + 1);
}
return result;
}
use of java.awt.geom.Point2D in project JMRI by JMRI.
the class MathUtil method drawBezier.
// recursive routine to draw a Bezier curve...
// (also returns distance!)
private static double drawBezier(Graphics2D g2, Point2D[] points, int depth) {
int len = points.length, idx, jdx;
double result = 0;
// calculate flatness to determine if we need to recurse...
double outer_distance = 0;
for (idx = 1; idx < len; idx++) {
outer_distance += MathUtil.distance(points[idx - 1], points[idx]);
}
double inner_distance = MathUtil.distance(points[0], points[len - 1]);
double flatness = outer_distance / inner_distance;
// (I just kept moving it closer to 1 until I got good results. ;-)
if ((depth > 12) || (flatness <= 1.001)) {
g2.draw(new Line2D.Double(points[0], points[len - 1]));
result = inner_distance;
} else {
// calculate (len - 1) order of points
// (zero'th order are the input points)
Point2D[][] nthOrderPoints = new Point2D[len - 1][];
for (idx = 0; idx < len - 1; idx++) {
nthOrderPoints[idx] = new Point2D[len - 1 - idx];
for (jdx = 0; jdx < len - 1 - idx; jdx++) {
if (idx == 0) {
nthOrderPoints[idx][jdx] = midPoint(points[jdx], points[jdx + 1]);
} else {
nthOrderPoints[idx][jdx] = midPoint(nthOrderPoints[idx - 1][jdx], nthOrderPoints[idx - 1][jdx + 1]);
}
}
}
// collect left points
Point2D[] leftPoints = new Point2D[len];
leftPoints[0] = points[0];
for (idx = 0; idx < len - 1; idx++) {
leftPoints[idx + 1] = nthOrderPoints[idx][0];
}
// draw left side Bezier
result = drawBezier(g2, leftPoints, depth + 1);
// collect right points
Point2D[] rightPoints = new Point2D[len];
for (idx = 0; idx < len - 1; idx++) {
rightPoints[idx] = nthOrderPoints[len - 2 - idx][idx];
}
rightPoints[idx] = points[len - 1];
// draw right side Bezier
result += drawBezier(g2, rightPoints, depth + 1);
}
return result;
}
use of java.awt.geom.Point2D in project JMRI by JMRI.
the class MathUtil method scale.
/**
* scale a rectangle
* @param r the rectangle
* @param s the scale
* @return the scaled rectangle
*/
public static Rectangle2D scale(Rectangle2D r, double s) {
Point2D c = center(r);
double w = r.getWidth() * s, h = r.getHeight() * s;
return new Rectangle2D.Double(c.getX() - (w / 2), c.getY() - (h / 2), w, h);
}
Aggregations