Revision 35714

View differences:

tags/v1_11_0_Build_1306/libraries/libGeoUtils/build.xml
1
<project name="libGeoUtils" default="create-jar" basedir=".">
2
  	<!-- set global properties for this build -->
3
	<property name="src"  location="src"/>
4
	<property name="src-test" location="src-test"/>
5
	<property name="build"  location="bin"/>
6
	<property name="build-test" location="bin-test"/>
7
	<property name="dist"  location="dist"/>
8
	<property name="targetDir" location="../libFMap/lib"/>
9
	<property name="jarName" value="geoutils.jar"/>
10
	<import file="../binaries/ant/utilities.xml"/>
11

  
12
  <target name="init">
13
    <!-- Create the time stamp -->
14
<!--    <tstamp/>-->
15
	<echo>
16
		Compiling ${ant.project.name}...</echo>
17
  </target>
18

  
19
	<target name="batch-build"
20
				description="compile the sources, create the jar file"
21
				depends="init,compile,create-jar">
22
	</target>
23

  
24
	<target name="compile" description="compile the source">
25
		<!-- Compile the Java code from ${src} to ${build} -->
26
		<mkdir dir="${build}" />
27
		<loadEclipseClasspath project="${basedir}"/>
28
		<gvSIG-javac
29
			classpath="${eclipseClasspath}"
30
		/>
31
		<copy todir="${build}">
32
			<fileset dir="${src}" excludes="**/*.java" casesensitive="false"/>
33
		</copy>
34
	</target>
35

  
36
	<target name="create-jar" description="Crea el jar de la aplicacion">
37
		<!--<mkdir dir="${dist}" />-->
38
	  	<jar jarfile="${targetDir}/${jarName}" basedir="${build}"/>
39
	</target>
40

  
41
	<target name="clean" description="clean up">
42
		<!-- Delete the ${build} and ${dist} directory trees -->
43
		<delete dir="${build}" />
44
		<delete dir="${dist}" />
45
	</target>
46

  
47
	<target name="run-tests" depends="batch-build,compile-tests">
48
		<antcall target="generic-run-tests">
49
			<param name="TestSuite.Name" value="com.iver.utiles.AllTests"/>
50
		</antcall>
51
	</target>
52
</project>
0 53

  
tags/v1_11_0_Build_1306/libraries/libGeoUtils/.classpath
1
<?xml version="1.0" encoding="UTF-8"?>
2
<classpath>
3
	<classpathentry kind="src" path="src"/>
4
	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
5
	<classpathentry kind="output" path="bin"/>
6
</classpath>
0 7

  
tags/v1_11_0_Build_1306/libraries/libGeoUtils/SUN-LICENSE.txt
1
The GNU General Public License (GPL)
2

  
3
Version 2, June 1991
4

  
5
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
6
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
7

  
8
Everyone is permitted to copy and distribute verbatim copies of this license
9
document, but changing it is not allowed.
10

  
11
Preamble
12

  
13
The licenses for most software are designed to take away your freedom to share
14
and change it.  By contrast, the GNU General Public License is intended to
15
guarantee your freedom to share and change free software--to make sure the
16
software is free for all its users.  This General Public License applies to
17
most of the Free Software Foundation's software and to any other program whose
18
authors commit to using it.  (Some other Free Software Foundation software is
19
covered by the GNU Library General Public License instead.) You can apply it to
20
your programs, too.
21

  
22
When we speak of free software, we are referring to freedom, not price.  Our
23
General Public Licenses are designed to make sure that you have the freedom to
24
distribute copies of free software (and charge for this service if you wish),
25
that you receive source code or can get it if you want it, that you can change
26
the software or use pieces of it in new free programs; and that you know you
27
can do these things.
28

  
29
To protect your rights, we need to make restrictions that forbid anyone to deny
30
you these rights or to ask you to surrender the rights.  These restrictions
31
translate to certain responsibilities for you if you distribute copies of the
32
software, or if you modify it.
33

  
34
For example, if you distribute copies of such a program, whether gratis or for
35
a fee, you must give the recipients all the rights that you have.  You must
36
make sure that they, too, receive or can get the source code.  And you must
37
show them these terms so they know their rights.
38

  
39
We protect your rights with two steps: (1) copyright the software, and (2)
40
offer you this license which gives you legal permission to copy, distribute
41
and/or modify the software.
42

  
43
Also, for each author's protection and ours, we want to make certain that
44
everyone understands that there is no warranty for this free software.  If the
45
software is modified by someone else and passed on, we want its recipients to
46
know that what they have is not the original, so that any problems introduced
47
by others will not reflect on the original authors' reputations.
48

  
49
Finally, any free program is threatened constantly by software patents.  We
50
wish to avoid the danger that redistributors of a free program will
51
individually obtain patent licenses, in effect making the program proprietary.
52
To prevent this, we have made it clear that any patent must be licensed for
53
everyone's free use or not licensed at all.
54

  
55
The precise terms and conditions for copying, distribution and modification
56
follow.
57

  
58
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
59

  
60
0. This License applies to any program or other work which contains a notice
61
placed by the copyright holder saying it may be distributed under the terms of
62
this General Public License.  The "Program", below, refers to any such program
63
or work, and a "work based on the Program" means either the Program or any
64
derivative work under copyright law: that is to say, a work containing the
65
Program or a portion of it, either verbatim or with modifications and/or
66
translated into another language.  (Hereinafter, translation is included
67
without limitation in the term "modification".) Each licensee is addressed as
68
"you".
69

  
70
Activities other than copying, distribution and modification are not covered by
71
this License; they are outside its scope.  The act of running the Program is
72
not restricted, and the output from the Program is covered only if its contents
73
constitute a work based on the Program (independent of having been made by
74
running the Program).  Whether that is true depends on what the Program does.
75

  
76
1. You may copy and distribute verbatim copies of the Program's source code as
77
you receive it, in any medium, provided that you conspicuously and
78
appropriately publish on each copy an appropriate copyright notice and
79
disclaimer of warranty; keep intact all the notices that refer to this License
80
and to the absence of any warranty; and give any other recipients of the
81
Program a copy of this License along with the Program.
82

  
83
You may charge a fee for the physical act of transferring a copy, and you may
84
at your option offer warranty protection in exchange for a fee.
85

  
86
2. You may modify your copy or copies of the Program or any portion of it, thus
87
forming a work based on the Program, and copy and distribute such modifications
88
or work under the terms of Section 1 above, provided that you also meet all of
89
these conditions:
90

  
91
    a) You must cause the modified files to carry prominent notices stating
92
    that you changed the files and the date of any change.
93

  
94
    b) You must cause any work that you distribute or publish, that in whole or
