Example usage for java.lang Math toRadians

List of usage examples for java.lang Math toRadians

Introduction

In this page you can find the example usage for java.lang Math toRadians.

Prototype

public static double toRadians(double angdeg) 

Source Link

Document

Converts an angle measured in degrees to an approximately equivalent angle measured in radians.

Usage

From source file:com.github.lucapino.sheetmaker.renderer.JavaTemplateRenderer.java

public void drawString(Graphics g, String text, RectangularShape bounds, Align align, double angle,
        boolean multiline) {
    Graphics2D g2 = (Graphics2D) g;
    Font font = g2.getFont();/*from   w  w  w  . jav  a  2s.co m*/
    if (angle != 0) {
        g2.setFont(font.deriveFont(AffineTransform.getRotateInstance(Math.toRadians(angle))));
    }

    Rectangle2D sSize = g2.getFontMetrics().getStringBounds(text, g2);
    Point2D pos = getPoint(bounds, align);
    double x = pos.getX();
    double y = pos.getY() + sSize.getHeight();

    switch (align) {
    case TopCenter:
    case BottomCenter:
    case Center:
        x -= (sSize.getWidth() / 2);
        break;
    case TopRight:
    case MiddleRight:
    case BottomRight:
        x -= (sSize.getWidth());
        break;
    case BottomLeft:
    case MiddleLeft:
    case TopLeft:
        break;
    }
    if (multiline) {
        // Create a new LineBreakMeasurer from the paragraph.
        // It will be cached and re-used.
        //if (lineMeasurer == null) {
        AttributedCharacterIterator paragraph = new AttributedString(text).getIterator();
        paragraphStart = paragraph.getBeginIndex();
        paragraphEnd = paragraph.getEndIndex();
        FontRenderContext frc = g2.getFontRenderContext();
        lineMeasurer = new LineBreakMeasurer(paragraph, frc);
        //}

        // Set break width to width of Component.
        float breakWidth = (float) bounds.getWidth();
        float drawPosY = (float) y;
        // Set position to the index of the first character in the paragraph.
        lineMeasurer.setPosition(paragraphStart);

        // Get lines until the entire paragraph has been displayed.
        while (lineMeasurer.getPosition() < paragraphEnd) {

            // Retrieve next layout. A cleverer program would also cache
            // these layouts until the component is re-sized.
            TextLayout layout = lineMeasurer.nextLayout(breakWidth);

            // Compute pen x position. If the paragraph is right-to-left we
            // will align the TextLayouts to the right edge of the panel.
            // Note: this won't occur for the English text in this sample.
            // Note: drawPosX is always where the LEFT of the text is placed.
            float drawPosX = layout.isLeftToRight() ? (float) x : (float) x + breakWidth - layout.getAdvance();

            // Move y-coordinate by the ascent of the layout.
            drawPosY += layout.getAscent();

            // Draw the TextLayout at (drawPosX, drawPosY).
            layout.draw(g2, drawPosX, drawPosY);

            // Move y-coordinate in preparation for next layout.
            drawPosY += layout.getDescent() + layout.getLeading();
        }
    } else {
        g2.drawString(text, (float) x, (float) y);
    }
    g2.setFont(font);
}

From source file:org.jrman.parser.Parser.java

public void addSphere(final float radius, float zMin, float zMax, float tMax, final ParameterList parameters) {
    if (inAreaLightSource)
        return;/*from w w w  .j a v a 2 s . co m*/
    final float phiMin = (float) ((zMin <= -radius) ? -Math.PI / 2 : Math.asin(zMin / radius));
    final float phiMax = (float) ((zMax >= radius) ? Math.PI / 2 : Math.asin(zMax / radius));
    final float thetaMin = 0f;
    final float thetaMax = (float) Math.toRadians(tMax);
    if (!inObject) {
        renderer.addPrimitive(
                new Sphere(radius, phiMin, phiMax, thetaMin, thetaMax, parameters, getAttributes()));
        sphereCount++;
    } else {
        final Transform transform = currentAttributes.getTransform();
        currentObjectInstanceList.addPrimitiveCreator(new ObjectInstanceList.PrimitiveCreator() {
            public Primitive create(Attributes attributes) {
                sphereCount++;
                return new Sphere(radius, phiMin, phiMax, thetaMin, thetaMax, parameters,
                        createAttributes(transform, attributes));
            }
        });
    }
}

