src/java.desktop/share/classes/sun/java2d/marlin/DStroker.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/DStroker.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:
47126
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
     1
/*
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
     2
 * Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved.
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
     4
 *
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    10
 *
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    15
 * accompanied this code).
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    16
 *
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    20
 *
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    23
 * questions.
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    24
 */
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    25
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    26
package sun.java2d.marlin;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    27
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    28
import java.util.Arrays;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    29
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    30
// TODO: some of the arithmetic here is too verbose and prone to hard to
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    31
// debug typos. We should consider making a small Point/Vector class that
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    32
// has methods like plus(Point), minus(Point), dot(Point), cross(Point)and such
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    33
final class DStroker implements DPathConsumer2D, MarlinConst {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    34
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    35
    private static final int MOVE_TO = 0;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    36
    private static final int DRAWING_OP_TO = 1; // ie. curve, line, or quad
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    37
    private static final int CLOSE = 2;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    38
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    39
    /**
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    40
     * Constant value for join style.
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    41
     */
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    42
    public static final int JOIN_MITER = 0;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    43
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    44
    /**
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    45
     * Constant value for join style.
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    46
     */
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    47
    public static final int JOIN_ROUND = 1;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    48
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    49
    /**
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    50
     * Constant value for join style.
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    51
     */
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    52
    public static final int JOIN_BEVEL = 2;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    53
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    54
    /**
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    55
     * Constant value for end cap style.
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    56
     */
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    57
    public static final int CAP_BUTT = 0;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    58
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    59
    /**
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    60
     * Constant value for end cap style.
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    61
     */
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    62
    public static final int CAP_ROUND = 1;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    63
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    64
    /**
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    65
     * Constant value for end cap style.
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    66
     */
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    67
    public static final int CAP_SQUARE = 2;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    68
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    69
    // pisces used to use fixed point arithmetic with 16 decimal digits. I
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    70
    // didn't want to change the values of the constant below when I converted
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    71
    // it to floating point, so that's why the divisions by 2^16 are there.
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    72
    private static final double ROUND_JOIN_THRESHOLD = 1000.0d/65536.0d;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    73
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    74
    private static final double C = 0.5522847498307933d;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    75
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    76
    private static final int MAX_N_CURVES = 11;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    77
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    78
    private DPathConsumer2D out;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    79
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    80
    private int capStyle;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    81
    private int joinStyle;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    82
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    83
    private double lineWidth2;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    84
    private double invHalfLineWidth2Sq;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    85
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    86
    private final double[] offset0 = new double[2];
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    87
    private final double[] offset1 = new double[2];
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    88
    private final double[] offset2 = new double[2];
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    89
    private final double[] miter = new double[2];
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    90
    private double miterLimitSq;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    91
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    92
    private int prev;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    93
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    94
    // The starting point of the path, and the slope there.
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    95
    private double sx0, sy0, sdx, sdy;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    96
    // the current point and the slope there.
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    97
    private double cx0, cy0, cdx, cdy; // c stands for current
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    98
    // vectors that when added to (sx0,sy0) and (cx0,cy0) respectively yield the
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    99
    // first and last points on the left parallel path. Since this path is
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   100
    // parallel, it's slope at any point is parallel to the slope of the
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   101
    // original path (thought they may have different directions), so these
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   102
    // could be computed from sdx,sdy and cdx,cdy (and vice versa), but that
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   103
    // would be error prone and hard to read, so we keep these anyway.
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   104
    private double smx, smy, cmx, cmy;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   105
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   106
    private final PolyStack reverse;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   107
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   108
    // This is where the curve to be processed is put. We give it
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   109
    // enough room to store all curves.
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   110
    private final double[] middle = new double[MAX_N_CURVES * 6 + 2];
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   111
    private final double[] lp = new double[8];
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   112
    private final double[] rp = new double[8];
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   113
    private final double[] subdivTs = new double[MAX_N_CURVES - 1];
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   114
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   115
    // per-thread renderer context
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   116
    final DRendererContext rdrCtx;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   117
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   118
    // dirty curve
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   119
    final DCurve curve;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   120
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   121
    /**
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   122
     * Constructs a <code>DStroker</code>.
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   123
     * @param rdrCtx per-thread renderer context
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   124
     */
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   125
    DStroker(final DRendererContext rdrCtx) {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   126
        this.rdrCtx = rdrCtx;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   127
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   128
        this.reverse = new PolyStack(rdrCtx);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   129
        this.curve = rdrCtx.curve;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   130
    }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   131
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   132
    /**
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   133
     * Inits the <code>DStroker</code>.
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   134
     *
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   135
     * @param pc2d an output <code>DPathConsumer2D</code>.
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   136
     * @param lineWidth the desired line width in pixels
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   137
     * @param capStyle the desired end cap style, one of
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   138
     * <code>CAP_BUTT</code>, <code>CAP_ROUND</code> or
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   139
     * <code>CAP_SQUARE</code>.
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   140
     * @param joinStyle the desired line join style, one of
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   141
     * <code>JOIN_MITER</code>, <code>JOIN_ROUND</code> or
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   142
     * <code>JOIN_BEVEL</code>.
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   143
     * @param miterLimit the desired miter limit
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   144
     * @return this instance
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   145
     */
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   146
    DStroker init(DPathConsumer2D pc2d,
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   147
              double lineWidth,
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   148
              int capStyle,
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   149
              int joinStyle,
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   150
              double miterLimit)
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   151
    {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   152
        this.out = pc2d;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   153
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   154
        this.lineWidth2 = lineWidth / 2.0d;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   155
        this.invHalfLineWidth2Sq = 1.0d / (2.0d * lineWidth2 * lineWidth2);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   156
        this.capStyle = capStyle;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   157
        this.joinStyle = joinStyle;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   158
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   159
        double limit = miterLimit * lineWidth2;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   160
        this.miterLimitSq = limit * limit;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   161
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   162
        this.prev = CLOSE;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   163
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   164
        rdrCtx.stroking = 1;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   165
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   166
        return this; // fluent API
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   167
    }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   168
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   169
    /**
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   170
     * Disposes this stroker:
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   171
     * clean up before reusing this instance
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   172
     */
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   173
    void dispose() {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   174
        reverse.dispose();
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   175
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   176
        if (DO_CLEAN_DIRTY) {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   177
            // Force zero-fill dirty arrays:
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   178
            Arrays.fill(offset0, 0.0d);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   179
            Arrays.fill(offset1, 0.0d);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   180
            Arrays.fill(offset2, 0.0d);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   181
            Arrays.fill(miter, 0.0d);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   182
            Arrays.fill(middle, 0.0d);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   183
            Arrays.fill(lp, 0.0d);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   184
            Arrays.fill(rp, 0.0d);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   185
            Arrays.fill(subdivTs, 0.0d);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   186
        }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   187
    }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   188
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   189
    private static void computeOffset(final double lx, final double ly,
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   190
                                      final double w, final double[] m)
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   191
    {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   192
        double len = lx*lx + ly*ly;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   193
        if (len == 0.0d) {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   194
            m[0] = 0.0d;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   195
            m[1] = 0.0d;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   196
        } else {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   197
            len = Math.sqrt(len);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   198
            m[0] =  (ly * w) / len;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   199
            m[1] = -(lx * w) / len;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   200
        }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   201
    }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   202
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   203
    // Returns true if the vectors (dx1, dy1) and (dx2, dy2) are
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   204
    // clockwise (if dx1,dy1 needs to be rotated clockwise to close
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   205
    // the smallest angle between it and dx2,dy2).
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   206
    // This is equivalent to detecting whether a point q is on the right side
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   207
    // of a line passing through points p1, p2 where p2 = p1+(dx1,dy1) and
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   208
    // q = p2+(dx2,dy2), which is the same as saying p1, p2, q are in a
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   209
    // clockwise order.
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   210
    // NOTE: "clockwise" here assumes coordinates with 0,0 at the bottom left.
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   211
    private static boolean isCW(final double dx1, final double dy1,
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   212
                                final double dx2, final double dy2)
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   213
    {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   214
        return dx1 * dy2 <= dy1 * dx2;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   215
    }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   216
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   217
    private void drawRoundJoin(double x, double y,
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   218
                               double omx, double omy, double mx, double my,
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   219
                               boolean rev,
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   220
                               double threshold)
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   221
    {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   222
        if ((omx == 0.0d && omy == 0.0d) || (mx == 0.0d && my == 0.0d)) {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   223
            return;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   224
        }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   225
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   226
        double domx = omx - mx;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   227
        double domy = omy - my;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   228
        double len = domx*domx + domy*domy;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   229
        if (len < threshold) {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   230
            return;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   231
        }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   232
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   233
        if (rev) {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   234
            omx = -omx;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   235
            omy = -omy;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   236
            mx  = -mx;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   237
            my  = -my;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   238
        }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   239
        drawRoundJoin(x, y, omx, omy, mx, my, rev);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   240
    }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   241
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   242
    private void drawRoundJoin(double cx, double cy,
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   243
                               double omx, double omy,
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   244
                               double mx, double my,
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   245
                               boolean rev)
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   246
    {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   247
        // The sign of the dot product of mx,my and omx,omy is equal to the
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   248
        // the sign of the cosine of ext
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   249
        // (ext is the angle between omx,omy and mx,my).
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   250
        final double cosext = omx * mx + omy * my;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   251
        // If it is >=0, we know that abs(ext) is <= 90 degrees, so we only
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   252
        // need 1 curve to approximate the circle section that joins omx,omy
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   253
        // and mx,my.
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   254
        final int numCurves = (cosext >= 0.0d) ? 1 : 2;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   255
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   256
        switch (numCurves) {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   257
        case 1:
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   258
            drawBezApproxForArc(cx, cy, omx, omy, mx, my, rev);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   259
            break;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   260
        case 2:
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   261
            // we need to split the arc into 2 arcs spanning the same angle.
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   262
            // The point we want will be one of the 2 intersections of the
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   263
            // perpendicular bisector of the chord (omx,omy)->(mx,my) and the
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   264
            // circle. We could find this by scaling the vector
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   265
            // (omx+mx, omy+my)/2 so that it has length=lineWidth2 (and thus lies
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   266
            // on the circle), but that can have numerical problems when the angle
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   267
            // between omx,omy and mx,my is close to 180 degrees. So we compute a
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   268
            // normal of (omx,omy)-(mx,my). This will be the direction of the
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   269
            // perpendicular bisector. To get one of the intersections, we just scale
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   270
            // this vector that its length is lineWidth2 (this works because the
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   271
            // perpendicular bisector goes through the origin). This scaling doesn't
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   272
            // have numerical problems because we know that lineWidth2 divided by
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   273
            // this normal's length is at least 0.5 and at most sqrt(2)/2 (because
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   274
            // we know the angle of the arc is > 90 degrees).
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   275
            double nx = my - omy, ny = omx - mx;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   276
            double nlen = Math.sqrt(nx*nx + ny*ny);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   277
            double scale = lineWidth2/nlen;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   278
            double mmx = nx * scale, mmy = ny * scale;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   279
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   280
            // if (isCW(omx, omy, mx, my) != isCW(mmx, mmy, mx, my)) then we've
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   281
            // computed the wrong intersection so we get the other one.
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   282
            // The test above is equivalent to if (rev).
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   283
            if (rev) {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   284
                mmx = -mmx;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   285
                mmy = -mmy;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   286
            }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   287
            drawBezApproxForArc(cx, cy, omx, omy, mmx, mmy, rev);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   288
            drawBezApproxForArc(cx, cy, mmx, mmy, mx, my, rev);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   289
            break;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   290
        default:
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   291
        }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   292
    }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   293
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   294
    // the input arc defined by omx,omy and mx,my must span <= 90 degrees.
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   295
    private void drawBezApproxForArc(final double cx, final double cy,
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   296
                                     final double omx, final double omy,
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   297
                                     final double mx, final double my,
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   298
                                     boolean rev)
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   299
    {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   300
        final double cosext2 = (omx * mx + omy * my) * invHalfLineWidth2Sq;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   301
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   302
        // check round off errors producing cos(ext) > 1 and a NaN below
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   303
        // cos(ext) == 1 implies colinear segments and an empty join anyway
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   304
        if (cosext2 >= 0.5d) {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   305
            // just return to avoid generating a flat curve:
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   306
            return;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   307
        }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   308
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   309
        // cv is the length of P1-P0 and P2-P3 divided by the radius of the arc
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   310
        // (so, cv assumes the arc has radius 1). P0, P1, P2, P3 are the points that
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   311
        // define the bezier curve we're computing.
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   312
        // It is computed using the constraints that P1-P0 and P3-P2 are parallel
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   313
        // to the arc tangents at the endpoints, and that |P1-P0|=|P3-P2|.
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   314
        double cv = ((4.0d / 3.0d) * Math.sqrt(0.5d - cosext2) /
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   315
                            (1.0d + Math.sqrt(cosext2 + 0.5d)));
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   316
        // if clockwise, we need to negate cv.
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   317
        if (rev) { // rev is equivalent to isCW(omx, omy, mx, my)
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   318
            cv = -cv;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   319
        }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   320
        final double x1 = cx + omx;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   321
        final double y1 = cy + omy;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   322
        final double x2 = x1 - cv * omy;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   323
        final double y2 = y1 + cv * omx;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   324
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   325
        final double x4 = cx + mx;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   326
        final double y4 = cy + my;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   327
        final double x3 = x4 + cv * my;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   328
        final double y3 = y4 - cv * mx;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   329
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   330
        emitCurveTo(x1, y1, x2, y2, x3, y3, x4, y4, rev);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   331
    }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   332
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   333
    private void drawRoundCap(double cx, double cy, double mx, double my) {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   334
        final double Cmx = C * mx;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   335
        final double Cmy = C * my;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   336
        emitCurveTo(cx + mx - Cmy, cy + my + Cmx,
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   337
                    cx - my + Cmx, cy + mx + Cmy,
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   338
                    cx - my,       cy + mx);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   339
        emitCurveTo(cx - my - Cmx, cy + mx - Cmy,
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   340
                    cx - mx - Cmy, cy - my + Cmx,
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   341
                    cx - mx,       cy - my);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   342
    }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   343
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   344
    // Return the intersection point of the lines (x0, y0) -> (x1, y1)
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   345
    // and (x0p, y0p) -> (x1p, y1p) in m[off] and m[off+1]
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   346
    private static void computeMiter(final double x0, final double y0,
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   347
                                     final double x1, final double y1,
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   348
                                     final double x0p, final double y0p,
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   349
                                     final double x1p, final double y1p,
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   350
                                     final double[] m, int off)
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   351
    {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   352
        double x10 = x1 - x0;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   353
        double y10 = y1 - y0;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   354
        double x10p = x1p - x0p;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   355
        double y10p = y1p - y0p;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   356
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   357
        // if this is 0, the lines are parallel. If they go in the
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   358
        // same direction, there is no intersection so m[off] and
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   359
        // m[off+1] will contain infinity, so no miter will be drawn.
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   360
        // If they go in the same direction that means that the start of the
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   361
        // current segment and the end of the previous segment have the same
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   362
        // tangent, in which case this method won't even be involved in
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   363
        // miter drawing because it won't be called by drawMiter (because
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   364
        // (mx == omx && my == omy) will be true, and drawMiter will return
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   365
        // immediately).
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   366
        double den = x10*y10p - x10p*y10;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   367
        double t = x10p*(y0-y0p) - y10p*(x0-x0p);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   368
        t /= den;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   369
        m[off++] = x0 + t*x10;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   370
        m[off]   = y0 + t*y10;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   371
    }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   372
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   373
    // Return the intersection point of the lines (x0, y0) -> (x1, y1)
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   374
    // and (x0p, y0p) -> (x1p, y1p) in m[off] and m[off+1]
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   375
    private static void safeComputeMiter(final double x0, final double y0,
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   376
                                         final double x1, final double y1,
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   377
                                         final double x0p, final double y0p,
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   378
                                         final double x1p, final double y1p,
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   379
                                         final double[] m, int off)
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   380
    {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   381
        double x10 = x1 - x0;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   382
        double y10 = y1 - y0;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   383
        double x10p = x1p - x0p;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   384
        double y10p = y1p - y0p;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   385
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   386
        // if this is 0, the lines are parallel. If they go in the
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   387
        // same direction, there is no intersection so m[off] and
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   388
        // m[off+1] will contain infinity, so no miter will be drawn.
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   389
        // If they go in the same direction that means that the start of the
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   390
        // current segment and the end of the previous segment have the same
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   391
        // tangent, in which case this method won't even be involved in
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   392
        // miter drawing because it won't be called by drawMiter (because
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   393
        // (mx == omx && my == omy) will be true, and drawMiter will return
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   394
        // immediately).
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   395
        double den = x10*y10p - x10p*y10;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   396
        if (den == 0.0d) {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   397
            m[off++] = (x0 + x0p) / 2.0d;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   398
            m[off]   = (y0 + y0p) / 2.0d;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   399
            return;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   400
        }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   401
        double t = x10p*(y0-y0p) - y10p*(x0-x0p);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   402
        t /= den;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   403
        m[off++] = x0 + t*x10;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   404
        m[off] = y0 + t*y10;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   405
    }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   406
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   407
    private void drawMiter(final double pdx, final double pdy,
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   408
                           final double x0, final double y0,
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   409
                           final double dx, final double dy,
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   410
                           double omx, double omy, double mx, double my,
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   411
                           boolean rev)
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   412
    {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   413
        if ((mx == omx && my == omy) ||
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   414
            (pdx == 0.0d && pdy == 0.0d) ||
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   415
            (dx == 0.0d && dy == 0.0d))
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   416
        {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   417
            return;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   418
        }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   419
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   420
        if (rev) {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   421
            omx = -omx;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   422
            omy = -omy;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   423
            mx  = -mx;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   424
            my  = -my;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   425
        }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   426
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   427
        computeMiter((x0 - pdx) + omx, (y0 - pdy) + omy, x0 + omx, y0 + omy,
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   428
                     (dx + x0) + mx, (dy + y0) + my, x0 + mx, y0 + my,
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   429
                     miter, 0);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   430
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   431
        final double miterX = miter[0];
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   432
        final double miterY = miter[1];
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   433
        double lenSq = (miterX-x0)*(miterX-x0) + (miterY-y0)*(miterY-y0);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   434
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   435
        // If the lines are parallel, lenSq will be either NaN or +inf
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   436
        // (actually, I'm not sure if the latter is possible. The important
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   437
        // thing is that -inf is not possible, because lenSq is a square).
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   438
        // For both of those values, the comparison below will fail and
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   439
        // no miter will be drawn, which is correct.
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   440
        if (lenSq < miterLimitSq) {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   441
            emitLineTo(miterX, miterY, rev);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   442
        }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   443
    }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   444
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   445
    @Override
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   446
    public void moveTo(double x0, double y0) {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   447
        if (prev == DRAWING_OP_TO) {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   448
            finish();
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   449
        }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   450
        this.sx0 = this.cx0 = x0;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   451
        this.sy0 = this.cy0 = y0;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   452
        this.cdx = this.sdx = 1.0d;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   453
        this.cdy = this.sdy = 0.0d;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   454
        this.prev = MOVE_TO;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   455
    }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   456
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   457
    @Override
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   458
    public void lineTo(double x1, double y1) {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   459
        double dx = x1 - cx0;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   460
        double dy = y1 - cy0;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   461
        if (dx == 0.0d && dy == 0.0d) {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   462
            dx = 1.0d;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   463
        }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   464
        computeOffset(dx, dy, lineWidth2, offset0);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   465
        final double mx = offset0[0];
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   466
        final double my = offset0[1];
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   467
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   468
        drawJoin(cdx, cdy, cx0, cy0, dx, dy, cmx, cmy, mx, my);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   469
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   470
        emitLineTo(cx0 + mx, cy0 + my);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   471
        emitLineTo( x1 + mx,  y1 + my);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   472
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   473
        emitLineToRev(cx0 - mx, cy0 - my);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   474
        emitLineToRev( x1 - mx,  y1 - my);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   475
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   476
        this.cmx = mx;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   477
        this.cmy = my;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   478
        this.cdx = dx;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   479
        this.cdy = dy;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   480
        this.cx0 = x1;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   481
        this.cy0 = y1;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   482
        this.prev = DRAWING_OP_TO;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   483
    }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   484
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   485
    @Override
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   486
    public void closePath() {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   487
        if (prev != DRAWING_OP_TO) {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   488
            if (prev == CLOSE) {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   489
                return;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   490
            }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   491
            emitMoveTo(cx0, cy0 - lineWidth2);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   492
            this.cmx = this.smx = 0.0d;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   493
            this.cmy = this.smy = -lineWidth2;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   494
            this.cdx = this.sdx = 1.0d;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   495
            this.cdy = this.sdy = 0.0d;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   496
            finish();
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   497
            return;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   498
        }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   499
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   500
        if (cx0 != sx0 || cy0 != sy0) {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   501
            lineTo(sx0, sy0);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   502
        }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   503
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   504
        drawJoin(cdx, cdy, cx0, cy0, sdx, sdy, cmx, cmy, smx, smy);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   505
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   506
        emitLineTo(sx0 + smx, sy0 + smy);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   507
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   508
        emitMoveTo(sx0 - smx, sy0 - smy);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   509
        emitReverse();
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   510
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   511
        this.prev = CLOSE;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   512
        emitClose();
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   513
    }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   514
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   515
    private void emitReverse() {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   516
        reverse.popAll(out);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   517
    }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   518
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   519
    @Override
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   520
    public void pathDone() {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   521
        if (prev == DRAWING_OP_TO) {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   522
            finish();
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   523
        }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   524
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   525
        out.pathDone();
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   526
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   527
        // this shouldn't matter since this object won't be used
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   528
        // after the call to this method.
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   529
        this.prev = CLOSE;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   530
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   531
        // Dispose this instance:
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   532
        dispose();
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   533
    }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   534
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   535
    private void finish() {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   536
        if (capStyle == CAP_ROUND) {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   537
            drawRoundCap(cx0, cy0, cmx, cmy);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   538
        } else if (capStyle == CAP_SQUARE) {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   539
            emitLineTo(cx0 - cmy + cmx, cy0 + cmx + cmy);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   540
            emitLineTo(cx0 - cmy - cmx, cy0 + cmx - cmy);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   541
        }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   542
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   543
        emitReverse();
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   544
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   545
        if (capStyle == CAP_ROUND) {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   546
            drawRoundCap(sx0, sy0, -smx, -smy);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   547
        } else if (capStyle == CAP_SQUARE) {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   548
            emitLineTo(sx0 + smy - smx, sy0 - smx - smy);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   549
            emitLineTo(sx0 + smy + smx, sy0 - smx + smy);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   550
        }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   551
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   552
        emitClose();
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   553
    }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   554
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   555
    private void emitMoveTo(final double x0, final double y0) {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   556
        out.moveTo(x0, y0);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   557
    }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   558
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   559
    private void emitLineTo(final double x1, final double y1) {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   560
        out.lineTo(x1, y1);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   561
    }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   562
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   563
    private void emitLineToRev(final double x1, final double y1) {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   564
        reverse.pushLine(x1, y1);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   565
    }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   566
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   567
    private void emitLineTo(final double x1, final double y1,
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   568
                            final boolean rev)
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   569
    {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   570
        if (rev) {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   571
            emitLineToRev(x1, y1);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   572
        } else {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   573
            emitLineTo(x1, y1);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   574
        }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   575
    }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   576
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   577
    private void emitQuadTo(final double x1, final double y1,
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   578
                            final double x2, final double y2)
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   579
    {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   580
        out.quadTo(x1, y1, x2, y2);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   581
    }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   582
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   583
    private void emitQuadToRev(final double x0, final double y0,
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   584
                               final double x1, final double y1)
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   585
    {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   586
        reverse.pushQuad(x0, y0, x1, y1);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   587
    }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   588
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   589
    private void emitCurveTo(final double x1, final double y1,
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   590
                             final double x2, final double y2,
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   591
                             final double x3, final double y3)
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   592
    {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   593
        out.curveTo(x1, y1, x2, y2, x3, y3);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   594
    }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   595
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   596
    private void emitCurveToRev(final double x0, final double y0,
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   597
                                final double x1, final double y1,
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   598
                                final double x2, final double y2)
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   599
    {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   600
        reverse.pushCubic(x0, y0, x1, y1, x2, y2);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   601
    }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   602
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   603
    private void emitCurveTo(final double x0, final double y0,
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   604
                             final double x1, final double y1,
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   605
                             final double x2, final double y2,
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   606
                             final double x3, final double y3, final boolean rev)
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   607
    {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   608
        if (rev) {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   609
            reverse.pushCubic(x0, y0, x1, y1, x2, y2);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   610
        } else {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   611
            out.curveTo(x1, y1, x2, y2, x3, y3);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   612
        }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   613
    }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   614
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   615
    private void emitClose() {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   616
        out.closePath();
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   617
    }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   618
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   619
    private void drawJoin(double pdx, double pdy,
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   620
                          double x0, double y0,
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   621
                          double dx, double dy,
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   622
                          double omx, double omy,
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   623
                          double mx, double my)
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   624
    {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   625
        if (prev != DRAWING_OP_TO) {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   626
            emitMoveTo(x0 + mx, y0 + my);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   627
            this.sdx = dx;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   628
            this.sdy = dy;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   629
            this.smx = mx;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   630
            this.smy = my;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   631
        } else {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   632
            boolean cw = isCW(pdx, pdy, dx, dy);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   633
            if (joinStyle == JOIN_MITER) {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   634
                drawMiter(pdx, pdy, x0, y0, dx, dy, omx, omy, mx, my, cw);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   635
            } else if (joinStyle == JOIN_ROUND) {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   636
                drawRoundJoin(x0, y0,
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   637
                              omx, omy,
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   638
                              mx, my, cw,
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   639
                              ROUND_JOIN_THRESHOLD);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   640
            }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   641
            emitLineTo(x0, y0, !cw);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   642
        }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   643
        prev = DRAWING_OP_TO;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   644
    }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   645
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   646
    private static boolean within(final double x1, final double y1,
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   647
                                  final double x2, final double y2,
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   648
                                  final double ERR)
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   649
    {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   650
        assert ERR > 0 : "";
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   651
        // compare taxicab distance. ERR will always be small, so using
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   652
        // true distance won't give much benefit
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   653
        return (DHelpers.within(x1, x2, ERR) &&  // we want to avoid calling Math.abs
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   654
                DHelpers.within(y1, y2, ERR)); // this is just as good.
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   655
    }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   656
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   657
    private void getLineOffsets(double x1, double y1,
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   658
                                double x2, double y2,
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   659
                                double[] left, double[] right) {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   660
        computeOffset(x2 - x1, y2 - y1, lineWidth2, offset0);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   661
        final double mx = offset0[0];
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   662
        final double my = offset0[1];
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   663
        left[0] = x1 + mx;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   664
        left[1] = y1 + my;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   665
        left[2] = x2 + mx;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   666
        left[3] = y2 + my;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   667
        right[0] = x1 - mx;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   668
        right[1] = y1 - my;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   669
        right[2] = x2 - mx;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   670
        right[3] = y2 - my;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   671
    }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   672
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   673
    private int computeOffsetCubic(double[] pts, final int off,
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   674
                                   double[] leftOff, double[] rightOff)
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   675
    {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   676
        // if p1=p2 or p3=p4 it means that the derivative at the endpoint
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   677
        // vanishes, which creates problems with computeOffset. Usually
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   678
        // this happens when this stroker object is trying to widen
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   679
        // a curve with a cusp. What happens is that curveTo splits
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   680
        // the input curve at the cusp, and passes it to this function.
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   681
        // because of inaccuracies in the splitting, we consider points
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   682
        // equal if they're very close to each other.
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   683
        final double x1 = pts[off + 0], y1 = pts[off + 1];
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   684
        final double x2 = pts[off + 2], y2 = pts[off + 3];
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   685
        final double x3 = pts[off + 4], y3 = pts[off + 5];
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   686
        final double x4 = pts[off + 6], y4 = pts[off + 7];
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   687
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   688
        double dx4 = x4 - x3;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   689
        double dy4 = y4 - y3;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   690
        double dx1 = x2 - x1;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   691
        double dy1 = y2 - y1;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   692
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   693
        // if p1 == p2 && p3 == p4: draw line from p1->p4, unless p1 == p4,
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   694
        // in which case ignore if p1 == p2
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   695
        final boolean p1eqp2 = within(x1, y1, x2, y2, 6.0d * Math.ulp(y2));
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   696
        final boolean p3eqp4 = within(x3, y3, x4, y4, 6.0d * Math.ulp(y4));
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   697
        if (p1eqp2 && p3eqp4) {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   698
            getLineOffsets(x1, y1, x4, y4, leftOff, rightOff);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   699
            return 4;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   700
        } else if (p1eqp2) {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   701
            dx1 = x3 - x1;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   702
            dy1 = y3 - y1;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   703
        } else if (p3eqp4) {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   704
            dx4 = x4 - x2;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   705
            dy4 = y4 - y2;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   706
        }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   707
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   708
        // if p2-p1 and p4-p3 are parallel, that must mean this curve is a line
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   709
        double dotsq = (dx1 * dx4 + dy1 * dy4);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   710
        dotsq *= dotsq;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   711
        double l1sq = dx1 * dx1 + dy1 * dy1, l4sq = dx4 * dx4 + dy4 * dy4;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   712
        if (DHelpers.within(dotsq, l1sq * l4sq, 4.0d * Math.ulp(dotsq))) {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   713
            getLineOffsets(x1, y1, x4, y4, leftOff, rightOff);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   714
            return 4;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   715
        }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   716
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   717
//      What we're trying to do in this function is to approximate an ideal
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   718
//      offset curve (call it I) of the input curve B using a bezier curve Bp.
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   719
//      The constraints I use to get the equations are:
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   720
//
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   721
//      1. The computed curve Bp should go through I(0) and I(1). These are
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   722
//      x1p, y1p, x4p, y4p, which are p1p and p4p. We still need to find
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   723
//      4 variables: the x and y components of p2p and p3p (i.e. x2p, y2p, x3p, y3p).
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   724
//
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   725
//      2. Bp should have slope equal in absolute value to I at the endpoints. So,
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   726
//      (by the way, the operator || in the comments below means "aligned with".
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   727
//      It is defined on vectors, so when we say I'(0) || Bp'(0) we mean that
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   728
//      vectors I'(0) and Bp'(0) are aligned, which is the same as saying
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   729
//      that the tangent lines of I and Bp at 0 are parallel. Mathematically
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   730
//      this means (I'(t) || Bp'(t)) <==> (I'(t) = c * Bp'(t)) where c is some
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   731
//      nonzero constant.)
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   732
//      I'(0) || Bp'(0) and I'(1) || Bp'(1). Obviously, I'(0) || B'(0) and
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   733
//      I'(1) || B'(1); therefore, Bp'(0) || B'(0) and Bp'(1) || B'(1).
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   734
//      We know that Bp'(0) || (p2p-p1p) and Bp'(1) || (p4p-p3p) and the same
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   735
//      is true for any bezier curve; therefore, we get the equations
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   736
//          (1) p2p = c1 * (p2-p1) + p1p
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   737
//          (2) p3p = c2 * (p4-p3) + p4p
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   738
//      We know p1p, p4p, p2, p1, p3, and p4; therefore, this reduces the number
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   739
//      of unknowns from 4 to 2 (i.e. just c1 and c2).
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   740
//      To eliminate these 2 unknowns we use the following constraint:
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   741
//
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   742
//      3. Bp(0.5) == I(0.5). Bp(0.5)=(x,y) and I(0.5)=(xi,yi), and I should note
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   743
//      that I(0.5) is *the only* reason for computing dxm,dym. This gives us
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   744
//          (3) Bp(0.5) = (p1p + 3 * (p2p + p3p) + p4p)/8, which is equivalent to
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   745
//          (4) p2p + p3p = (Bp(0.5)*8 - p1p - p4p) / 3
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   746
//      We can substitute (1) and (2) from above into (4) and we get:
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   747
//          (5) c1*(p2-p1) + c2*(p4-p3) = (Bp(0.5)*8 - p1p - p4p)/3 - p1p - p4p
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   748
//      which is equivalent to
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   749
//          (6) c1*(p2-p1) + c2*(p4-p3) = (4/3) * (Bp(0.5) * 2 - p1p - p4p)
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   750
//
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   751
//      The right side of this is a 2D vector, and we know I(0.5), which gives us
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   752
//      Bp(0.5), which gives us the value of the right side.
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   753
//      The left side is just a matrix vector multiplication in disguise. It is
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   754
//
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   755
//      [x2-x1, x4-x3][c1]
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   756
//      [y2-y1, y4-y3][c2]
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   757
//      which, is equal to
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   758
//      [dx1, dx4][c1]
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   759
//      [dy1, dy4][c2]
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   760
//      At this point we are left with a simple linear system and we solve it by
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   761
//      getting the inverse of the matrix above. Then we use [c1,c2] to compute
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   762
//      p2p and p3p.
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   763
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   764
        double x = (x1 + 3.0d * (x2 + x3) + x4) / 8.0d;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   765
        double y = (y1 + 3.0d * (y2 + y3) + y4) / 8.0d;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   766
        // (dxm,dym) is some tangent of B at t=0.5. This means it's equal to
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   767
        // c*B'(0.5) for some constant c.
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   768
        double dxm = x3 + x4 - x1 - x2, dym = y3 + y4 - y1 - y2;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   769
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   770
        // this computes the offsets at t=0, 0.5, 1, using the property that
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   771
        // for any bezier curve the vectors p2-p1 and p4-p3 are parallel to
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   772
        // the (dx/dt, dy/dt) vectors at the endpoints.
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   773
        computeOffset(dx1, dy1, lineWidth2, offset0);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   774
        computeOffset(dxm, dym, lineWidth2, offset1);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   775
        computeOffset(dx4, dy4, lineWidth2, offset2);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   776
        double x1p = x1 + offset0[0]; // start
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   777
        double y1p = y1 + offset0[1]; // point
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   778
        double xi  = x  + offset1[0]; // interpolation
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   779
        double yi  = y  + offset1[1]; // point
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   780
        double x4p = x4 + offset2[0]; // end
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   781
        double y4p = y4 + offset2[1]; // point
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   782
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   783
        double invdet43 = 4.0d / (3.0d * (dx1 * dy4 - dy1 * dx4));
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   784
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   785
        double two_pi_m_p1_m_p4x = 2.0d * xi - x1p - x4p;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   786
        double two_pi_m_p1_m_p4y = 2.0d * yi - y1p - y4p;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   787
        double c1 = invdet43 * (dy4 * two_pi_m_p1_m_p4x - dx4 * two_pi_m_p1_m_p4y);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   788
        double c2 = invdet43 * (dx1 * two_pi_m_p1_m_p4y - dy1 * two_pi_m_p1_m_p4x);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   789
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   790
        double x2p, y2p, x3p, y3p;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   791
        x2p = x1p + c1*dx1;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   792
        y2p = y1p + c1*dy1;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   793
        x3p = x4p + c2*dx4;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   794
        y3p = y4p + c2*dy4;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   795
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   796
        leftOff[0] = x1p; leftOff[1] = y1p;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   797
        leftOff[2] = x2p; leftOff[3] = y2p;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   798
        leftOff[4] = x3p; leftOff[5] = y3p;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   799
        leftOff[6] = x4p; leftOff[7] = y4p;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   800
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   801
        x1p = x1 - offset0[0]; y1p = y1 - offset0[1];
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   802
        xi = xi - 2.0d * offset1[0]; yi = yi - 2.0d * offset1[1];
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   803
        x4p = x4 - offset2[0]; y4p = y4 - offset2[1];
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   804
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   805
        two_pi_m_p1_m_p4x = 2.0d * xi - x1p - x4p;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   806
        two_pi_m_p1_m_p4y = 2.0d * yi - y1p - y4p;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   807
        c1 = invdet43 * (dy4 * two_pi_m_p1_m_p4x - dx4 * two_pi_m_p1_m_p4y);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   808
        c2 = invdet43 * (dx1 * two_pi_m_p1_m_p4y - dy1 * two_pi_m_p1_m_p4x);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   809
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   810
        x2p = x1p + c1*dx1;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   811
        y2p = y1p + c1*dy1;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   812
        x3p = x4p + c2*dx4;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   813
        y3p = y4p + c2*dy4;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   814
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   815
        rightOff[0] = x1p; rightOff[1] = y1p;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   816
        rightOff[2] = x2p; rightOff[3] = y2p;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   817
        rightOff[4] = x3p; rightOff[5] = y3p;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   818
        rightOff[6] = x4p; rightOff[7] = y4p;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   819
        return 8;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   820
    }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   821
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   822
    // compute offset curves using bezier spline through t=0.5 (i.e.
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   823
    // ComputedCurve(0.5) == IdealParallelCurve(0.5))
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   824
    // return the kind of curve in the right and left arrays.
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   825
    private int computeOffsetQuad(double[] pts, final int off,
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   826
                                  double[] leftOff, double[] rightOff)
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   827
    {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   828
        final double x1 = pts[off + 0], y1 = pts[off + 1];
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   829
        final double x2 = pts[off + 2], y2 = pts[off + 3];
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   830
        final double x3 = pts[off + 4], y3 = pts[off + 5];
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   831
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   832
        final double dx3 = x3 - x2;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   833
        final double dy3 = y3 - y2;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   834
        final double dx1 = x2 - x1;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   835
        final double dy1 = y2 - y1;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   836
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   837
        // if p1=p2 or p3=p4 it means that the derivative at the endpoint
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   838
        // vanishes, which creates problems with computeOffset. Usually
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   839
        // this happens when this stroker object is trying to widen
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   840
        // a curve with a cusp. What happens is that curveTo splits
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   841
        // the input curve at the cusp, and passes it to this function.
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   842
        // because of inaccuracies in the splitting, we consider points
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   843
        // equal if they're very close to each other.
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   844
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   845
        // if p1 == p2 && p3 == p4: draw line from p1->p4, unless p1 == p4,
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   846
        // in which case ignore.
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   847
        final boolean p1eqp2 = within(x1, y1, x2, y2, 6.0d * Math.ulp(y2));
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   848
        final boolean p2eqp3 = within(x2, y2, x3, y3, 6.0d * Math.ulp(y3));
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   849
        if (p1eqp2 || p2eqp3) {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   850
            getLineOffsets(x1, y1, x3, y3, leftOff, rightOff);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   851
            return 4;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   852
        }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   853
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   854
        // if p2-p1 and p4-p3 are parallel, that must mean this curve is a line
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   855
        double dotsq = (dx1 * dx3 + dy1 * dy3);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   856
        dotsq *= dotsq;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   857
        double l1sq = dx1 * dx1 + dy1 * dy1, l3sq = dx3 * dx3 + dy3 * dy3;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   858
        if (DHelpers.within(dotsq, l1sq * l3sq, 4.0d * Math.ulp(dotsq))) {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   859
            getLineOffsets(x1, y1, x3, y3, leftOff, rightOff);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   860
            return 4;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   861
        }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   862
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   863
        // this computes the offsets at t=0, 0.5, 1, using the property that
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   864
        // for any bezier curve the vectors p2-p1 and p4-p3 are parallel to
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   865
        // the (dx/dt, dy/dt) vectors at the endpoints.
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   866
        computeOffset(dx1, dy1, lineWidth2, offset0);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   867
        computeOffset(dx3, dy3, lineWidth2, offset1);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   868
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   869
        double x1p = x1 + offset0[0]; // start
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   870
        double y1p = y1 + offset0[1]; // point
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   871
        double x3p = x3 + offset1[0]; // end
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   872
        double y3p = y3 + offset1[1]; // point
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   873
        safeComputeMiter(x1p, y1p, x1p+dx1, y1p+dy1, x3p, y3p, x3p-dx3, y3p-dy3, leftOff, 2);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   874
        leftOff[0] = x1p; leftOff[1] = y1p;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   875
        leftOff[4] = x3p; leftOff[5] = y3p;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   876
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   877
        x1p = x1 - offset0[0]; y1p = y1 - offset0[1];
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   878
        x3p = x3 - offset1[0]; y3p = y3 - offset1[1];
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   879
        safeComputeMiter(x1p, y1p, x1p+dx1, y1p+dy1, x3p, y3p, x3p-dx3, y3p-dy3, rightOff, 2);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   880
        rightOff[0] = x1p; rightOff[1] = y1p;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   881
        rightOff[4] = x3p; rightOff[5] = y3p;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   882
        return 6;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   883
    }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   884
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   885
    // finds values of t where the curve in pts should be subdivided in order
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   886
    // to get good offset curves a distance of w away from the middle curve.
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   887
    // Stores the points in ts, and returns how many of them there were.
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   888
    private static int findSubdivPoints(final DCurve c, double[] pts, double[] ts,
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   889
                                        final int type, final double w)
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   890
    {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   891
        final double x12 = pts[2] - pts[0];
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   892
        final double y12 = pts[3] - pts[1];
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   893
        // if the curve is already parallel to either axis we gain nothing
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   894
        // from rotating it.
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   895
        if (y12 != 0.0d && x12 != 0.0d) {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   896
            // we rotate it so that the first vector in the control polygon is
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   897
            // parallel to the x-axis. This will ensure that rotated quarter
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   898
            // circles won't be subdivided.
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   899
            final double hypot = Math.sqrt(x12 * x12 + y12 * y12);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   900
            final double cos = x12 / hypot;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   901
            final double sin = y12 / hypot;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   902
            final double x1 = cos * pts[0] + sin * pts[1];
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   903
            final double y1 = cos * pts[1] - sin * pts[0];
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   904
            final double x2 = cos * pts[2] + sin * pts[3];
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   905
            final double y2 = cos * pts[3] - sin * pts[2];
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   906
            final double x3 = cos * pts[4] + sin * pts[5];
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   907
            final double y3 = cos * pts[5] - sin * pts[4];
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   908
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   909
            switch(type) {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   910
            case 8:
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   911
                final double x4 = cos * pts[6] + sin * pts[7];
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   912
                final double y4 = cos * pts[7] - sin * pts[6];
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   913
                c.set(x1, y1, x2, y2, x3, y3, x4, y4);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   914
                break;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   915
            case 6:
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   916
                c.set(x1, y1, x2, y2, x3, y3);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   917
                break;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   918
            default:
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   919
            }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   920
        } else {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   921
            c.set(pts, type);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   922
        }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   923
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   924
        int ret = 0;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   925
        // we subdivide at values of t such that the remaining rotated
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   926
        // curves are monotonic in x and y.
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   927
        ret += c.dxRoots(ts, ret);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   928
        ret += c.dyRoots(ts, ret);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   929
        // subdivide at inflection points.
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   930
        if (type == 8) {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   931
            // quadratic curves can't have inflection points
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   932
            ret += c.infPoints(ts, ret);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   933
        }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   934
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   935
        // now we must subdivide at points where one of the offset curves will have
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   936
        // a cusp. This happens at ts where the radius of curvature is equal to w.
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   937
        ret += c.rootsOfROCMinusW(ts, ret, w, 0.0001d);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   938
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   939
        ret = DHelpers.filterOutNotInAB(ts, 0, ret, 0.0001d, 0.9999d);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   940
        DHelpers.isort(ts, 0, ret);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   941
        return ret;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   942
    }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   943
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   944
    @Override public void curveTo(double x1, double y1,
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   945
                                  double x2, double y2,
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   946
                                  double x3, double y3)
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   947
    {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   948
        final double[] mid = middle;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   949
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   950
        mid[0] = cx0; mid[1] = cy0;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   951
        mid[2] = x1;  mid[3] = y1;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   952
        mid[4] = x2;  mid[5] = y2;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   953
        mid[6] = x3;  mid[7] = y3;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   954
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   955
        // need these so we can update the state at the end of this method
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   956
        final double xf = mid[6], yf = mid[7];
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   957
        double dxs = mid[2] - mid[0];
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   958
        double dys = mid[3] - mid[1];
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   959
        double dxf = mid[6] - mid[4];
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   960
        double dyf = mid[7] - mid[5];
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   961
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   962
        boolean p1eqp2 = (dxs == 0.0d && dys == 0.0d);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   963
        boolean p3eqp4 = (dxf == 0.0d && dyf == 0.0d);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   964
        if (p1eqp2) {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   965
            dxs = mid[4] - mid[0];
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   966
            dys = mid[5] - mid[1];
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   967
            if (dxs == 0.0d && dys == 0.0d) {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   968
                dxs = mid[6] - mid[0];
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   969
                dys = mid[7] - mid[1];
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   970
            }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   971
        }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   972
        if (p3eqp4) {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   973
            dxf = mid[6] - mid[2];
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   974
            dyf = mid[7] - mid[3];
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   975
            if (dxf == 0.0d && dyf == 0.0d) {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   976
                dxf = mid[6] - mid[0];
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   977
                dyf = mid[7] - mid[1];
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   978
            }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   979
        }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   980
        if (dxs == 0.0d && dys == 0.0d) {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   981
            // this happens if the "curve" is just a point
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   982
            lineTo(mid[0], mid[1]);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   983
            return;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   984
        }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   985
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   986
        // if these vectors are too small, normalize them, to avoid future
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   987
        // precision problems.
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   988
        if (Math.abs(dxs) < 0.1d && Math.abs(dys) < 0.1d) {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   989
            double len = Math.sqrt(dxs*dxs + dys*dys);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   990
            dxs /= len;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   991
            dys /= len;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   992
        }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   993
        if (Math.abs(dxf) < 0.1d && Math.abs(dyf) < 0.1d) {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   994
            double len = Math.sqrt(dxf*dxf + dyf*dyf);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   995
            dxf /= len;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   996
            dyf /= len;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   997
        }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   998
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   999
        computeOffset(dxs, dys, lineWidth2, offset0);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1000
        drawJoin(cdx, cdy, cx0, cy0, dxs, dys, cmx, cmy, offset0[0], offset0[1]);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1001
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1002
        final int nSplits = findSubdivPoints(curve, mid, subdivTs, 8, lineWidth2);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1003
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1004
        double prevT = 0.0d;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1005
        for (int i = 0, off = 0; i < nSplits; i++, off += 6) {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1006
            final double t = subdivTs[i];
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1007
            DHelpers.subdivideCubicAt((t - prevT) / (1.0d - prevT),
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1008
                                     mid, off, mid, off, mid, off + 6);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1009
            prevT = t;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1010
        }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1011
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1012
        final double[] l = lp;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1013
        final double[] r = rp;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1014
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1015
        int kind = 0;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1016
        for (int i = 0, off = 0; i <= nSplits; i++, off += 6) {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1017
            kind = computeOffsetCubic(mid, off, l, r);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1018
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1019
            emitLineTo(l[0], l[1]);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1020
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1021
            switch(kind) {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1022
            case 8:
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1023
                emitCurveTo(l[2], l[3], l[4], l[5], l[6], l[7]);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1024
                emitCurveToRev(r[0], r[1], r[2], r[3], r[4], r[5]);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1025
                break;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1026
            case 4:
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1027
                emitLineTo(l[2], l[3]);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1028
                emitLineToRev(r[0], r[1]);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1029
                break;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1030
            default:
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1031
            }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1032
            emitLineToRev(r[kind - 2], r[kind - 1]);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1033
        }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1034
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1035
        this.cmx = (l[kind - 2] - r[kind - 2]) / 2.0d;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1036
        this.cmy = (l[kind - 1] - r[kind - 1]) / 2.0d;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1037
        this.cdx = dxf;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1038
        this.cdy = dyf;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1039
        this.cx0 = xf;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1040
        this.cy0 = yf;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1041
        this.prev = DRAWING_OP_TO;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1042
    }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1043
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1044
    @Override public void quadTo(double x1, double y1, double x2, double y2) {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1045
        final double[] mid = middle;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1046
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1047
        mid[0] = cx0; mid[1] = cy0;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1048
        mid[2] = x1;  mid[3] = y1;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1049
        mid[4] = x2;  mid[5] = y2;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1050
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1051
        // need these so we can update the state at the end of this method
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1052
        final double xf = mid[4], yf = mid[5];
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1053
        double dxs = mid[2] - mid[0];
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1054
        double dys = mid[3] - mid[1];
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1055
        double dxf = mid[4] - mid[2];
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1056
        double dyf = mid[5] - mid[3];
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1057
        if ((dxs == 0.0d && dys == 0.0d) || (dxf == 0.0d && dyf == 0.0d)) {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1058
            dxs = dxf = mid[4] - mid[0];
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1059
            dys = dyf = mid[5] - mid[1];
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1060
        }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1061
        if (dxs == 0.0d && dys == 0.0d) {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1062
            // this happens if the "curve" is just a point
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1063
            lineTo(mid[0], mid[1]);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1064
            return;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1065
        }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1066
        // if these vectors are too small, normalize them, to avoid future
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1067
        // precision problems.
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1068
        if (Math.abs(dxs) < 0.1d && Math.abs(dys) < 0.1d) {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1069
            double len = Math.sqrt(dxs*dxs + dys*dys);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1070
            dxs /= len;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1071
            dys /= len;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1072
        }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1073
        if (Math.abs(dxf) < 0.1d && Math.abs(dyf) < 0.1d) {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1074
            double len = Math.sqrt(dxf*dxf + dyf*dyf);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1075
            dxf /= len;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1076
            dyf /= len;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1077
        }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1078
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1079
        computeOffset(dxs, dys, lineWidth2, offset0);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1080
        drawJoin(cdx, cdy, cx0, cy0, dxs, dys, cmx, cmy, offset0[0], offset0[1]);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1081
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1082
        int nSplits = findSubdivPoints(curve, mid, subdivTs, 6, lineWidth2);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1083
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1084
        double prevt = 0.0d;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1085
        for (int i = 0, off = 0; i < nSplits; i++, off += 4) {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1086
            final double t = subdivTs[i];
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1087
            DHelpers.subdivideQuadAt((t - prevt) / (1.0d - prevt),
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1088
                                    mid, off, mid, off, mid, off + 4);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1089
            prevt = t;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1090
        }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1091
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1092
        final double[] l = lp;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1093
        final double[] r = rp;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1094
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1095
        int kind = 0;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1096
        for (int i = 0, off = 0; i <= nSplits; i++, off += 4) {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1097
            kind = computeOffsetQuad(mid, off, l, r);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1098
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1099
            emitLineTo(l[0], l[1]);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1100
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1101
            switch(kind) {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1102
            case 6:
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1103
                emitQuadTo(l[2], l[3], l[4], l[5]);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1104
                emitQuadToRev(r[0], r[1], r[2], r[3]);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1105
                break;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1106
            case 4:
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1107
                emitLineTo(l[2], l[3]);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1108
                emitLineToRev(r[0], r[1]);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1109
                break;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1110
            default:
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1111
            }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1112
            emitLineToRev(r[kind - 2], r[kind - 1]);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1113
        }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1114
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1115
        this.cmx = (l[kind - 2] - r[kind - 2]) / 2.0d;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1116
        this.cmy = (l[kind - 1] - r[kind - 1]) / 2.0d;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1117
        this.cdx = dxf;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1118
        this.cdy = dyf;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1119
        this.cx0 = xf;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1120
        this.cy0 = yf;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1121
        this.prev = DRAWING_OP_TO;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1122
    }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1123
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1124
    @Override public long getNativeConsumer() {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1125
        throw new InternalError("Stroker doesn't use a native consumer");
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1126
    }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1127
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1128
    // a stack of polynomial curves where each curve shares endpoints with
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1129
    // adjacent ones.
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1130
    static final class PolyStack {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1131
        private static final byte TYPE_LINETO  = (byte) 0;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1132
        private static final byte TYPE_QUADTO  = (byte) 1;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1133
        private static final byte TYPE_CUBICTO = (byte) 2;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1134
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1135
        // curves capacity = edges count (8192) = edges x 2 (coords)
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1136
        private static final int INITIAL_CURVES_COUNT = INITIAL_EDGES_COUNT << 1;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1137
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1138
        // types capacity = edges count (4096)
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1139
        private static final int INITIAL_TYPES_COUNT = INITIAL_EDGES_COUNT;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1140
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1141
        double[] curves;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1142
        int end;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1143
        byte[] curveTypes;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1144
        int numCurves;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1145
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1146
        // per-thread renderer context
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1147
        final DRendererContext rdrCtx;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1148
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1149
        // curves ref (dirty)
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1150
        final DoubleArrayCache.Reference curves_ref;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1151
        // curveTypes ref (dirty)
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1152
        final ByteArrayCache.Reference curveTypes_ref;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1153
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1154
        // used marks (stats only)
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1155
        int curveTypesUseMark;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1156
        int curvesUseMark;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1157
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1158
        /**
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1159
         * Constructor
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1160
         * @param rdrCtx per-thread renderer context
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1161
         */
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1162
        PolyStack(final DRendererContext rdrCtx) {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1163
            this.rdrCtx = rdrCtx;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1164
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1165
            curves_ref = rdrCtx.newDirtyDoubleArrayRef(INITIAL_CURVES_COUNT); // 32K
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1166
            curves     = curves_ref.initial;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1167
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1168
            curveTypes_ref = rdrCtx.newDirtyByteArrayRef(INITIAL_TYPES_COUNT); // 4K
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1169
            curveTypes     = curveTypes_ref.initial;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1170
            numCurves = 0;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1171
            end = 0;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1172
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1173
            if (DO_STATS) {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1174
                curveTypesUseMark = 0;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1175
                curvesUseMark = 0;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1176
            }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1177
        }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1178
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1179
        /**
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1180
         * Disposes this PolyStack:
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1181
         * clean up before reusing this instance
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1182
         */
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1183
        void dispose() {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1184
            end = 0;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1185
            numCurves = 0;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1186
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1187
            if (DO_STATS) {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1188
                rdrCtx.stats.stat_rdr_poly_stack_types.add(curveTypesUseMark);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1189
                rdrCtx.stats.stat_rdr_poly_stack_curves.add(curvesUseMark);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1190
                rdrCtx.stats.hist_rdr_poly_stack_curves.add(curvesUseMark);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1191
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1192
                // reset marks
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1193
                curveTypesUseMark = 0;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1194
                curvesUseMark = 0;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1195
            }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1196
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1197
            // Return arrays:
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1198
            // curves and curveTypes are kept dirty
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1199
            curves     = curves_ref.putArray(curves);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1200
            curveTypes = curveTypes_ref.putArray(curveTypes);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1201
        }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1202
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1203
        private void ensureSpace(final int n) {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1204
            // use substraction to avoid integer overflow:
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1205
            if (curves.length - end < n) {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1206
                if (DO_STATS) {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1207
                    rdrCtx.stats.stat_array_stroker_polystack_curves
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1208
                        .add(end + n);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1209
                }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1210
                curves = curves_ref.widenArray(curves, end, end + n);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1211
            }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1212
            if (curveTypes.length <= numCurves) {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1213
                if (DO_STATS) {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1214
                    rdrCtx.stats.stat_array_stroker_polystack_curveTypes
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1215
                        .add(numCurves + 1);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1216
                }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1217
                curveTypes = curveTypes_ref.widenArray(curveTypes,
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1218
                                                       numCurves,
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1219
                                                       numCurves + 1);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1220
            }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1221
        }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1222
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1223
        void pushCubic(double x0, double y0,
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1224
                       double x1, double y1,
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1225
                       double x2, double y2)
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1226
        {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1227
            ensureSpace(6);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1228
            curveTypes[numCurves++] = TYPE_CUBICTO;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1229
            // we reverse the coordinate order to make popping easier
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1230
            final double[] _curves = curves;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1231
            int e = end;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1232
            _curves[e++] = x2;    _curves[e++] = y2;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1233
            _curves[e++] = x1;    _curves[e++] = y1;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1234
            _curves[e++] = x0;    _curves[e++] = y0;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1235
            end = e;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1236
        }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1237
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1238
        void pushQuad(double x0, double y0,
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1239
                      double x1, double y1)
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1240
        {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1241
            ensureSpace(4);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1242
            curveTypes[numCurves++] = TYPE_QUADTO;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1243
            final double[] _curves = curves;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1244
            int e = end;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1245
            _curves[e++] = x1;    _curves[e++] = y1;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1246
            _curves[e++] = x0;    _curves[e++] = y0;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1247
            end = e;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1248
        }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1249
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1250
        void pushLine(double x, double y) {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1251
            ensureSpace(2);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1252
            curveTypes[numCurves++] = TYPE_LINETO;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1253
            curves[end++] = x;    curves[end++] = y;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1254
        }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1255
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1256
        void popAll(DPathConsumer2D io) {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1257
            if (DO_STATS) {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1258
                // update used marks:
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1259
                if (numCurves > curveTypesUseMark) {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1260
                    curveTypesUseMark = numCurves;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1261
                }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1262
                if (end > curvesUseMark) {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1263
                    curvesUseMark = end;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1264
                }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1265
            }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1266
            final byte[]  _curveTypes = curveTypes;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1267
            final double[] _curves = curves;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1268
            int nc = numCurves;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1269
            int e  = end;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1270
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1271
            while (nc != 0) {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1272
                switch(_curveTypes[--nc]) {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1273
                case TYPE_LINETO:
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1274
                    e -= 2;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1275
                    io.lineTo(_curves[e], _curves[e+1]);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1276
                    continue;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1277
                case TYPE_QUADTO:
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1278
                    e -= 4;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1279
                    io.quadTo(_curves[e+0], _curves[e+1],
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1280
                              _curves[e+2], _curves[e+3]);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1281
                    continue;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1282
                case TYPE_CUBICTO:
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1283
                    e -= 6;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1284
                    io.curveTo(_curves[e+0], _curves[e+1],
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1285
                               _curves[e+2], _curves[e+3],
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1286
                               _curves[e+4], _curves[e+5]);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1287
                    continue;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1288
                default:
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1289
                }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1290
            }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1291
            numCurves = 0;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1292
            end = 0;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1293
        }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1294
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1295
        @Override
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1296
        public String toString() {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1297
            String ret = "";
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1298
            int nc = numCurves;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1299
            int last = end;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1300
            int len;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1301
            while (nc != 0) {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1302
                switch(curveTypes[--nc]) {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1303
                case TYPE_LINETO:
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1304
                    len = 2;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1305
                    ret += "line: ";
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1306
                    break;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1307
                case TYPE_QUADTO:
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1308
                    len = 4;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1309
                    ret += "quad: ";
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1310
                    break;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1311
                case TYPE_CUBICTO:
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1312
                    len = 6;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1313
                    ret += "cubic: ";
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1314
                    break;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1315
                default:
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1316
                    len = 0;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1317
                }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1318
                last -= len;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1319
                ret += Arrays.toString(Arrays.copyOfRange(curves, last, last+len))
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1320
                                       + "\n";
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1321
            }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1322
            return ret;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1323
        }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1324
    }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
  1325
}