PolylineShape.java

1
/*
2
 * $Id: PolylineShape.java 3117 2008-01-31 05:53:22Z xlv $
3
 *
4
 * Copyright 2007 Bruno Lowagie and Wil
5
 *
6
 * The contents of this file are subject to the Mozilla Public License Version 1.1
7
 * (the "License"); you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at http://www.mozilla.org/MPL/
9
 *
10
 * Software distributed under the License is distributed on an "AS IS" basis,
11
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12
 * for the specific language governing rights and limitations under the License.
13
 *
14
 * The Original Code is 'iText, a free JAVA-PDF library'.
15
 *
16
 * The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
17
 * the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
18
 * All Rights Reserved.
19
 * Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
20
 * are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
21
 *
22
 * Contributor(s): all the names of the contributors are added in the source code
23
 * where applicable.
24
 *
25
 * Alternatively, the contents of this file may be used under the terms of the
26
 * LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
27
 * provisions of LGPL are applicable instead of those above.  If you wish to
28
 * allow use of your version of this file only under the terms of the LGPL
29
 * License and not to allow others to use your version of this file under
30
 * the MPL, indicate your decision by deleting the provisions above and
31
 * replace them with the notice and other provisions required by the LGPL.
32
 * If you do not delete the provisions above, a recipient may use your version
33
 * of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
34
 *
35
 * This library is free software; you can redistribute it and/or modify it
36
 * under the terms of the MPL as stated above or under the terms of the GNU
37
 * Library General Public License as published by the Free Software Foundation;
38
 * either version 2 of the License, or any later version.
39
 *
40
 * This library is distributed in the hope that it will be useful, but WITHOUT
41
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
42
 * FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more
43
 * details.
44
 *
45
 * If you didn't download this code from the following link, you should check if
46
 * you aren't using an obsolete version:
47
 * http://www.lowagie.com/iText/
48
 */
49
50
package com.lowagie.text.pdf.internal;
51
52
import java.awt.Shape;
53
import java.awt.Rectangle;
54
import java.awt.geom.AffineTransform;
55
import java.awt.geom.PathIterator;
56
import java.awt.geom.Line2D;
57
import java.awt.geom.Point2D;
58
import java.awt.geom.Rectangle2D;
59
60
/**
61
 * Class that defines a Polyline shape.
62
 * This class was originally written by wil - amristar.com.au
63
 * and integrated into iText by Bruno.
64
 */