From source file:jp.furplag.util.commons.NumberUtilsTest.java

/**
 * {@link jp.furplag.util.commons.NumberUtils#cos(long)}.
 *//*from   w  w  w. j  a v a2 s. c o m*/
@Test
public void testCosLong() {
    long l = -720L;
    while (l <= 720L) {
        assertEquals("deg: " + l, (Object) Math.cos(Math.toRadians(l)), cos(l));
        l++;
    }
}

From source file:com.jjoe64.graphview.GridLabelRenderer.java

/**
 * calculates the horizontal label size//w w  w .j a  v a  2s  . com
 * @param canvas canvas
 */
protected void calcLabelHorizontalSize(Canvas canvas) {
    // test label
    double testX = ((mGraphView.getViewport().getMaxX(false) - mGraphView.getViewport().getMinX(false)) * 0.783)
            + mGraphView.getViewport().getMinX(false);
    String testLabel = mLabelFormatter.formatLabel(testX, true);
    if (testLabel == null) {
        testLabel = "";
    }
    Rect textBounds = new Rect();
    mPaintLabel.getTextBounds(testLabel, 0, testLabel.length(), textBounds);
    mLabelHorizontalWidth = textBounds.width();

    if (!mLabelHorizontalHeightFixed) {
        mLabelHorizontalHeight = textBounds.height();

        // multiline
        int lines = 1;
        for (byte c : testLabel.getBytes()) {
            if (c == '\n')
                lines++;
        }
        mLabelHorizontalHeight *= lines;

        mLabelHorizontalHeight = (int) Math.max(mLabelHorizontalHeight, mStyles.textSize);
    }

    if (mStyles.horizontalLabelsAngle > 0f && mStyles.horizontalLabelsAngle <= 180f) {
        int adjHorizontalHeightH = (int) Math.round(
                Math.abs(mLabelHorizontalHeight * Math.cos(Math.toRadians(mStyles.horizontalLabelsAngle))));
        int adjHorizontalHeightW = (int) Math.round(
                Math.abs(mLabelHorizontalWidth * Math.sin(Math.toRadians(mStyles.horizontalLabelsAngle))));
        int adjHorizontalWidthH = (int) Math.round(
                Math.abs(mLabelHorizontalHeight * Math.sin(Math.toRadians(mStyles.horizontalLabelsAngle))));
        int adjHorizontalWidthW = (int) Math.round(
                Math.abs(mLabelHorizontalWidth * Math.cos(Math.toRadians(mStyles.horizontalLabelsAngle))));

        mLabelHorizontalHeight = adjHorizontalHeightH + adjHorizontalHeightW;
        mLabelHorizontalWidth = adjHorizontalWidthH + adjHorizontalWidthW;
    }

    // space between text and graph content
    mLabelHorizontalHeight += mStyles.labelsSpace;
}

From source file:cw.kop.autobackground.settings.WearSettingsFragment.java