95
    in part contains or is derived from the Program or any part thereof, to be
96
    licensed as a whole at no charge to all third parties under the terms of
97
    this License.
98

  
99
    c) If the modified program normally reads commands interactively when run,
100
    you must cause it, when started running for such interactive use in the
101
    most ordinary way, to print or display an announcement including an
102
    appropriate copyright notice and a notice that there is no warranty (or
103
    else, saying that you provide a warranty) and that users may redistribute
104
    the program under these conditions, and telling the user how to view a copy
105
    of this License.  (Exception: if the Program itself is interactive but does
106
    not normally print such an announcement, your work based on the Program is
107
    not required to print an announcement.)
108

  
109
These requirements apply to the modified work as a whole.  If identifiable
110
sections of that work are not derived from the Program, and can be reasonably
111
considered independent and separate works in themselves, then this License, and
112
its terms, do not apply to those sections when you distribute them as separate
113
works.  But when you distribute the same sections as part of a whole which is a
114
work based on the Program, the distribution of the whole must be on the terms
115
of this License, whose permissions for other licensees extend to the entire
116
whole, and thus to each and every part regardless of who wrote it.
117

  
118
Thus, it is not the intent of this section to claim rights or contest your
119
rights to work written entirely by you; rather, the intent is to exercise the
120
right to control the distribution of derivative or collective works based on
121
the Program.
122

  
123
In addition, mere aggregation of another work not based on the Program with the
124
Program (or with a work based on the Program) on a volume of a storage or
125
distribution medium does not bring the other work under the scope of this
126
License.
127

  
128
3. You may copy and distribute the Program (or a work based on it, under
129
Section 2) in object code or executable form under the terms of Sections 1 and
130
2 above provided that you also do one of the following:
131

  
132
    a) Accompany it with the complete corresponding machine-readable source
133
    code, which must be distributed under the terms of Sections 1 and 2 above
134
    on a medium customarily used for software interchange; or,
135

  
136
    b) Accompany it with a written offer, valid for at least three years, to
137
    give any third party, for a charge no more than your cost of physically
138
    performing source distribution, a complete machine-readable copy of the
139
    corresponding source code, to be distributed under the terms of Sections 1
140
    and 2 above on a medium customarily used for software interchange; or,
141

  
142
    c) Accompany it with the information you received as to the offer to
143
    distribute corresponding source code.  (This alternative is allowed only
144
    for noncommercial distribution and only if you received the program in
145
    object code or executable form with such an offer, in accord with
146
    Subsection b above.)
147

  
148
The source code for a work means the preferred form of the work for making
149
modifications to it.  For an executable work, complete source code means all
150
the source code for all modules it contains, plus any associated interface
151
definition files, plus the scripts used to control compilation and installation
152
of the executable.  However, as a special exception, the source code
153
distributed need not include anything that is normally distributed (in either
154
source or binary form) with the major components (compiler, kernel, and so on)
155
of the operating system on which the executable runs, unless that component
156
itself accompanies the executable.
157

  
158
If distribution of executable or object code is made by offering access to copy
159
from a designated place, then offering equivalent access to copy the source
160
code from the same place counts as distribution of the source code, even though
161
third parties are not compelled to copy the source along with the object code.
162

  
163
4. You may not copy, modify, sublicense, or distribute the Program except as
164
expressly provided under this License.  Any attempt otherwise to copy, modify,
165
sublicense or distribute the Program is void, and will automatically terminate
166
your rights under this License.  However, parties who have received copies, or
167
rights, from you under this License will not have their licenses terminated so
168
long as such parties remain in full compliance.
169

  
170
5. You are not required to accept this License, since you have not signed it.
171
However, nothing else grants you permission to modify or distribute the Program
172
or its derivative works.  These actions are prohibited by law if you do not
173
accept this License.  Therefore, by modifying or distributing the Program (or
174
any work based on the Program), you indicate your acceptance of this License to
175
do so, and all its terms and conditions for copying, distributing or modifying
176
the Program or works based on it.
177

  
178
6. Each time you redistribute the Program (or any work based on the Program),
179
the recipient automatically receives a license from the original licensor to
180
copy, distribute or modify the Program subject to these terms and conditions.
181
You may not impose any further restrictions on the recipients' exercise of the
182
rights granted herein.  You are not responsible for enforcing compliance by
183
third parties to this License.
184

  
185
7. If, as a consequence of a court judgment or allegation of patent
186
infringement or for any other reason (not limited to patent issues), conditions
187
are imposed on you (whether by court order, agreement or otherwise) that
188
contradict the conditions of this License, they do not excuse you from the
189
conditions of this License.  If you cannot distribute so as to satisfy
190
simultaneously your obligations under this License and any other pertinent
191
obligations, then as a consequence you may not distribute the Program at all.
192
For example, if a patent license would not permit royalty-free redistribution
193
of the Program by all those who receive copies directly or indirectly through
194
you, then the only way you could satisfy both it and this License would be to
195
refrain entirely from distribution of the Program.
196

  
197
If any portion of this section is held invalid or unenforceable under any
198
particular circumstance, the balance of the section is intended to apply and
199
the section as a whole is intended to apply in other circumstances.
200

  
201
It is not the purpose of this section to induce you to infringe any patents or
202
other property right claims or to contest validity of any such claims; this
203
section has the sole purpose of protecting the integrity of the free software
204
distribution system, which is implemented by public license practices.  Many
205
people have made generous contributions to the wide range of software
206
distributed through that system in reliance on consistent application of that
207
system; it is up to the author/donor to decide if he or she is willing to
208
distribute software through any other system and a licensee cannot impose that
209
choice.
210

  
211
This section is intended to make thoroughly clear what is believed to be a
212
consequence of the rest of this License.
213

  
214
8. If the distribution and/or use of the Program is restricted in certain
215
countries either by patents or by copyrighted interfaces, the original
216
copyright holder who places the Program under this License may add an explicit
217
geographical distribution limitation excluding those countries, so that
218
distribution is permitted only in or among countries not thus excluded.  In
219
such case, this License incorporates the limitation as if written in the body
220
of this License.
221

  
222
9. The Free Software Foundation may publish revised and/or new versions of the
223
General Public License from time to time.  Such new versions will be similar in
224
spirit to the present version, but may differ in detail to address new problems
225
or concerns.
226

  
227
Each version is given a distinguishing version number.  If the Program
228
specifies a version number of this License which applies to it and "any later
229
version", you have the option of following the terms and conditions either of
230
that version or of any later version published by the Free Software Foundation.
231
If the Program does not specify a version number of this License, you may
232
choose any version ever published by the Free Software Foundation.
233

  
234
10. If you wish to incorporate parts of the Program into other free programs
235
whose distribution conditions are different, write to the author to ask for
236
permission.  For software which is copyrighted by the Free Software Foundation,
237
write to the Free Software Foundation; we sometimes make exceptions for this.
238
Our decision will be guided by the two goals of preserving the free status of
239
all derivatives of our free software and of promoting the sharing and reuse of
240
software generally.
241

  
242
NO WARRANTY
243

  
244
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR
245
THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN OTHERWISE
246
STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE
247
PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED,
248
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
249
FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND
250
PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE PROGRAM PROVE DEFECTIVE,
251
YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
252

  
253
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL
254
ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE
255
PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
256
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR
257
INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA
258
BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
259
FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER
260
OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
261

  
262
END OF TERMS AND CONDITIONS
263

  
264
How to Apply These Terms to Your New Programs
265

  
266
If you develop a new program, and you want it to be of the greatest possible
267
use to the public, the best way to achieve this is to make it free software
268
which everyone can redistribute and change under these terms.
269

  
270
To do so, attach the following notices to the program.  It is safest to attach
271
them to the start of each source file to most effectively convey the exclusion
272
of warranty; and each file should have at least the "copyright" line and a
273
pointer to where the full notice is found.
274

  
275
    One line to give the program's name and a brief idea of what it does.