65
public class PolylineShape implements Shape {
66
    /** All the X-values of the coordinates in the polyline. */
67
    protected int[] x;
68
    /** All the Y-values of the coordinates in the polyline. */
69
    protected int[] y;
70
    /** The total number of points. */
71
    protected int np;
72
73
    /** Creates a PolylineShape. */
74
    public PolylineShape(int[] x, int[] y, int nPoints) {
75
        // Should copy array (as done in Polygon)
76
        this.np = nPoints;
77
        // Take a copy.
78
        this.x = new int[np];
79
        this.y = new int[np];
80 1 1. : removed call to java/lang/System::arraycopy → NO_COVERAGE
        System.arraycopy(x, 0, this.x, 0, np);
81 1 1. : removed call to java/lang/System::arraycopy → NO_COVERAGE
        System.arraycopy(y, 0, this.y, 0, np);
82
    }
83
84
    /**
85
     * Returns the bounding box of this polyline.
86
     *
87
     * @return a {@link Rectangle2D} that is the high-precision
88
     *     bounding box of this line.
89
     * @see java.awt.Shape#getBounds2D()
90
     */
91
    public Rectangle2D getBounds2D() {
92
        int[] r = rect();
93 2 1. getBounds2D : negated conditional → NO_COVERAGE
2. getBounds2D : mutated return of Object value for com/lowagie/text/pdf/internal/PolylineShape::getBounds2D to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE
        return r==null?null:new Rectangle2D.Double(r[0], r[1], r[2], r[3]);
94
    }
95
    
96
    /**
97
     * Returns the bounding box of this polyline.
98
     * @see java.awt.Shape#getBounds()
99
     */
100
    public Rectangle getBounds() {
101 1 1. getBounds : mutated return of Object value for com/lowagie/text/pdf/internal/PolylineShape::getBounds to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE
        return getBounds2D().getBounds();
102
    }
103
104
    /**
105
     * Calculates the origin (X, Y) and the width and height
106
     * of a rectangle that contains all the segments of the
107
     * polyline.
108
     */
109
    private int[] rect() {
110 2 1. rect : negated conditional → NO_COVERAGE
2. rect : mutated return of Object value for com/lowagie/text/pdf/internal/PolylineShape::rect to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE
         if(np==0)return null;
111
        int xMin = x[0], yMin=y[0], xMax=x[0],yMax=y[0];
112
113 3 1. rect : changed conditional boundary → NO_COVERAGE
2. rect : Changed increment from 1 to -1 → NO_COVERAGE
3. rect : negated conditional → NO_COVERAGE
         for(int i=1;i<np;i++) {
114 2 1. rect : changed conditional boundary → NO_COVERAGE
2. rect : negated conditional → NO_COVERAGE
             if(x[i]<xMin)xMin=x[i];
115 2 1. rect : changed conditional boundary → NO_COVERAGE
2. rect : negated conditional → NO_COVERAGE
             else if(x[i]>xMax)xMax=x[i];
116 2 1. rect : changed conditional boundary → NO_COVERAGE
2. rect : negated conditional → NO_COVERAGE
             if(y[i]<yMin)yMin=y[i];
117 2 1. rect : changed conditional boundary → NO_COVERAGE
2. rect : negated conditional → NO_COVERAGE
             else if(y[i]>yMax)yMax=y[i];
118
         }
119
120 3 1. rect : Replaced integer subtraction with addition → NO_COVERAGE
2. rect : Replaced integer subtraction with addition → NO_COVERAGE
3. rect : mutated return of Object value for com/lowagie/text/pdf/internal/PolylineShape::rect to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE
         return new int[] { xMin, yMin, xMax-xMin, yMax-yMin };
121
    }
122
123
    /**
124
     * A polyline can't contain a point.
125
     * @see java.awt.Shape#contains(double, double)
126
     */
127
    public boolean contains(double x, double y) { return false; }
128
    
129
    /**
130
     * A polyline can't contain a point.
131
     * @see java.awt.Shape#contains(java.awt.geom.Point2D)
132
     */
133
    public boolean contains(Point2D p) { return false; }
134
    
135
    /**
136
     * A polyline can't contain a point.
137
     * @see java.awt.Shape#contains(double, double, double, double)
138
     */
139
    public boolean contains(double x, double y, double w, double h) { return false; }
140
    
141
    /**
142
     * A polyline can't contain a point.
143
     * @see java.awt.Shape#contains(java.awt.geom.Rectangle2D)
144
     */
145
    public boolean contains(Rectangle2D r) { return false; }
146
147
    /**
148
     * Checks if one of the lines in the polyline intersects
149
     * with a given rectangle.
150
     * @see java.awt.Shape#intersects(double, double, double, double)
151
     */
152
    public boolean intersects(double x, double y, double w, double h) {
153 1 1. intersects : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE
        return intersects(new Rectangle2D.Double(x, y, w, h));
154
    }
155
156
    /**
157
     * Checks if one of the lines in the polyline intersects
158
     * with a given rectangle.
159
     * @see java.awt.Shape#intersects(java.awt.geom.Rectangle2D)
160
     */
161
    public boolean intersects(Rectangle2D r) {
162 2 1. intersects : negated conditional → NO_COVERAGE
2. intersects : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE
        if(np==0)return false;
163
        Line2D line = new Line2D.Double(x[0],y[0],x[0],y[0]);
164 3 1. intersects : changed conditional boundary → NO_COVERAGE
2. intersects : Changed increment from 1 to -1 → NO_COVERAGE
3. intersects : negated conditional → NO_COVERAGE
        for (int i = 1; i < np; i++) {
165 3 1. intersects : Replaced integer subtraction with addition → NO_COVERAGE
2. intersects : Replaced integer subtraction with addition → NO_COVERAGE
3. intersects : removed call to java/awt/geom/Line2D::setLine → NO_COVERAGE
            line.setLine(x[i-1], y[i-1], x[i], y[i]);
166 2 1. intersects : negated conditional → NO_COVERAGE
2. intersects : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE
            if(line.intersects(r))return true;
167
        }
168 1 1. intersects : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE
        return false;
169
    }
170
171
    /**
172
     * Returns an iteration object that defines the boundary of the polyline.
173
     * @param at the specified {@link AffineTransform}
174
     * @return a {@link PathIterator} that defines the boundary of this polyline.
175
     * @see java.awt.Shape#intersects(java.awt.geom.Rectangle2D)
176
     */
177
    public PathIterator getPathIterator(AffineTransform at) {
178 1 1. getPathIterator : mutated return of Object value for com/lowagie/text/pdf/internal/PolylineShape::getPathIterator to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE
        return new PolylineShapeIterator(this, at);
179
    }
180
181
    /**
182
     * There's no difference with getPathIterator(AffineTransform at);
183
     * we just need this method to implement the Shape interface.
184
     */
185
    public PathIterator getPathIterator(AffineTransform at, double flatness) {
186 1 1. getPathIterator : mutated return of Object value for com/lowagie/text/pdf/internal/PolylineShape::getPathIterator to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE
        return new PolylineShapeIterator(this, at);
187
    }
188
189
}
190