private void drawAnalog() {
    if (!AppSettings.getTimeType().equals(AppSettings.ANALOG)) {
        return;/*ww  w .j  a v  a  2s .c  om*/
    }

    canvas = surfaceView.getHolder().lockCanvas();

    if (canvas == null) {
        return;
    }

    setPaints();

    if (imageBitmap != null) {
        canvas.drawBitmap(imageBitmap, 0, 0, bitmapPaint);
    }
    //        Time time = new Time();
    //        time.setToNow();
    //        time.set(time.toMillis(false) + AppSettings.getTimeOffset());
    //
    //        float hour = time.hour + time.minute / 60f;
    //        float minute = time.minute + time.second / 60f;
    //        float second = time.second;
    float centerX = watchContainer.getWidth() * 0.222f;
    float centerY = watchContainer.getHeight() * 0.222f;
    float radius = centerX;
    // Draw tick marks

    for (int i = 0; i < 12; i++) {
        canvas.drawLine((float) (centerX + (radius * tickRadius / 100f) * Math.cos(Math.toRadians(i * 30f))),
                (float) (centerY + (radius * tickRadius / 100f) * Math.sin(Math.toRadians(i * 30f))),
                (float) (centerX + (radius) * Math.cos(Math.toRadians(i * 30f))),
                (float) (centerY + (radius) * Math.sin(Math.toRadians(i * 30f))), tickPaint);
    }

    // Draw clock hands

    // Draw shadows first to prevent outline overlapping other hands

    Path hourShadowPath = new Path();
    hourShadowPath.moveTo((float) (centerX + hourWidth / 1.5f * Math.cos(Math.toRadians(90f))),
            (float) (centerY + hourWidth / 1.5f * Math.sin(Math.toRadians(90f))));
    hourShadowPath.quadTo((float) (centerX - (hourWidth / 1.5f) * Math.cos(Math.toRadians(0f))),
            (float) (centerY - (hourWidth / 1.5f) * Math.sin(Math.toRadians(0f))),
            (float) (centerX + hourWidth / 1.5f * Math.cos(Math.toRadians(270f))),
            (float) (centerY + hourWidth / 1.5f * Math.sin(Math.toRadians(270f))));
    hourShadowPath.lineTo(
            (float) (centerX + (radius * hourRadius / 100f + 2.0f) * Math.cos(Math.toRadians(0f))),
            (float) (centerY + (radius * hourRadius / 100f + 2.0f) * Math.sin(Math.toRadians(0f))));
    hourShadowPath.close();
    canvas.drawPath(hourShadowPath, hourShadowPaint);

    Path minuteShadowPath = new Path();
    minuteShadowPath.moveTo((float) (centerX + minuteWidth / 1.5f * Math.cos(Math.toRadians(0f))),
            (float) (centerY + minuteWidth / 1.5f * Math.sin(Math.toRadians(0f))));
    minuteShadowPath.quadTo((float) (centerX - (minuteWidth / 1.5f) * Math.cos(Math.toRadians(-180f))),
            (float) (centerY - (minuteWidth / 1.5f) * Math.sin(Math.toRadians(-180f))),
            (float) (centerX + minuteWidth / 1.5f * Math.cos(Math.toRadians(90f))),
            (float) (centerY + minuteWidth / 1.5f * Math.sin(Math.toRadians(90f))));
    minuteShadowPath.lineTo(
            (float) (centerX + (radius * minuteRadius / 100f + 2.0f) * Math.cos(Math.toRadians(-90f))),
            (float) (centerY + (radius * minuteRadius / 100f + 2.0f) * Math.sin(Math.toRadians(-90f))));
    minuteShadowPath.close();
    canvas.drawPath(minuteShadowPath, minuteShadowPaint);

    Path secondShadowPath = new Path();
    secondShadowPath.moveTo((float) (centerX + secondWidth / 1.5f * Math.cos(Math.toRadians(225f))),
            (float) (centerY + secondWidth / 1.5f * Math.sin(Math.toRadians(225f))));
    secondShadowPath.quadTo((float) (centerX - (secondWidth / 1.5f) * Math.cos(Math.toRadians(45f))),
            (float) (centerY - (secondWidth / 1.5f) * Math.sin(Math.toRadians(45f))),
            (float) (centerX + secondWidth / 1.5f * Math.cos(Math.toRadians(315f))),
            (float) (centerY + secondWidth / 1.5f * Math.sin(Math.toRadians(315f))));
    secondShadowPath.lineTo(
            (float) (centerX + (radius * secondRadius / 100f + 2f) * Math.cos(Math.toRadians(135f))),
            (float) (centerY + (radius * secondRadius / 100f + 2.0f) * Math.sin(Math.toRadians(135f))));
    secondShadowPath.close();
    canvas.drawPath(secondShadowPath, secondShadowPaint);

    // Now draw actual hands

    Path hourPath = new Path();
    hourPath.moveTo((float) (centerX + hourWidth / 2f * Math.cos(Math.toRadians(90f))),
            (float) (centerY + hourWidth / 2f * Math.sin(Math.toRadians(90f))));
    hourPath.quadTo((float) (centerX - (hourWidth / 2f) * Math.cos(Math.toRadians(0f))),
            (float) (centerY - (hourWidth / 2f) * Math.sin(Math.toRadians(0f))),
            (float) (centerX + hourWidth / 2f * Math.cos(Math.toRadians(270f))),
            (float) (centerY + hourWidth / 2f * Math.sin(Math.toRadians(270f))));
    hourPath.lineTo((float) (centerX + (radius * hourRadius / 100f) * Math.cos(Math.toRadians(0f))),
            (float) (centerY + (radius * hourRadius / 100f) * Math.sin(Math.toRadians(0f))));
    hourPath.close();
    canvas.drawPath(hourPath, hourPaint);

    Path minutePath = new Path();
    minutePath.moveTo((float) (centerX + minuteWidth / 2f * Math.cos(Math.toRadians(0f))),
            (float) (centerY + minuteWidth / 2f * Math.sin(Math.toRadians(0f))));
    minutePath.quadTo((float) (centerX - (minuteWidth / 2f) * Math.cos(Math.toRadians(-180f))),
            (float) (centerY - (minuteWidth / 2f) * Math.sin(Math.toRadians(-180f))),
            (float) (centerX + minuteWidth / 2f * Math.cos(Math.toRadians(90f))),
            (float) (centerY + minuteWidth / 2f * Math.sin(Math.toRadians(90f))));
    minutePath.lineTo((float) (centerX + (radius * minuteRadius / 100f) * Math.cos(Math.toRadians(-90f))),
            (float) (centerY + (radius * minuteRadius / 100f) * Math.sin(Math.toRadians(-90f))));
    minutePath.close();
    canvas.drawPath(minutePath, minutePaint);

    Path secondPath = new Path();
    secondPath.moveTo((float) (centerX + secondWidth / 2f * Math.cos(Math.toRadians(225f))),
            (float) (centerY + secondWidth / 2f * Math.sin(Math.toRadians(225f))));
    secondPath.quadTo((float) (centerX - (secondWidth / 2f) * Math.cos(Math.toRadians(45f))),
            (float) (centerY - (secondWidth / 2f) * Math.sin(Math.toRadians(45f))),
            (float) (centerX + secondWidth / 2f * Math.cos(Math.toRadians(315f))),
            (float) (centerY + secondWidth / 2f * Math.sin(Math.toRadians(315f))));
    secondPath.lineTo((float) (centerX + (radius * secondRadius / 100f) * Math.cos(Math.toRadians(135f))),
            (float) (centerY + (radius * secondRadius / 100f) * Math.sin(Math.toRadians(135f))));
    secondPath.close();
    canvas.drawPath(secondPath, secondPaint);

    surfaceView.getHolder().unlockCanvasAndPost(canvas);
}