276

  
277
    Copyright (C) <year> <name of author>
278

  
279
    This program is free software; you can redistribute it and/or modify it
280
    under the terms of the GNU General Public License as published by the Free
281
    Software Foundation; either version 2 of the License, or (at your option)
282
    any later version.
283

  
284
    This program is distributed in the hope that it will be useful, but WITHOUT
285
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
286
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
287
    more details.
288

  
289
    You should have received a copy of the GNU General Public License along
290
    with this program; if not, write to the Free Software Foundation, Inc., 59
291
    Temple Place, Suite 330, Boston, MA 02111-1307 USA
292

  
293
Also add information on how to contact you by electronic and paper mail.
294

  
295
If the program is interactive, make it output a short notice like this when it
296
starts in an interactive mode:
297

  
298
    Gnomovision version 69, Copyright (C) year name of author Gnomovision comes
299
    with ABSOLUTELY NO WARRANTY; for details type 'show w'.  This is free
300
    software, and you are welcome to redistribute it under certain conditions;
301
    type 'show c' for details.
302

  
303
The hypothetical commands 'show w' and 'show c' should show the appropriate
304
parts of the General Public License.  Of course, the commands you use may be
305
called something other than 'show w' and 'show c'; they could even be
306
mouse-clicks or menu items--whatever suits your program.
307

  
308
You should also get your employer (if you work as a programmer) or your school,
309
if any, to sign a "copyright disclaimer" for the program, if necessary.  Here
310
is a sample; alter the names:
311

  
312
    Yoyodyne, Inc., hereby disclaims all copyright interest in the program
313
    'Gnomovision' (which makes passes at compilers) written by James Hacker.
314

  
315
    signature of Ty Coon, 1 April 1989
316

  
317
    Ty Coon, President of Vice
318

  
319
This General Public License does not permit incorporating your program into
320
proprietary programs.  If your program is a subroutine library, you may
321
consider it more useful to permit linking proprietary applications with the
322
library.  If this is what you want to do, use the GNU Library General Public
323
License instead of this License.
324

  
325

  
326
"CLASSPATH" EXCEPTION TO THE GPL
327

  
328
Certain source files distributed by Sun Microsystems, Inc.  are subject to
329
the following clarification and special exception to the GPL, but only where
330
Sun has expressly included in the particular source file's header the words
331
"Sun designates this particular file as subject to the "Classpath" exception
332
as provided by Sun in the LICENSE file that accompanied this code."
333

  
334
    Linking this library statically or dynamically with other modules is making
335
    a combined work based on this library.  Thus, the terms and conditions of
336
    the GNU General Public License cover the whole combination.
337

  
338
    As a special exception, the copyright holders of this library give you
339
    permission to link this library with independent modules to produce an
340
    executable, regardless of the license terms of these independent modules,
341
    and to copy and distribute the resulting executable under terms of your
342
    choice, provided that you also meet, for each linked independent module,
343
    the terms and conditions of the license of that module.  An independent
344
    module is a module which is not derived from or based on this library.  If
345
    you modify this library, you may extend this exception to your version of
346
    the library, but you are not obligated to do so.  If you do not wish to do
347
    so, delete this exception statement from your version.
0 348

  
tags/v1_11_0_Build_1306/libraries/libGeoUtils/.project
1
<?xml version="1.0" encoding="UTF-8"?>
2
<projectDescription>
3
	<name>libGeoUtils</name>
4
	<comment></comment>
5
	<projects>
6
	</projects>
7
	<buildSpec>
8
		<buildCommand>
9
			<name>org.eclipse.jdt.core.javabuilder</name>
10
			<arguments>
11
			</arguments>
12
		</buildCommand>
13
	</buildSpec>
14
	<natures>
15
		<nature>org.eclipse.jdt.core.javanature</nature>
16
	</natures>
17
</projectDescription>
0 18

  
tags/v1_11_0_Build_1306/libraries/libGeoUtils/src/org/gvsig/geoutils/sun/awt/geom/Order0.java
1
/*
2
 * Copyright 1998 Sun Microsystems, Inc.  All Rights Reserved.
3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
 *
5
 * This code is free software; you can redistribute it and/or modify it
6
 * under the terms of the GNU General Public License version 2 only, as
7
 * published by the Free Software Foundation.  Sun designates this
8
 * particular file as subject to the "Classpath" exception as provided
9
 * by Sun in the LICENSE file that accompanied this code.
10
 *
11
 * This code is distributed in the hope that it will be useful, but WITHOUT
12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14
 * version 2 for more details (a copy is included in the LICENSE file that
15
 * accompanied this code).
16
 *
17
 * You should have received a copy of the GNU General Public License version
18
 * 2 along with this work; if not, write to the Free Software Foundation,
19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20
 *
21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22
 * CA 95054 USA or visit www.sun.com if you need additional information or
23
 * have any questions.
24
 */
