src/java.desktop/share/classes/sun/java2d/marlin/Helpers.java
author erikj
Tue, 12 Sep 2017 19:03:39 +0200
changeset 47216 71c04702a3d5
parent 47126 jdk/src/java.desktop/share/classes/sun/java2d/marlin/Helpers.java@188ef162f019
child 48284 fd7fbc929001
permissions -rw-r--r--
8187443: Forest Consolidation: Move files to unified layout Reviewed-by: darcy, ihse
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
     1
/*
47126
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 39519
diff changeset
     2
 * Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved.
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
     4
 *
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    10
 *
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    15
 * accompanied this code).
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    16
 *
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    20
 *
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    23
 * questions.
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    24
 */
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    25
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    26
package sun.java2d.marlin;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    27
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    28
import static java.lang.Math.PI;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    29
import static java.lang.Math.cos;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    30
import static java.lang.Math.sqrt;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    31
import static java.lang.Math.cbrt;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    32
import static java.lang.Math.acos;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    33
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    34
final class Helpers implements MarlinConst {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    35
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    36
    private Helpers() {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    37
        throw new Error("This is a non instantiable class");
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    38
    }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    39
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    40
    static boolean within(final float x, final float y, final float err) {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    41
        final float d = y - x;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    42
        return (d <= err && d >= -err);
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    43
    }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    44
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    45
    static boolean within(final double x, final double y, final double err) {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    46
        final double d = y - x;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    47
        return (d <= err && d >= -err);
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    48
    }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    49
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    50
    static int quadraticRoots(final float a, final float b,
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    51
                              final float c, float[] zeroes, final int off)
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    52
    {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    53
        int ret = off;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    54
        float t;
47126
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 39519
diff changeset
    55
        if (a != 0.0f) {
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    56
            final float dis = b*b - 4*a*c;
47126
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 39519
diff changeset
    57
            if (dis > 0.0f) {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 39519
diff changeset
    58
                final float sqrtDis = (float) Math.sqrt(dis);
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    59
                // depending on the sign of b we use a slightly different
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    60
                // algorithm than the traditional one to find one of the roots
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    61
                // so we can avoid adding numbers of different signs (which
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    62
                // might result in loss of precision).
47126
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 39519
diff changeset
    63
                if (b >= 0.0f) {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 39519
diff changeset
    64
                    zeroes[ret++] = (2.0f * c) / (-b - sqrtDis);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 39519
diff changeset
    65
                    zeroes[ret++] = (-b - sqrtDis) / (2.0f * a);
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    66
                } else {
47126
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 39519
diff changeset
    67
                    zeroes[ret++] = (-b + sqrtDis) / (2.0f * a);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 39519
diff changeset
    68
                    zeroes[ret++] = (2.0f * c) / (-b + sqrtDis);
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    69
                }
47126
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 39519
diff changeset
    70
            } else if (dis == 0.0f) {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 39519
diff changeset
    71
                t = (-b) / (2.0f * a);
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    72
                zeroes[ret++] = t;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    73
            }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    74
        } else {
47126
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 39519
diff changeset
    75
            if (b != 0.0f) {
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    76
                t = (-c) / b;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    77
                zeroes[ret++] = t;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    78
            }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    79
        }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    80
        return ret - off;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    81
    }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    82
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    83
    // find the roots of g(t) = d*t^3 + a*t^2 + b*t + c in [A,B)
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    84
    static int cubicRootsInAB(float d, float a, float b, float c,
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    85
                              float[] pts, final int off,
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    86
                              final float A, final float B)
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    87
    {
47126
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 39519
diff changeset
    88
        if (d == 0.0f) {
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    89
            int num = quadraticRoots(a, b, c, pts, off);
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    90
            return filterOutNotInAB(pts, off, num, A, B) - off;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    91
        }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    92
        // From Graphics Gems:
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    93
        // http://tog.acm.org/resources/GraphicsGems/gems/Roots3And4.c
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    94
        // (also from awt.geom.CubicCurve2D. But here we don't need as
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    95
        // much accuracy and we don't want to create arrays so we use
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    96
        // our own customized version).
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    97
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    98
        // normal form: x^3 + ax^2 + bx + c = 0
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    99
        a /= d;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   100
        b /= d;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   101
        c /= d;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   102
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   103
        //  substitute x = y - A/3 to eliminate quadratic term:
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   104
        //     x^3 +Px + Q = 0
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   105
        //
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   106
        // Since we actually need P/3 and Q/2 for all of the
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   107
        // calculations that follow, we will calculate
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   108
        // p = P/3
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   109
        // q = Q/2
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   110
        // instead and use those values for simplicity of the code.
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   111
        double sq_A = a * a;
47126
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 39519
diff changeset
   112
        double p = (1.0d/3.0d) * ((-1.0d/3.0d) * sq_A + b);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 39519
diff changeset
   113
        double q = (1.0d/2.0d) * ((2.0d/27.0d) * a * sq_A - (1.0d/3.0d) * a * b + c);
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   114
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   115
        // use Cardano's formula
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   116
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   117
        double cb_p = p * p * p;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   118
        double D = q * q + cb_p;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   119
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   120
        int num;
47126
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 39519
diff changeset
   121
        if (D < 0.0d) {
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   122
            // see: http://en.wikipedia.org/wiki/Cubic_function#Trigonometric_.28and_hyperbolic.29_method
47126
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 39519
diff changeset
   123
            final double phi = (1.0d/3.0d) * acos(-q / sqrt(-cb_p));
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 39519
diff changeset
   124
            final double t = 2.0d * sqrt(-p);
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   125
47126
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 39519
diff changeset
   126
            pts[ off+0 ] = (float) ( t * cos(phi));
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 39519
diff changeset
   127
            pts[ off+1 ] = (float) (-t * cos(phi + (PI / 3.0d)));
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 39519
diff changeset
   128
            pts[ off+2 ] = (float) (-t * cos(phi - (PI / 3.0d)));
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   129
            num = 3;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   130
        } else {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   131
            final double sqrt_D = sqrt(D);
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   132
            final double u = cbrt(sqrt_D - q);
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   133
            final double v = - cbrt(sqrt_D + q);
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   134
47126
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 39519
diff changeset
   135
            pts[ off ] = (float) (u + v);
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   136
            num = 1;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   137
47126
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 39519
diff changeset
   138
            if (within(D, 0.0d, 1e-8d)) {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 39519
diff changeset
   139
                pts[off+1] = -(pts[off] / 2.0f);
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   140
                num = 2;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   141
            }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   142
        }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   143
47126
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 39519
diff changeset
   144
        final float sub = (1.0f/3.0f) * a;
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   145
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   146
        for (int i = 0; i < num; ++i) {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   147
            pts[ off+i ] -= sub;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   148
        }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   149
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   150
        return filterOutNotInAB(pts, off, num, A, B) - off;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   151
    }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   152
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   153
    static float evalCubic(final float a, final float b,
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   154
                           final float c, final float d,
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   155
                           final float t)
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   156
    {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   157
        return t * (t * (t * a + b) + c) + d;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   158
    }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   159
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   160
    static float evalQuad(final float a, final float b,
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   161
                          final float c, final float t)
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   162
    {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   163
        return t * (t * a + b) + c;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   164
    }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   165
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   166
    // returns the index 1 past the last valid element remaining after filtering
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   167
    static int filterOutNotInAB(float[] nums, final int off, final int len,
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   168
                                final float a, final float b)
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   169
    {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   170
        int ret = off;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   171
        for (int i = off, end = off + len; i < end; i++) {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   172
            if (nums[i] >= a && nums[i] < b) {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   173
                nums[ret++] = nums[i];
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   174
            }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   175
        }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   176
        return ret;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   177
    }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   178
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   179
    static float polyLineLength(float[] poly, final int off, final int nCoords) {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   180
        assert nCoords % 2 == 0 && poly.length >= off + nCoords : "";
47126
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 39519
diff changeset
   181
        float acc = 0.0f;
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   182
        for (int i = off + 2; i < off + nCoords; i += 2) {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   183
            acc += linelen(poly[i], poly[i+1], poly[i-2], poly[i-1]);
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   184
        }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   185
        return acc;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   186
    }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   187
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   188
    static float linelen(float x1, float y1, float x2, float y2) {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   189
        final float dx = x2 - x1;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   190
        final float dy = y2 - y1;
47126
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 39519
diff changeset
   191
        return (float) Math.sqrt(dx*dx + dy*dy);
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   192
    }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   193
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   194
    static void subdivide(float[] src, int srcoff, float[] left, int leftoff,
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   195
                          float[] right, int rightoff, int type)
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   196
    {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   197
        switch(type) {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   198
        case 6:
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   199
            Helpers.subdivideQuad(src, srcoff, left, leftoff, right, rightoff);
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   200
            return;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   201
        case 8:
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   202
            Helpers.subdivideCubic(src, srcoff, left, leftoff, right, rightoff);
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   203
            return;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   204
        default:
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   205
            throw new InternalError("Unsupported curve type");
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   206
        }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   207
    }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   208
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   209
    static void isort(float[] a, int off, int len) {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   210
        for (int i = off + 1, end = off + len; i < end; i++) {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   211
            float ai = a[i];
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   212
            int j = i - 1;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   213
            for (; j >= off && a[j] > ai; j--) {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   214
                a[j+1] = a[j];
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   215
            }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   216
            a[j+1] = ai;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   217
        }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   218
    }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   219
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   220
    // Most of these are copied from classes in java.awt.geom because we need
47126
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 39519
diff changeset
   221
    // both single and double precision variants of these functions, and Line2D,
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 39519
diff changeset
   222
    // CubicCurve2D, QuadCurve2D don't provide them.
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   223
    /**
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   224
     * Subdivides the cubic curve specified by the coordinates
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   225
     * stored in the <code>src</code> array at indices <code>srcoff</code>
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   226
     * through (<code>srcoff</code>&nbsp;+&nbsp;7) and stores the
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   227
     * resulting two subdivided curves into the two result arrays at the
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   228
     * corresponding indices.
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   229
     * Either or both of the <code>left</code> and <code>right</code>
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   230
     * arrays may be <code>null</code> or a reference to the same array
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   231
     * as the <code>src</code> array.
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   232
     * Note that the last point in the first subdivided curve is the
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   233
     * same as the first point in the second subdivided curve. Thus,
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   234
     * it is possible to pass the same array for <code>left</code>
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   235
     * and <code>right</code> and to use offsets, such as <code>rightoff</code>
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   236
     * equals (<code>leftoff</code> + 6), in order
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   237
     * to avoid allocating extra storage for this common point.
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   238
     * @param src the array holding the coordinates for the source curve
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   239
     * @param srcoff the offset into the array of the beginning of the
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   240
     * the 6 source coordinates
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   241
     * @param left the array for storing the coordinates for the first
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   242
     * half of the subdivided curve
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   243
     * @param leftoff the offset into the array of the beginning of the
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   244
     * the 6 left coordinates
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   245
     * @param right the array for storing the coordinates for the second
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   246
     * half of the subdivided curve
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   247
     * @param rightoff the offset into the array of the beginning of the
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   248
     * the 6 right coordinates
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   249
     * @since 1.7
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   250
     */
39519
21bfc4452441 8159093: Fix coding conventions in Marlin renderer
lbourges
parents: 34417
diff changeset
   251
    static void subdivideCubic(float[] src, int srcoff,
21bfc4452441 8159093: Fix coding conventions in Marlin renderer
lbourges
parents: 34417
diff changeset
   252
                               float[] left, int leftoff,
21bfc4452441 8159093: Fix coding conventions in Marlin renderer
lbourges
parents: 34417
diff changeset
   253
                               float[] right, int rightoff)
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   254
    {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   255
        float x1 = src[srcoff + 0];
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   256
        float y1 = src[srcoff + 1];
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   257
        float ctrlx1 = src[srcoff + 2];
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   258
        float ctrly1 = src[srcoff + 3];
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   259
        float ctrlx2 = src[srcoff + 4];
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   260
        float ctrly2 = src[srcoff + 5];
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   261
        float x2 = src[srcoff + 6];
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   262
        float y2 = src[srcoff + 7];
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   263
        if (left != null) {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   264
            left[leftoff + 0] = x1;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   265
            left[leftoff + 1] = y1;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   266
        }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   267
        if (right != null) {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   268
            right[rightoff + 6] = x2;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   269
            right[rightoff + 7] = y2;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   270
        }
47126
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 39519
diff changeset
   271
        x1 = (x1 + ctrlx1) / 2.0f;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 39519
diff changeset
   272
        y1 = (y1 + ctrly1) / 2.0f;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 39519
diff changeset
   273
        x2 = (x2 + ctrlx2) / 2.0f;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 39519
diff changeset
   274
        y2 = (y2 + ctrly2) / 2.0f;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 39519
diff changeset
   275
        float centerx = (ctrlx1 + ctrlx2) / 2.0f;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 39519
diff changeset
   276
        float centery = (ctrly1 + ctrly2) / 2.0f;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 39519
diff changeset
   277
        ctrlx1 = (x1 + centerx) / 2.0f;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 39519
diff changeset
   278
        ctrly1 = (y1 + centery) / 2.0f;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 39519
diff changeset
   279
        ctrlx2 = (x2 + centerx) / 2.0f;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 39519
diff changeset
   280
        ctrly2 = (y2 + centery) / 2.0f;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 39519
diff changeset
   281
        centerx = (ctrlx1 + ctrlx2) / 2.0f;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 39519
diff changeset
   282
        centery = (ctrly1 + ctrly2) / 2.0f;
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   283
        if (left != null) {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   284
            left[leftoff + 2] = x1;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   285
            left[leftoff + 3] = y1;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   286
            left[leftoff + 4] = ctrlx1;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   287
            left[leftoff + 5] = ctrly1;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   288
            left[leftoff + 6] = centerx;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   289
            left[leftoff + 7] = centery;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   290
        }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   291
        if (right != null) {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   292
            right[rightoff + 0] = centerx;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   293
            right[rightoff + 1] = centery;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   294
            right[rightoff + 2] = ctrlx2;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   295
            right[rightoff + 3] = ctrly2;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   296
            right[rightoff + 4] = x2;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   297
            right[rightoff + 5] = y2;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   298
        }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   299
    }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   300
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   301
39519
21bfc4452441 8159093: Fix coding conventions in Marlin renderer
lbourges
parents: 34417
diff changeset
   302
    static void subdivideCubicAt(float t, float[] src, int srcoff,
21bfc4452441 8159093: Fix coding conventions in Marlin renderer
lbourges
parents: 34417
diff changeset
   303
                                 float[] left, int leftoff,
21bfc4452441 8159093: Fix coding conventions in Marlin renderer
lbourges
parents: 34417
diff changeset
   304
                                 float[] right, int rightoff)
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   305
    {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   306
        float x1 = src[srcoff + 0];
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   307
        float y1 = src[srcoff + 1];
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   308
        float ctrlx1 = src[srcoff + 2];
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   309
        float ctrly1 = src[srcoff + 3];
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   310
        float ctrlx2 = src[srcoff + 4];
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   311
        float ctrly2 = src[srcoff + 5];
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   312
        float x2 = src[srcoff + 6];
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   313
        float y2 = src[srcoff + 7];
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   314
        if (left != null) {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   315
            left[leftoff + 0] = x1;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   316
            left[leftoff + 1] = y1;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   317
        }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   318
        if (right != null) {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   319
            right[rightoff + 6] = x2;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   320
            right[rightoff + 7] = y2;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   321
        }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   322
        x1 = x1 + t * (ctrlx1 - x1);
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   323
        y1 = y1 + t * (ctrly1 - y1);
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   324
        x2 = ctrlx2 + t * (x2 - ctrlx2);
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   325
        y2 = ctrly2 + t * (y2 - ctrly2);
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   326
        float centerx = ctrlx1 + t * (ctrlx2 - ctrlx1);
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   327
        float centery = ctrly1 + t * (ctrly2 - ctrly1);
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   328
        ctrlx1 = x1 + t * (centerx - x1);
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   329
        ctrly1 = y1 + t * (centery - y1);
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   330
        ctrlx2 = centerx + t * (x2 - centerx);
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   331
        ctrly2 = centery + t * (y2 - centery);
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   332
        centerx = ctrlx1 + t * (ctrlx2 - ctrlx1);
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   333
        centery = ctrly1 + t * (ctrly2 - ctrly1);
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   334
        if (left != null) {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   335
            left[leftoff + 2] = x1;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   336
            left[leftoff + 3] = y1;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   337
            left[leftoff + 4] = ctrlx1;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   338
            left[leftoff + 5] = ctrly1;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   339
            left[leftoff + 6] = centerx;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   340
            left[leftoff + 7] = centery;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   341
        }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   342
        if (right != null) {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   343
            right[rightoff + 0] = centerx;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   344
            right[rightoff + 1] = centery;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   345
            right[rightoff + 2] = ctrlx2;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   346
            right[rightoff + 3] = ctrly2;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   347
            right[rightoff + 4] = x2;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   348
            right[rightoff + 5] = y2;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   349
        }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   350
    }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   351
39519
21bfc4452441 8159093: Fix coding conventions in Marlin renderer
lbourges
parents: 34417
diff changeset
   352
    static void subdivideQuad(float[] src, int srcoff,
21bfc4452441 8159093: Fix coding conventions in Marlin renderer
lbourges
parents: 34417
diff changeset
   353
                              float[] left, int leftoff,
21bfc4452441 8159093: Fix coding conventions in Marlin renderer
lbourges
parents: 34417
diff changeset
   354
                              float[] right, int rightoff)
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   355
    {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   356
        float x1 = src[srcoff + 0];
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   357
        float y1 = src[srcoff + 1];
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   358
        float ctrlx = src[srcoff + 2];
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   359
        float ctrly = src[srcoff + 3];
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   360
        float x2 = src[srcoff + 4];
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   361
        float y2 = src[srcoff + 5];
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   362
        if (left != null) {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   363
            left[leftoff + 0] = x1;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   364
            left[leftoff + 1] = y1;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   365
        }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   366
        if (right != null) {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   367
            right[rightoff + 4] = x2;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   368
            right[rightoff + 5] = y2;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   369
        }
47126
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 39519
diff changeset
   370
        x1 = (x1 + ctrlx) / 2.0f;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 39519
diff changeset
   371
        y1 = (y1 + ctrly) / 2.0f;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 39519
diff changeset
   372
        x2 = (x2 + ctrlx) / 2.0f;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 39519
diff changeset
   373
        y2 = (y2 + ctrly) / 2.0f;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 39519
diff changeset
   374
        ctrlx = (x1 + x2) / 2.0f;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 39519
diff changeset
   375
        ctrly = (y1 + y2) / 2.0f;
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   376
        if (left != null) {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   377
            left[leftoff + 2] = x1;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   378
            left[leftoff + 3] = y1;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   379
            left[leftoff + 4] = ctrlx;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   380
            left[leftoff + 5] = ctrly;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   381
        }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   382
        if (right != null) {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   383
            right[rightoff + 0] = ctrlx;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   384
            right[rightoff + 1] = ctrly;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   385
            right[rightoff + 2] = x2;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   386
            right[rightoff + 3] = y2;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   387
        }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   388
    }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   389
39519
21bfc4452441 8159093: Fix coding conventions in Marlin renderer
lbourges
parents: 34417
diff changeset
   390
    static void subdivideQuadAt(float t, float[] src, int srcoff,
21bfc4452441 8159093: Fix coding conventions in Marlin renderer
lbourges
parents: 34417
diff changeset
   391
                                float[] left, int leftoff,
21bfc4452441 8159093: Fix coding conventions in Marlin renderer
lbourges
parents: 34417
diff changeset
   392
                                float[] right, int rightoff)
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   393
    {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   394
        float x1 = src[srcoff + 0];
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   395
        float y1 = src[srcoff + 1];
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   396
        float ctrlx = src[srcoff + 2];
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   397
        float ctrly = src[srcoff + 3];
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   398
        float x2 = src[srcoff + 4];
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   399
        float y2 = src[srcoff + 5];
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   400
        if (left != null) {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   401
            left[leftoff + 0] = x1;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   402
            left[leftoff + 1] = y1;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   403
        }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   404
        if (right != null) {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   405
            right[rightoff + 4] = x2;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   406
            right[rightoff + 5] = y2;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   407
        }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   408
        x1 = x1 + t * (ctrlx - x1);
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   409
        y1 = y1 + t * (ctrly - y1);
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   410
        x2 = ctrlx + t * (x2 - ctrlx);
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   411
        y2 = ctrly + t * (y2 - ctrly);
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   412
        ctrlx = x1 + t * (x2 - x1);
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   413
        ctrly = y1 + t * (y2 - y1);
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   414
        if (left != null) {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   415
            left[leftoff + 2] = x1;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   416
            left[leftoff + 3] = y1;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   417
            left[leftoff + 4] = ctrlx;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   418
            left[leftoff + 5] = ctrly;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   419
        }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   420
        if (right != null) {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   421
            right[rightoff + 0] = ctrlx;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   422
            right[rightoff + 1] = ctrly;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   423
            right[rightoff + 2] = x2;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   424
            right[rightoff + 3] = y2;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   425
        }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   426
    }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   427
39519
21bfc4452441 8159093: Fix coding conventions in Marlin renderer
lbourges
parents: 34417
diff changeset
   428
    static void subdivideAt(float t, float[] src, int srcoff,
21bfc4452441 8159093: Fix coding conventions in Marlin renderer
lbourges
parents: 34417
diff changeset
   429
                            float[] left, int leftoff,
21bfc4452441 8159093: Fix coding conventions in Marlin renderer
lbourges
parents: 34417
diff changeset
   430
                            float[] right, int rightoff, int size)
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   431
    {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   432
        switch(size) {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   433
        case 8:
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   434
            subdivideCubicAt(t, src, srcoff, left, leftoff, right, rightoff);
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   435
            return;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   436
        case 6:
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   437
            subdivideQuadAt(t, src, srcoff, left, leftoff, right, rightoff);
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   438
            return;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   439
        }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   440
    }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   441
}