From source file:org.eclipse.birt.chart.device.g2d.G2dRendererBase.java

@Override
public void drawArc(ArcRenderEvent are) throws ChartException {
    if (iv != null) {
        iv.modifyEvent(are);//  w  w  w  .  java 2  s. c  om
    }

    // CHECK IF THE LINE ATTRIBUTES ARE CORRECTLY DEFINED
    final LineAttributes lia = are.getOutline();
    if (!validateLineAttributes(are.getSource(), lia)) {
        return;
    }

    // SETUP THE FOREGROUND COLOR (DARKER BACKGROUND IF DEFINED AS NULL)
    final Color cFG = (Color) validateEdgeColor(lia.getColor(), are.getBackground(), _ids);
    if (cFG == null || cFG.getAlpha() == 0) {
        return;
    }

    // DRAW THE ARC
    Stroke sPrevious = null;
    Stroke sCurrent = getCachedStroke(lia);
    if (sCurrent != null) // SOME STROKE DEFINED?
    {
        sPrevious = _g2d.getStroke();
        _g2d.setStroke(sCurrent);
    }
    _g2d.setColor(cFG);

    if ((are.getInnerRadius() >= 0 && are.getOuterRadius() > 0 && are.getInnerRadius() < are.getOuterRadius())
            || (are.getInnerRadius() > 0 && are.getOuterRadius() <= 0)) {
        Bounds rctOuter = getOuterRectangle(are);
        Bounds rctInner = getInnerRectangle(are);

        Shape outerArc = new Arc2D.Double(rctOuter.getLeft(), rctOuter.getTop(), rctOuter.getWidth(),
                rctOuter.getHeight(), are.getStartAngle(), are.getAngleExtent(), Arc2D.OPEN);
        Shape innerArc = new Arc2D.Double(rctInner.getLeft(), rctInner.getTop(), rctInner.getWidth(),
                rctInner.getHeight(), are.getStartAngle() + are.getAngleExtent(), -are.getAngleExtent(),
                Arc2D.OPEN);

        double startAngle = Math.toRadians(-are.getStartAngle());
        double stopAngle = Math.toRadians(-are.getStartAngle() - are.getAngleExtent());

        double xsOuter = (rctOuter.getLeft() + (Math.cos(startAngle) * 0.5 + 0.5) * rctOuter.getWidth());
        double ysOuter = (rctOuter.getTop() + (Math.sin(startAngle) * 0.5 + 0.5) * rctOuter.getHeight());

        double xeInner = (rctInner.getLeft() + (Math.cos(stopAngle) * 0.5 + 0.5) * rctInner.getWidth());
        double yeInner = (rctInner.getTop() + (Math.sin(stopAngle) * 0.5 + 0.5) * rctInner.getHeight());

        GeneralPath gp = new GeneralPath();
        gp.append(outerArc, false);
        gp.lineTo((float) xeInner, (float) yeInner);
        gp.append(innerArc, false);
        gp.lineTo((float) xsOuter, (float) ysOuter);

        Area area = new Area(gp);
        Shape prevClip = _g2d.getClip();
        Area ar2 = new Area(area);
        if (prevClip != null) {
            Area ar1 = new Area(prevClip);
            ar2.intersect(ar1);
        }
        _g2d.setClip(ar2);
        _g2d.draw(area);
        _g2d.setClip(prevClip);

    } else {
        _g2d.draw(new Arc2D.Double(are.getTopLeft().getX(), are.getTopLeft().getY(), are.getWidth(),
                are.getHeight(), are.getStartAngle(), are.getAngleExtent(), toG2dArcType(are.getStyle())));
    }

    if (sPrevious != null) // RESTORE PREVIOUS STROKE
    {
        _g2d.setStroke(sPrevious);
    }
}