25

  
26
package org.gvsig.geoutils.sun.awt.geom;
27

  
28
import java.awt.geom.PathIterator;
29
import java.awt.geom.Rectangle2D;
30

  
31
final class Order0 extends Curve {
32
    private double x;
33
    private double y;
34

  
35
    public Order0(double x, double y) {
36
        super(INCREASING);
37
        this.x = x;
38
        this.y = y;
39
    }
40

  
41
    public int getOrder() {
42
        return 0;
43
    }
44

  
45
    public double getXTop() {
46
        return x;
47
    }
48

  
49
    public double getYTop() {
50
        return y;
51
    }
52

  
53
    public double getXBot() {
54
        return x;
55
    }
56

  
57
    public double getYBot() {
58
        return y;
59
    }
60

  
61
    public double getXMin() {
62
        return x;
63
    }
64

  
65
    public double getXMax() {
66
        return x;
67
    }
68

  
69
    public double getX0() {
70
        return x;
71
    }
72

  
73
    public double getY0() {
74
        return y;
75
    }
76

  
77
    public double getX1() {
78
        return x;
79
    }
80

  
81
    public double getY1() {
82
        return y;
83
    }
84

  
85
    public double XforY(double y) {
86
        return y;
87
    }
88

  
89
    public double TforY(double y) {
90
        return 0;
91
    }
92

  
93
    public double XforT(double t) {
94
        return x;
95
    }
96

  
97
    public double YforT(double t) {
98
        return y;
99
    }
100

  
101
    public double dXforT(double t, int deriv) {
102
        return 0;
103
    }
104

  
105
    public double dYforT(double t, int deriv) {
106
        return 0;
107
    }
108

  
109
    public double nextVertical(double t0, double t1) {
110
        return t1;
111
    }
112

  
113
    public int crossingsFor(double x, double y) {
114
        return 0;
115
    }
116

  
117
    public boolean accumulateCrossings(Crossings c) {
118
        return (x > c.getXLo() &&
119
                x < c.getXHi() &&
120
                y > c.getYLo() &&
121
                y < c.getYHi());
122
    }
123

  
124
    public void enlarge(Rectangle2D r) {
125
        r.add(x, y);
126
    }
127

  
128
    public Curve getSubCurve(double ystart, double yend, int dir) {
129
        return this;
130
    }
131

  
132
    public Curve getReversedCurve() {
133
        return this;
134
    }
135

  
136
    public int getSegment(double coords[]) {
137
        coords[0] = x;
138
        coords[1] = y;
139
        return PathIterator.SEG_MOVETO;
140
    }
141
}
0 142

  
tags/v1_11_0_Build_1306/libraries/libGeoUtils/src/org/gvsig/geoutils/sun/awt/geom/Order1.java
1
/*
2
 * Copyright 1998-2006 Sun Microsystems, Inc.  All Rights Reserved.
3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
 *
5
 * This code is free software; you can redistribute it and/or modify it
6
 * under the terms of the GNU General Public License version 2 only, as
7
 * published by the Free Software Foundation.  Sun designates this
8
 * particular file as subject to the "Classpath" exception as provided
9
 * by Sun in the LICENSE file that accompanied this code.
10
 *
11
 * This code is distributed in the hope that it will be useful, but WITHOUT
12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14
 * version 2 for more details (a copy is included in the LICENSE file that
15
 * accompanied this code).
16
 *
17
 * You should have received a copy of the GNU General Public License version
18
 * 2 along with this work; if not, write to the Free Software Foundation,
19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20
 *
21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22
 * CA 95054 USA or visit www.sun.com if you need additional information or
23
 * have any questions.
24
 */