Mutations

80

1.1
Location :
Killed by : none
removed call to java/lang/System::arraycopy → NO_COVERAGE

81

1.1
Location :
Killed by : none
removed call to java/lang/System::arraycopy → NO_COVERAGE

93

1.1
Location : getBounds2D
Killed by : none
negated conditional → NO_COVERAGE

2.2
Location : getBounds2D
Killed by : none
mutated return of Object value for com/lowagie/text/pdf/internal/PolylineShape::getBounds2D to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE

101

1.1
Location : getBounds
Killed by : none
mutated return of Object value for com/lowagie/text/pdf/internal/PolylineShape::getBounds to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE

110

1.1
Location : rect
Killed by : none
negated conditional → NO_COVERAGE

2.2
Location : rect
Killed by : none
mutated return of Object value for com/lowagie/text/pdf/internal/PolylineShape::rect to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE

113

1.1
Location : rect
Killed by : none
changed conditional boundary → NO_COVERAGE

2.2
Location : rect
Killed by : none
Changed increment from 1 to -1 → NO_COVERAGE

3.3
Location : rect
Killed by : none
negated conditional → NO_COVERAGE

114

1.1
Location : rect
Killed by : none
changed conditional boundary → NO_COVERAGE

2.2
Location : rect
Killed by : none
negated conditional → NO_COVERAGE

115

1.1
Location : rect
Killed by : none
changed conditional boundary → NO_COVERAGE

2.2
Location : rect
Killed by : none
negated conditional → NO_COVERAGE

116

1.1
Location : rect
Killed by : none
changed conditional boundary → NO_COVERAGE

2.2
Location : rect
Killed by : none
negated conditional → NO_COVERAGE

117

1.1
Location : rect
Killed by : none
changed conditional boundary → NO_COVERAGE

2.2
Location : rect
Killed by : none
negated conditional → NO_COVERAGE

120

1.1
Location : rect
Killed by : none
Replaced integer subtraction with addition → NO_COVERAGE

2.2
Location : rect
Killed by : none
Replaced integer subtraction with addition → NO_COVERAGE

3.3
Location : rect
Killed by : none
mutated return of Object value for com/lowagie/text/pdf/internal/PolylineShape::rect to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE

153

1.1
Location : intersects
Killed by : none
replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE

162

1.1
Location : intersects
Killed by : none
negated conditional → NO_COVERAGE

2.2
Location : intersects
Killed by : none
replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE

164

1.1
Location : intersects
Killed by : none
changed conditional boundary → NO_COVERAGE

2.2
Location : intersects
Killed by : none
Changed increment from 1 to -1 → NO_COVERAGE

3.3
Location : intersects
Killed by : none
negated conditional → NO_COVERAGE

165

1.1
Location : intersects
Killed by : none
Replaced integer subtraction with addition → NO_COVERAGE

2.2
Location : intersects
Killed by : none
Replaced integer subtraction with addition → NO_COVERAGE

3.3
Location : intersects
Killed by : none
removed call to java/awt/geom/Line2D::setLine → NO_COVERAGE

166

1.1
Location : intersects
Killed by : none
negated conditional → NO_COVERAGE

2.2
Location : intersects
Killed by : none
replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE

168

1.1
Location : intersects
Killed by : none
replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE

178

1.1
Location : getPathIterator
Killed by : none
mutated return of Object value for com/lowagie/text/pdf/internal/PolylineShape::getPathIterator to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE

186

1.1
Location : getPathIterator
Killed by : none
mutated return of Object value for com/lowagie/text/pdf/internal/PolylineShape::getPathIterator to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT 1.4.2