From source file:at.alladin.rmbt.controlServer.OpenTestResource.java

/**
 * Calculate the rough distance in meters between two points
 * taken from http://stackoverflow.com/questions/120283/working-with-latitude-longitude-values-in-java
 * @param lat1 /*w w  w  .j av  a2  s  . c  o  m*/
 * @param lng1
 * @param lat2
 * @param lng2
 * @return
 */
private static double distFrom(double lat1, double lng1, double lat2, double lng2) {
    double earthRadius = 6371000;
    double dLat = Math.toRadians(lat2 - lat1);
    double dLng = Math.toRadians(lng2 - lng1);
    double sindLat = Math.sin(dLat / 2);
    double sindLng = Math.sin(dLng / 2);
    double a = Math.pow(sindLat, 2)
            + Math.pow(sindLng, 2) * Math.cos(Math.toRadians(lat1)) * Math.cos(Math.toRadians(lat2));
    double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
    double dist = earthRadius * c;

    return dist;
}

From source file:org.eclipse.birt.chart.device.swt.SwtRendererImpl.java

public void fillArc(ArcRenderEvent are) throws ChartException {
    iv.modifyEvent(are);/*from w w w .  ja v  a2  s  . c  o  m*/

    Fill flBackground = validateMultipleFill(are.getBackground());

    if (isFullTransparent(flBackground) || are.getAngleExtent() == 0) {
        return;
    }

    Bounds bo = goFactory.createBounds(are.getTopLeft().getX(), are.getTopLeft().getY(), are.getWidth(),
            are.getHeight());
    final Rectangle r = new Rectangle((int) ((bo.getLeft() + dTranslateX) * dScale),
            (int) ((bo.getTop() + dTranslateY) * dScale), (int) Math.ceil(bo.getWidth() * dScale),
            (int) Math.ceil(bo.getHeight() * dScale));

    Path pt = new Path(((SwtDisplayServer) _ids).getDevice());

    if (are.getInnerRadius() >= 0 && (are.getOuterRadius() > 0 && are.getInnerRadius() < are.getOuterRadius())
            || (are.getInnerRadius() > 0 && are.getOuterRadius() <= 0)) {
        Bounds rctOuter, rctInner;

        rctOuter = getOuterRectangle(are, dTranslateX, dTranslateY, dScale, bo);

        rctInner = getInnerRectangle(are, dTranslateX, dTranslateY, dScale, bo);

        double startAngle = Math.toRadians(-are.getStartAngle());
        double stopAngle = Math.toRadians(-are.getStartAngle() - are.getAngleExtent());

        double xsOuter = (rctOuter.getLeft() + (Math.cos(startAngle) * 0.5 + 0.5) * rctOuter.getWidth());
        double ysOuter = (rctOuter.getTop() + (Math.sin(startAngle) * 0.5 + 0.5) * rctOuter.getHeight());

        double xeInner = (rctInner.getLeft() + (Math.cos(stopAngle) * 0.5 + 0.5) * rctInner.getWidth());
        double yeInner = (rctInner.getTop() + (Math.sin(stopAngle) * 0.5 + 0.5) * rctInner.getHeight());

        pt.addArc((float) rctOuter.getLeft(), (float) rctOuter.getTop(), (float) rctOuter.getWidth(),
                (float) rctOuter.getHeight(), (float) are.getStartAngle(), (float) are.getAngleExtent());

        pt.lineTo((float) xeInner, (float) yeInner);

        pt.addArc((float) rctInner.getLeft(), (float) rctInner.getTop(), (float) rctInner.getWidth(),
                (float) rctInner.getHeight(), (float) (are.getStartAngle() + are.getAngleExtent()),
                (float) -are.getAngleExtent());

        pt.lineTo((float) xsOuter, (float) ysOuter);
    } else {
        if (are.getStyle() == ArcRenderEvent.SECTOR
                || (are.getStyle() == ArcRenderEvent.CLOSED && Math.abs(are.getAngleExtent()) >= 360)) {
            double xc = ((are.getTopLeft().getX() + dTranslateX + are.getWidth() / 2d) * dScale);
            double yc = ((are.getTopLeft().getY() + dTranslateY + are.getHeight() / 2d) * dScale);

            double xs = 0, ys = 0;
            double angle = Math.toRadians(-are.getStartAngle());

            xs = ((are.getTopLeft().getX() + dTranslateX + (Math.cos(angle) * 0.5 + 0.5) * are.getWidth())
                    * dScale);
            ys = ((are.getTopLeft().getY() + dTranslateY + (Math.sin(angle) * 0.5 + 0.5) * are.getHeight())
                    * dScale);

            if (are.getStyle() == ArcRenderEvent.CLOSED) {
                pt.addArc((float) ((are.getTopLeft().getX() + dTranslateX) * dScale),
                        (float) ((are.getTopLeft().getY() + dTranslateY) * dScale),
                        (float) (are.getWidth() * dScale), (float) (are.getHeight() * dScale),
                        (float) are.getStartAngle(), (float) are.getAngleExtent());
                pt.lineTo((float) xs, (float) ys);
            } else if (are.getStyle() == ArcRenderEvent.SECTOR) {
                pt.addArc((float) ((are.getTopLeft().getX() + dTranslateX) * dScale),
                        (float) ((are.getTopLeft().getY() + dTranslateY) * dScale),
                        (float) (are.getWidth() * dScale), (float) (are.getHeight() * dScale),
                        (float) are.getStartAngle(), (float) are.getAngleExtent());
                pt.lineTo((float) xc, (float) yc);
                pt.lineTo((float) xs, (float) ys);
            }
        }

        // Extra fix due to SWT arc rendering limitation.
        else if (are.getStyle() == ArcRenderEvent.OPEN || are.getStyle() == ArcRenderEvent.CLOSED) {
            double angle = Math.toRadians(-are.getStartAngle());

            double xs = ((are.getTopLeft().getX() + dTranslateX
                    + (Math.cos(angle) * 0.5 + 0.5) * are.getWidth()) * dScale);
            double ys = ((are.getTopLeft().getY() + dTranslateY
                    + (Math.sin(angle) * 0.5 + 0.5) * are.getHeight()) * dScale);

            pt.addArc((float) ((are.getTopLeft().getX() + dTranslateX) * dScale),
                    (float) ((are.getTopLeft().getY() + dTranslateY) * dScale),
                    (float) (are.getWidth() * dScale), (float) (are.getHeight() * dScale),
                    (float) are.getStartAngle(), (float) are.getAngleExtent());

            pt.lineTo((float) xs, (float) ys);
        }
    }

    try {
        if (flBackground instanceof ColorDefinition) {
            fillPathColor(pt, (ColorDefinition) flBackground);
        } else if (flBackground instanceof Gradient) {
            fillPathGradient(pt, (Gradient) flBackground, r);
        } else if (flBackground instanceof org.eclipse.birt.chart.model.attribute.Image) {
            fillPathImage(pt, (org.eclipse.birt.chart.model.attribute.Image) flBackground);
        }
    } finally {
        pt.dispose();
    }

}