25

  
26
package org.gvsig.geoutils.sun.awt.geom;
27

  
28
import java.awt.geom.PathIterator;
29
import java.awt.geom.Rectangle2D;
30

  
31
final class Order1 extends Curve {
32
    private double x0;
33
    private double y0;
34
    private double x1;
35
    private double y1;
36
    private double xmin;
37
    private double xmax;
38

  
39
    public Order1(double x0, double y0,
40
                  double x1, double y1,
41
                  int direction)
42
    {
43
        super(direction);
44
        this.x0 = x0;
45
        this.y0 = y0;
46
        this.x1 = x1;
47
        this.y1 = y1;
48
        if (x0 < x1) {
49
            this.xmin = x0;
50
            this.xmax = x1;
51
        } else {
52
            this.xmin = x1;
53
            this.xmax = x0;
54
        }
55
    }
56

  
57
    public int getOrder() {
58
        return 1;
59
    }
60

  
61
    public double getXTop() {
62
        return x0;
63
    }
64

  
65
    public double getYTop() {
66
        return y0;
67
    }
68

  
69
    public double getXBot() {
70
        return x1;
71
    }
72

  
73
    public double getYBot() {
74
        return y1;
75
    }
76

  
77
    public double getXMin() {
78
        return xmin;
79
    }
80

  
81
    public double getXMax() {
82
        return xmax;
83
    }
84

  
85
    public double getX0() {
86
        return (direction == INCREASING) ? x0 : x1;
87
    }
88

  
89
    public double getY0() {
90
        return (direction == INCREASING) ? y0 : y1;
91
    }
92

  
93
    public double getX1() {
94
        return (direction == DECREASING) ? x0 : x1;
95
    }
96

  
97
    public double getY1() {
98
        return (direction == DECREASING) ? y0 : y1;
99
    }
100

  
101
    public double XforY(double y) {
102
        if (x0 == x1 || y <= y0) {
103
            return x0;
104
        }
105
        if (y >= y1) {
106
            return x1;
107
        }
108
        // assert(y0 != y1); /* No horizontal lines... */
109
        return (x0 + (y - y0) * (x1 - x0) / (y1 - y0));
110
    }
111

  
112
    public double TforY(double y) {
113
        if (y <= y0) {
114
            return 0;
115
        }
116
        if (y >= y1) {
117
            return 1;
118
        }
119
        return (y - y0) / (y1 - y0);
120
    }
121

  
122
    public double XforT(double t) {
123
        return x0 + t * (x1 - x0);
124
    }
125

  
126
    public double YforT(double t) {
127
        return y0 + t * (y1 - y0);
128
    }
129

  
130
    public double dXforT(double t, int deriv) {
131
        switch (deriv) {
132
        case 0:
133
            return x0 + t * (x1 - x0);
134
        case 1:
135
            return (x1 - x0);
136
        default:
137
            return 0;
138
        }
139
    }
140

  
141
    public double dYforT(double t, int deriv) {
142
        switch (deriv) {
143
        case 0:
144
            return y0 + t * (y1 - y0);
145
        case 1:
146
            return (y1 - y0);
147
        default:
148
            return 0;
149
        }
150
    }
151

  
152
    public double nextVertical(double t0, double t1) {
153
        return t1;
154
    }
155

  
156
    public boolean accumulateCrossings(Crossings c) {
157
        double xlo = c.getXLo();
158
        double ylo = c.getYLo();
159
        double xhi = c.getXHi();
160
        double yhi = c.getYHi();
161
        if (xmin >= xhi) {
162
            return false;
163
        }
164
        double xstart, ystart, xend, yend;
165
        if (y0 < ylo) {
166
            if (y1 <= ylo) {
167
                return false;
168
            }
169
            ystart = ylo;
170
            xstart = XforY(ylo);
171
        } else {
172
            if (y0 >= yhi) {
173
                return false;
174
            }
175
            ystart = y0;
176
            xstart = x0;
177
        }
178
        if (y1 > yhi) {
179
            yend = yhi;
180
            xend = XforY(yhi);
181
        } else {
182
            yend = y1;
183
            xend = x1;
184
        }
185
        if (xstart >= xhi && xend >= xhi) {
186
            return false;
187
        }
188
        if (xstart > xlo || xend > xlo) {
189
            return true;
190
        }
191
        c.record(ystart, yend, direction);
192
        return false;
193
    }
194

  
195
    public void enlarge(Rectangle2D r) {
196
        r.add(x0, y0);
197
        r.add(x1, y1);
198
    }
199

  
200
    public Curve getSubCurve(double ystart, double yend, int dir) {
201
        if (ystart == y0 && yend == y1) {
202
            return getWithDirection(dir);
203
        }
204
        if (x0 == x1) {
205
            return new Order1(x0, ystart, x1, yend, dir);
206
        }
207
        double num = x0 - x1;
208
        double denom = y0 - y1;
209
        double xstart = (x0 + (ystart - y0) * num / denom);
210
        double xend = (x0 + (yend - y0) * num / denom);
211
        return new Order1(xstart, ystart, xend, yend, dir);
212
    }
213

  
214
    public Curve getReversedCurve() {
215
        return new Order1(x0, y0, x1, y1, -direction);
216
    }
217

  
218
    public int compareTo(Curve other, double yrange[]) {
219
        if (!(other instanceof Order1)) {
220
            return super.compareTo(other, yrange);
221
        }
222
        Order1 c1 = (Order1) other;
223
        if (yrange[1] <= yrange[0]) {
224
            throw new InternalError("yrange already screwed up...");
225
        }
226
        yrange[1] = Math.min(Math.min(yrange[1], y1), c1.y1);
227
        if (yrange[1] <= yrange[0]) {
228
            throw new InternalError("backstepping from "+yrange[0]+" to "+yrange[1]);
229
        }
230
        if (xmax <= c1.xmin) {
231
            return (xmin == c1.xmax) ? 0 : -1;
232
        }
233
        if (xmin >= c1.xmax) {
234
            return 1;
235
        }
236
        /*
237
         * If "this" is curve A and "other" is curve B, then...
238
         * xA(y) = x0A + (y - y0A) (x1A - x0A) / (y1A - y0A)
239
         * xB(y) = x0B + (y - y0B) (x1B - x0B) / (y1B - y0B)
240
         * xA(y) == xB(y)
241
         * x0A + (y - y0A) (x1A - x0A) / (y1A - y0A)
242
         *    == x0B + (y - y0B) (x1B - x0B) / (y1B - y0B)
243
         * 0 == x0A (y1A - y0A) (y1B - y0B) + (y - y0A) (x1A - x0A) (y1B - y0B)
244
         *    - x0B (y1A - y0A) (y1B - y0B) - (y - y0B) (x1B - x0B) (y1A - y0A)
245
         * 0 == (x0A - x0B) (y1A - y0A) (y1B - y0B)
246
         *    + (y - y0A) (x1A - x0A) (y1B - y0B)
247
         *    - (y - y0B) (x1B - x0B) (y1A - y0A)
248
         * If (dxA == x1A - x0A), etc...
249
         * 0 == (x0A - x0B) * dyA * dyB
250
         *    + (y - y0A) * dxA * dyB
251
         *    - (y - y0B) * dxB * dyA
252
         * 0 == (x0A - x0B) * dyA * dyB
253
         *    + y * dxA * dyB - y0A * dxA * dyB
254
         *    - y * dxB * dyA + y0B * dxB * dyA
255
         * 0 == (x0A - x0B) * dyA * dyB
256
         *    + y * dxA * dyB - y * dxB * dyA
257
         *    - y0A * dxA * dyB + y0B * dxB * dyA
258
         * 0 == (x0A - x0B) * dyA * dyB
259
         *    + y * (dxA * dyB - dxB * dyA)
260
         *    - y0A * dxA * dyB + y0B * dxB * dyA
261
         * y == ((x0A - x0B) * dyA * dyB
262
         *       - y0A * dxA * dyB + y0B * dxB * dyA)
263
         *    / (-(dxA * dyB - dxB * dyA))
264
         * y == ((x0A - x0B) * dyA * dyB
265
         *       - y0A * dxA * dyB + y0B * dxB * dyA)
266
         *    / (dxB * dyA - dxA * dyB)
267
         */
268
        double dxa = x1 - x0;
269
        double dya = y1 - y0;
270
        double dxb = c1.x1 - c1.x0;
271
        double dyb = c1.y1 - c1.y0;
272
        double denom = dxb * dya - dxa * dyb;
273
        double y;
274
        if (denom != 0) {
275
            double num = ((x0 - c1.x0) * dya * dyb
276
                          - y0 * dxa * dyb
277
                          + c1.y0 * dxb * dya);
278
            y = num / denom;
279
            if (y <= yrange[0]) {
280
                // intersection is above us
281
                // Use bottom-most common y for comparison
282
                y = Math.min(y1, c1.y1);
283
            } else {
284
                // intersection is below the top of our range
285
                if (y < yrange[1]) {
286
                    // If intersection is in our range, adjust valid range
287
                    yrange[1] = y;
288
                }
289
                // Use top-most common y for comparison
290
                y = Math.max(y0, c1.y0);
291
            }
292
        } else {
293
            // lines are parallel, choose any common y for comparison
294
            // Note - prefer an endpoint for speed of calculating the X
295
            // (see shortcuts in Order1.XforY())
296
            y = Math.max(y0, c1.y0);
297
        }
298
        return orderof(XforY(y), c1.XforY(y));
299
    }
300

  
301
    public int getSegment(double coords[]) {
302
        if (direction == INCREASING) {
303
            coords[0] = x1;
304
            coords[1] = y1;
305
        } else {
306
            coords[0] = x0;
307
            coords[1] = y0;
308
        }
309
        return PathIterator.SEG_LINETO;
310
    }
311
}
0 312

  
tags/v1_11_0_Build_1306/libraries/libGeoUtils/src/org/gvsig/geoutils/sun/awt/geom/Order2.java
1
/*
2
 * Copyright 1998-2006 Sun Microsystems, Inc.  All Rights Reserved.
3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
 *
5
 * This code is free software; you can redistribute it and/or modify it
6
 * under the terms of the GNU General Public License version 2 only, as
7
 * published by the Free Software Foundation.  Sun designates this
8
 * particular file as subject to the "Classpath" exception as provided
9
 * by Sun in the LICENSE file that accompanied this code.
10
 *
11
 * This code is distributed in the hope that it will be useful, but WITHOUT
12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14
 * version 2 for more details (a copy is included in the LICENSE file that
15
 * accompanied this code).
16
 *
17
 * You should have received a copy of the GNU General Public License version
18
 * 2 along with this work; if not, write to the Free Software Foundation,
19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20
 *
21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22
 * CA 95054 USA or visit www.sun.com if you need additional information or
23
 * have any questions.
24
 */