From source file:com.appeaser.sublimepickerlibrary.timepicker.RadialTimePickerView.java

private void drawSelector(Canvas canvas, int index, Path selectorPath, float alphaMod) {
    final int alpha = (int) (mAlpha[index % 2].getValue() * alphaMod + 0.5f);
    final int color = applyAlpha(mSelectorColor, alpha);

    // Calculate the current radius at which to place the selection circle.
    final int selRadius = mSelectorRadius;
    final int selLength = mCircleRadius - mTextInset[index];
    final double selAngleRad = Math.toRadians(mSelectionDegrees[index % 2]);
    final float selCenterX = mXCenter + selLength * (float) Math.sin(selAngleRad);
    final float selCenterY = mYCenter - selLength * (float) Math.cos(selAngleRad);

    // Draw the selection circle.
    final Paint paint = mPaintSelector[index % 2][SELECTOR_CIRCLE];
    paint.setColor(color);/*  ww w. jav  a  2 s .  co m*/
    canvas.drawCircle(selCenterX, selCenterY, selRadius, paint);

    // If needed, set up the clip path for later.
    if (selectorPath != null) {
        selectorPath.reset();
        selectorPath.addCircle(selCenterX, selCenterY, selRadius, Path.Direction.CCW);
    }

    // Draw the dot if we're between two items.
    final boolean shouldDrawDot = mSelectionDegrees[index % 2] % 30 != 0;
    if (shouldDrawDot) {
        final Paint dotPaint = mPaintSelector[index % 2][SELECTOR_DOT];
        dotPaint.setColor(mSelectorDotColor);
        canvas.drawCircle(selCenterX, selCenterY, mSelectorDotRadius, dotPaint);
    }

    // Shorten the line to only go from the edge of the center dot to the
    // edge of the selection circle.
    final double sin = Math.sin(selAngleRad);
    final double cos = Math.cos(selAngleRad);
    final int lineLength = selLength - selRadius;
    final int centerX = mXCenter + (int) (mCenterDotRadius * sin);
    final int centerY = mYCenter - (int) (mCenterDotRadius * cos);
    final float linePointX = centerX + (int) (lineLength * sin);
    final float linePointY = centerY - (int) (lineLength * cos);

    // Draw the line.
    final Paint linePaint = mPaintSelector[index % 2][SELECTOR_LINE];
    linePaint.setColor(color);
    linePaint.setStrokeWidth(mSelectorStroke);
    canvas.drawLine(mXCenter, mYCenter, linePointX, linePointY, linePaint);
}

From source file:jp.furplag.util.commons.NumberUtilsTest.java

/**
 * {@link jp.furplag.util.commons.NumberUtils#cos(java.lang.Number)}.
 *//*ww  w  .j  av  a  2s.co  m*/
@SuppressWarnings("unchecked")
@Test
public void testCosNumber() {
    assertEquals("null", (Object) Math.cos(0), cos(null));
    for (Class<?> type : NUMBERS) {
        int i = ObjectUtils.isAny(type, byte.class, Byte.class) ? -128 : -720;
        while (i <= (ObjectUtils.isAny(type, byte.class, Byte.class) ? 127 : 720)) {
            assertEquals("deg: " + i + ": " + type.getSimpleName(), (Object) Math.cos(Math.toRadians(i)),
                    cos(valueOf(i, (Class<? extends Number>) type)));
            i++;
        }
    }
}