25

  
26
package org.gvsig.geoutils.sun.awt.geom;
27

  
28
import java.awt.geom.PathIterator;
29
import java.awt.geom.Rectangle2D;
30
import java.util.Vector;
31

  
32
final class Order2 extends Curve {
33
    private double x0;
34
    private double y0;
35
    private double cx0;
36
    private double cy0;
37
    private double x1;
38
    private double y1;
39
    private double xmin;
40
    private double xmax;
41

  
42
    private double xcoeff0;
43
    private double xcoeff1;
44
    private double xcoeff2;
45
    private double ycoeff0;
46
    private double ycoeff1;
47
    private double ycoeff2;
48

  
49
    public static void insert(Vector curves, double tmp[],
50
                              double x0, double y0,
51
                              double cx0, double cy0,
52
                              double x1, double y1,
53
                              int direction)
54
    {
55
        int numparams = getHorizontalParams(y0, cy0, y1, tmp);
56
        if (numparams == 0) {
57
            // We are using addInstance here to avoid inserting horisontal
58
            // segments
59
            addInstance(curves, x0, y0, cx0, cy0, x1, y1, direction);
60
            return;
61
        }
62
        // assert(numparams == 1);
63
        double t = tmp[0];
64
        tmp[0] = x0;  tmp[1] = y0;
65
        tmp[2] = cx0; tmp[3] = cy0;
66
        tmp[4] = x1;  tmp[5] = y1;
67
        split(tmp, 0, t);
68
        int i0 = (direction == INCREASING)? 0 : 4;
69
        int i1 = 4 - i0;
70
        addInstance(curves, tmp[i0], tmp[i0 + 1], tmp[i0 + 2], tmp[i0 + 3],
71
                    tmp[i0 + 4], tmp[i0 + 5], direction);
72
        addInstance(curves, tmp[i1], tmp[i1 + 1], tmp[i1 + 2], tmp[i1 + 3],
73
                    tmp[i1 + 4], tmp[i1 + 5], direction);
74
    }
75

  
76
    public static void addInstance(Vector curves,
77
                                   double x0, double y0,
78
                                   double cx0, double cy0,
79
                                   double x1, double y1,
80
                                   int direction) {
81
        if (y0 > y1) {
82
            curves.add(new Order2(x1, y1, cx0, cy0, x0, y0, -direction));
83
        } else if (y1 > y0) {
84
            curves.add(new Order2(x0, y0, cx0, cy0, x1, y1, direction));
85
        }
86
    }
87

  
88
    /*
89
     * Return the count of the number of horizontal sections of the
90
     * specified quadratic Bezier curve.  Put the parameters for the
91
     * horizontal sections into the specified <code>ret</code> array.
92
     * <p>
93
     * If we examine the parametric equation in t, we have:
94
     *     Py(t) = C0*(1-t)^2 + 2*CP*t*(1-t) + C1*t^2
95
     *           = C0 - 2*C0*t + C0*t^2 + 2*CP*t - 2*CP*t^2 + C1*t^2
96
     *           = C0 + (2*CP - 2*C0)*t + (C0 - 2*CP + C1)*t^2
97
     *     Py(t) = (C0 - 2*CP + C1)*t^2 + (2*CP - 2*C0)*t + (C0)
98
     * If we take the derivative, we get:
99
     *     Py(t) = At^2 + Bt + C
100
     *     dPy(t) = 2At + B = 0
101
     *     2*(C0 - 2*CP + C1)t + 2*(CP - C0) = 0
102
     *     2*(C0 - 2*CP + C1)t = 2*(C0 - CP)
103
     *     t = 2*(C0 - CP) / 2*(C0 - 2*CP + C1)
104
     *     t = (C0 - CP) / (C0 - CP + C1 - CP)
105
     * Note that this method will return 0 if the equation is a line,
106
     * which is either always horizontal or never horizontal.
107
     * Completely horizontal curves need to be eliminated by other
108
     * means outside of this method.
109
     */
110
    public static int getHorizontalParams(double c0, double cp, double c1,
111
                                          double ret[]) {
112
        if (c0 <= cp && cp <= c1) {
113
            return 0;
114
        }
115
        c0 -= cp;
116
        c1 -= cp;
117
        double denom = c0 + c1;
118
        // If denom == 0 then cp == (c0+c1)/2 and we have a line.
119
        if (denom == 0) {
120
            return 0;
121
        }
122
        double t = c0 / denom;
123
        // No splits at t==0 and t==1
124
        if (t <= 0 || t >= 1) {
125
            return 0;
126
        }
127
        ret[0] = t;
128
        return 1;
129
    }
130

  
131
    /*
132
     * Split the quadratic Bezier stored at coords[pos...pos+5] representing
133
     * the paramtric range [0..1] into two subcurves representing the
134
     * parametric subranges [0..t] and [t..1].  Store the results back
135
     * into the array at coords[pos...pos+5] and coords[pos+4...pos+9].
136
     */
137
    public static void split(double coords[], int pos, double t) {
138
        double x0, y0, cx, cy, x1, y1;
139
        coords[pos+8] = x1 = coords[pos+4];
140
        coords[pos+9] = y1 = coords[pos+5];
141
        cx = coords[pos+2];
142
        cy = coords[pos+3];
143
        x1 = cx + (x1 - cx) * t;
144
        y1 = cy + (y1 - cy) * t;
145
        x0 = coords[pos+0];
146
        y0 = coords[pos+1];
147
        x0 = x0 + (cx - x0) * t;
148
        y0 = y0 + (cy - y0) * t;
149
        cx = x0 + (x1 - x0) * t;
150
        cy = y0 + (y1 - y0) * t;
151
        coords[pos+2] = x0;
152
        coords[pos+3] = y0;
153
        coords[pos+4] = cx;
154
        coords[pos+5] = cy;
155
        coords[pos+6] = x1;
156
        coords[pos+7] = y1;
157
    }
158

  
159
    public Order2(double x0, double y0,
160
                  double cx0, double cy0,
161
                  double x1, double y1,
162
                  int direction)
163
    {
164
        super(direction);
165
        // REMIND: Better accuracy in the root finding methods would
166
        //  ensure that cy0 is in range.  As it stands, it is never
167
        //  more than "1 mantissa bit" out of range...
168
        if (cy0 < y0) {
169
            cy0 = y0;
170
        } else if (cy0 > y1) {
171
            cy0 = y1;
172
        }
173
        this.x0 = x0;
174
        this.y0 = y0;
175
        this.cx0 = cx0;
176
        this.cy0 = cy0;
177
        this.x1 = x1;
178
        this.y1 = y1;
179
        xmin = Math.min(Math.min(x0, x1), cx0);
180
        xmax = Math.max(Math.max(x0, x1), cx0);
181
        xcoeff0 = x0;
182
        xcoeff1 = cx0 + cx0 - x0 - x0;
183
        xcoeff2 = x0 - cx0 - cx0 + x1;
184
        ycoeff0 = y0;
185
        ycoeff1 = cy0 + cy0 - y0 - y0;
186
        ycoeff2 = y0 - cy0 - cy0 + y1;
187
    }
188

  
189
    public int getOrder() {
190
        return 2;
191
    }
192

  
193
    public double getXTop() {
194
        return x0;
195
    }
196

  
197
    public double getYTop() {
198
        return y0;
199
    }
200

  
201
    public double getXBot() {
202
        return x1;
203
    }
204

  
205
    public double getYBot() {
206
        return y1;
207
    }
208

  
209
    public double getXMin() {
210
        return xmin;
211
    }
212

  
213
    public double getXMax() {
214
        return xmax;
215
    }
216

  
217
    public double getX0() {
218
        return (direction == INCREASING) ? x0 : x1;
219
    }
220

  
221
    public double getY0() {
222
        return (direction == INCREASING) ? y0 : y1;
223
    }
224

  
225
    public double getCX0() {
226
        return cx0;
227
    }
228

  
229
    public double getCY0() {
230
        return cy0;
231
    }
232

  
233
    public double getX1() {
234
        return (direction == DECREASING) ? x0 : x1;
235
    }
236

  
237
    public double getY1() {
238
        return (direction == DECREASING) ? y0 : y1;
239
    }
240

  
241
    public double XforY(double y) {
242
        if (y <= y0) {
243
            return x0;
244
        }
245
        if (y >= y1) {
246
            return x1;
247
        }
248
        return XforT(TforY(y));
249
    }
250

  
251
    public double TforY(double y) {
252
        if (y <= y0) {
253
            return 0;
254
        }
255
        if (y >= y1) {
256
            return 1;
257
        }
258
        return TforY(y, ycoeff0, ycoeff1, ycoeff2);
259
    }
260

  
261
    public static double TforY(double y,
262
                               double ycoeff0, double ycoeff1, double ycoeff2)
263
    {
264
        // The caller should have already eliminated y values
265
        // outside of the y0 to y1 range.
266
        ycoeff0 -= y;
267
        if (ycoeff2 == 0.0) {
268
            // The quadratic parabola has degenerated to a line.
269
            // ycoeff1 should not be 0.0 since we have already eliminated
270
            // totally horizontal lines, but if it is, then we will generate
271
            // infinity here for the root, which will not be in the [0,1]
272
            // range so we will pass to the failure code below.
273
            double root = -ycoeff0 / ycoeff1;
274
            if (root >= 0 && root <= 1) {
275
                return root;
276
            }
277
        } else {
278
            // From Numerical Recipes, 5.6, Quadratic and Cubic Equations
279
            double d = ycoeff1 * ycoeff1 - 4.0 * ycoeff2 * ycoeff0;
280
            // If d < 0.0, then there are no roots
281
            if (d >= 0.0) {
282
                d = Math.sqrt(d);
283
                // For accuracy, calculate one root using:
284
                //     (-ycoeff1 +/- d) / 2ycoeff2
285
                // and the other using:
286
                //     2ycoeff0 / (-ycoeff1 +/- d)
287
                // Choose the sign of the +/- so that ycoeff1+d
288
                // gets larger in magnitude
289
                if (ycoeff1 < 0.0) {
290
                    d = -d;
291
                }
292
                double q = (ycoeff1 + d) / -2.0;
293
                // We already tested ycoeff2 for being 0 above
294
                double root = q / ycoeff2;
295
                if (root >= 0 && root <= 1) {
296
                    return root;
297
                }
298
                if (q != 0.0) {
299
                    root = ycoeff0 / q;
300
                    if (root >= 0 && root <= 1) {
301
                        return root;
302
                    }
303
                }
304
            }
305
        }
306
        /* We failed to find a root in [0,1].  What could have gone wrong?
307
         * First, remember that these curves are constructed to be monotonic
308
         * in Y and totally horizontal curves have already been eliminated.
309
         * Now keep in mind that the Y coefficients of the polynomial form
310
         * of the curve are calculated from the Y coordinates which define
311
         * our curve.  They should theoretically define the same curve,
312
         * but they can be off by a couple of bits of precision after the
313
         * math is done and so can represent a slightly modified curve.
314
         * This is normally not an issue except when we have solutions near
315
         * the endpoints.  Since the answers we get from solving the polynomial
316
         * may be off by a few bits that means that they could lie just a
317
         * few bits of precision outside the [0,1] range.
318
         *
319
         * Another problem could be that while the parametric curve defined
320
         * by the Y coordinates has a local minima or maxima at or just
321
         * outside of the endpoints, the polynomial form might express
322
         * that same min/max just inside of and just shy of the Y coordinate
323
         * of that endpoint.  In that case, if we solve for a Y coordinate
324
         * at or near that endpoint, we may be solving for a Y coordinate
325
         * that is below that minima or above that maxima and we would find
326
         * no solutions at all.
327
         *
328
         * In either case, we can assume that y is so near one of the
329
         * endpoints that we can just collapse it onto the nearest endpoint
330
         * without losing more than a couple of bits of precision.
331
         */
332
        // First calculate the midpoint between y0 and y1 and choose to
333
        // return either 0.0 or 1.0 depending on whether y is above
334
        // or below the midpoint...
335
        // Note that we subtracted y from ycoeff0 above so both y0 and y1
336
        // will be "relative to y" so we are really just looking at where
337
        // zero falls with respect to the "relative midpoint" here.
338
        double y0 = ycoeff0;
339
        double y1 = ycoeff0 + ycoeff1 + ycoeff2;
340
        return (0 < (y0 + y1) / 2) ? 0.0 : 1.0;
341
    }
342

  
343
    public double XforT(double t) {
344
        return (xcoeff2 * t + xcoeff1) * t + xcoeff0;
345
    }
346

  
347
    public double YforT(double t) {
348
        return (ycoeff2 * t + ycoeff1) * t + ycoeff0;
349
    }
350

  
351
    public double dXforT(double t, int deriv) {
352
        switch (deriv) {
353
        case 0:
354
            return (xcoeff2 * t + xcoeff1) * t + xcoeff0;
355
        case 1:
356
            return 2 * xcoeff2 * t + xcoeff1;
357
        case 2:
358
            return 2 * xcoeff2;
359
        default:
360
            return 0;
361
        }
362
    }
363

  
364
    public double dYforT(double t, int deriv) {
365
        switch (deriv) {
366
        case 0:
367
            return (ycoeff2 * t + ycoeff1) * t + ycoeff0;
368
        case 1:
369
            return 2 * ycoeff2 * t + ycoeff1;
370
        case 2:
371
            return 2 * ycoeff2;
372
        default:
373
            return 0;
374
        }
375
    }
376

  
377
    public double nextVertical(double t0, double t1) {
378
        double t = -xcoeff1 / (2 * xcoeff2);
379
        if (t > t0 && t < t1) {
380
            return t;
381
        }
382
        return t1;
383
    }
384

  
385
    public void enlarge(Rectangle2D r) {
386
        r.add(x0, y0);
387
        double t = -xcoeff1 / (2 * xcoeff2);
388
        if (t > 0 && t < 1) {
389
            r.add(XforT(t), YforT(t));
390
        }
391
        r.add(x1, y1);
392
    }
393

  
394
    public Curve getSubCurve(double ystart, double yend, int dir) {
395
        double t0, t1;
396
        if (ystart <= y0) {
397
            if (yend >= y1) {
398
                return getWithDirection(dir);
399
            }
400
            t0 = 0;
401
        } else {
402
            t0 = TforY(ystart, ycoeff0, ycoeff1, ycoeff2);
403
        }
404
        if (yend >= y1) {
405
            t1 = 1;
406
        } else {
407
            t1 = TforY(yend, ycoeff0, ycoeff1, ycoeff2);
408
        }
409
        double eqn[] = new double[10];
410
        eqn[0] = x0;
411
        eqn[1] = y0;
412
        eqn[2] = cx0;
413
        eqn[3] = cy0;
414
        eqn[4] = x1;
415
        eqn[5] = y1;
416
        if (t1 < 1) {
417
            split(eqn, 0, t1);
418
        }
419
        int i;
420
        if (t0 <= 0) {
421
            i = 0;
422
        } else {
423
            split(eqn, 0, t0 / t1);
424
            i = 4;
425
        }
426
        return new Order2(eqn[i+0], ystart,
427
                          eqn[i+2], eqn[i+3],
428
                          eqn[i+4], yend,
429
                          dir);
430
    }
431

  
432
    public Curve getReversedCurve() {
433
        return new Order2(x0, y0, cx0, cy0, x1, y1, -direction);
434
    }
435

  
436
    public int getSegment(double coords[]) {
437
        coords[0] = cx0;
438
        coords[1] = cy0;
439
        if (direction == INCREASING) {
440
            coords[2] = x1;
441
            coords[3] = y1;
442
        } else {
443
            coords[2] = x0;
444
            coords[3] = y0;
445
        }
446
        return PathIterator.SEG_QUADTO;
447
    }
448

  
449
    public String controlPointString() {
450
        return ("("+round(cx0)+", "+round(cy0)+"), ");
451
    }
452
}
0 453

  
tags/v1_11_0_Build_1306/libraries/libGeoUtils/src/org/gvsig/geoutils/sun/awt/geom/Order3.java
1
/*
2
 * Copyright 1998-2006 Sun Microsystems, Inc.  All Rights Reserved.
3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
 *
5
 * This code is free software; you can redistribute it and/or modify it
6
 * under the terms of the GNU General Public License version 2 only, as
7
 * published by the Free Software Foundation.  Sun designates this
8
 * particular file as subject to the "Classpath" exception as provided
9
 * by Sun in the LICENSE file that accompanied this code.
10
 *
11
 * This code is distributed in the hope that it will be useful, but WITHOUT
12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14
 * version 2 for more details (a copy is included in the LICENSE file that
15
 * accompanied this code).
16
 *
17
 * You should have received a copy of the GNU General Public License version
18
 * 2 along with this work; if not, write to the Free Software Foundation,
19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20
 *
21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22
 * CA 95054 USA or visit www.sun.com if you need additional information or
23
 * have any questions.
24
 */
25

  
26
package org.gvsig.geoutils.sun.awt.geom;
27

  
28
import java.awt.geom.PathIterator;
29
import java.awt.geom.QuadCurve2D;
30
import java.awt.geom.Rectangle2D;
31
import java.util.Vector;
32

  
33
final class Order3 extends Curve {
34
    private double x0;
35
    private double y0;
36
    private double cx0;
37
    private double cy0;
38
    private double cx1;
39
    private double cy1;
40
    private double x1;
41
    private double y1;
42

  
43
    private double xmin;
44
    private double xmax;
45

  
46
    private double xcoeff0;
47
    private double xcoeff1;
48
    private double xcoeff2;
49
    private double xcoeff3;
50

  
51
    private double ycoeff0;
52
    private double ycoeff1;
53
    private double ycoeff2;
54
    private double ycoeff3;
55

  
56
    public static void insert(Vector curves, double tmp[],
57
                              double x0, double y0,
58
                              double cx0, double cy0,
59
                              double cx1, double cy1,
60
                              double x1, double y1,
61
                              int direction)
62
    {
63
        int numparams = getHorizontalParams(y0, cy0, cy1, y1, tmp);
64
        if (numparams == 0) {
65
            // We are using addInstance here to avoid inserting horisontal
66
            // segments
67
            addInstance(curves, x0, y0, cx0, cy0, cx1, cy1, x1, y1, direction);
68
            return;
69
        }
70
        // Store coordinates for splitting at tmp[3..10]
71
        tmp[3] = x0;  tmp[4]  = y0;
72
        tmp[5] = cx0; tmp[6]  = cy0;
73
        tmp[7] = cx1; tmp[8]  = cy1;
74
        tmp[9] = x1;  tmp[10] = y1;
75
        double t = tmp[0];
76
        if (numparams > 1 && t > tmp[1]) {
77
            // Perform a "2 element sort"...
78
            tmp[0] = tmp[1];
79
            tmp[1] = t;
80
            t = tmp[0];
81
        }
82
        split(tmp, 3, t);
83
        if (numparams > 1) {
84
            // Recalculate tmp[1] relative to the range [tmp[0]...1]
85
            t = (tmp[1] - t) / (1 - t);
86
            split(tmp, 9, t);
87
        }
88
        int index = 3;
89
        if (direction == DECREASING) {
90
            index += numparams * 6;
91
        }
92
        while (numparams >= 0) {
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff