Revision 33

View differences:

org.gvsig.jdk/tags/org.gvsig.jdk-1.0.1/pom.xml
1
<?xml version="1.0" encoding="ISO-8859-1"?>
2
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3
	<modelVersion>4.0.0</modelVersion>
4
	<groupId>org.gvsig</groupId>
5
	<artifactId>org.gvsig.jdk</artifactId>
6
	<packaging>pom</packaging>
7
	<version>1.0.1</version>
8
	<name>org.gvsig.jdk</name>
9
	<description>This library contains some private classes of the OpenJDK</description>
10
	
11
	<url>https://devel.gvsig.org/redmine/projects/gvsig-external-jdk</url>
12

  
13
    <licenses>
14
        <license>
15
            <name>GPLv3</name>
16
            <url>http://www.gnu.org/licenses/gpl.html</url>
17
            <distribution>repo</distribution>
18
            <comments>
19
                "GPL" stands for "General Public License". The most widespread such
20
                license is the GNU General Public License, or GNU GPL for short.
21
                This can be further shortened to "GPL", when it is understood that
22
                the GNU GPL is the one intended.
23
            </comments>
24
        </license>
25
    </licenses>
26

  
27
    <organization>
28
        <name>gvSIG Association</name>
29
        <url>http://www.gvsig.com/</url>
30
    </organization>
31
	
32
    <scm>
33
        <connection>scm:svn:https://devel.gvsig.org/svn/gvsig-external-jdk/org.gvsig.jdk/tags/org.gvsig.jdk-1.0.1</connection>
34
        <developerConnection>scm:svn:https://devel.gvsig.org/svn/gvsig-external-jdk/org.gvsig.jdk/tags/org.gvsig.jdk-1.0.1</developerConnection>
35
        <url>scm:svn:https://devel.gvsig.org/svn/gvsig-external-jdk/org.gvsig.jdk/tags/org.gvsig.jdk-1.0.1</url>
36
    </scm>
37
   	<developers>
38
		<developer>
39
			<id>jjdelcerro</id>
40
			<name>Joaquin Jose del Cerro Murciano</name>
41
			<email>jjdelcerro@gvsig.com</email>
42
			<roles>
43
				<role>Architect</role>
44
				<role>Developer</role>
45
			</roles>
46
		</developer>
47
	</developers>
48
    <repositories>
49
        <repository>
50
            <id>gvsig-public-http-repository</id>
51
            <name>gvSIG maven public HTTP repository</name>
52
            <url>http://devel.gvsig.org/m2repo/j2se</url>
53
            <releases>
54
                <enabled>true</enabled>
55
                <updatePolicy>daily</updatePolicy>
56
                <checksumPolicy>warn</checksumPolicy>
57
            </releases>
58
            <snapshots>
59
                <enabled>true</enabled>
60
                <updatePolicy>daily</updatePolicy>
61
                <checksumPolicy>warn</checksumPolicy>
62
            </snapshots>
63
        </repository>
64
    </repositories>
65

  
66
    <distributionManagement>
67
        <site>
68
            <id>gvsig-repository</id>
69
            <url>dav:https://devel.gvsig.org/sites/${project.artifactId}/${project.version}</url>
70
        </site>
71
        <repository>
72
            <id>gvsig-repository</id>
73
            <name>gvSIG maven repository</name>
74
            <url>dav:https://devel.gvsig.org/m2repo/j2se</url>
75
            <uniqueVersion>false</uniqueVersion>
76
        </repository>
77
        <snapshotRepository>
78
            <id>gvsig-repository</id>
79
            <name>gvSIG maven repository</name>
80
            <url>dav:https://devel.gvsig.org/m2repo/j2se</url>
81
            <uniqueVersion>false</uniqueVersion>
82
        </snapshotRepository>
83
    </distributionManagement>
84

  
85
	<dependencyManagement>
86
		<dependencies>
87
			<dependency>
88
				<groupId>org.gvsig</groupId>
89
				<artifactId>org.gvsig.tools.lib</artifactId>
90
				<version>3.0.53</version>
91
			</dependency>
92
		</dependencies>
93
	</dependencyManagement>
94
	<build>
95
        <extensions>
96
            <extension>
97
                <groupId>org.apache.maven.wagon</groupId>
98
                <artifactId>wagon-webdav-jackrabbit</artifactId>
99
                <version>2.4</version>
100
            </extension>
101
        </extensions>
102
		<plugins>
103
		    <plugin>
104
		      <artifactId>maven-release-plugin</artifactId>
105
		      <version>2.0</version>
106
		      <configuration>
107
		        <tagBase>https://devel.gvsig.org/svn/gvsig-external-jdk/org.gvsig.jdk/tags</tagBase>
108
		      </configuration>
109
			</plugin>
110
		</plugins>
111
	</build>
112
	<modules>
113
<!--
114
		<module>org.gvsig.jdk.v1_4</module>
115
-->
116
		<module>org.gvsig.jdk.v1_6</module>
117
	</modules>
118
	<reporting>
119
		<plugins>
120
			<plugin>
121
				<groupId>org.apache.maven.plugins</groupId>
122
				<artifactId>maven-javadoc-plugin</artifactId>
123
				<configuration>
124
					<links>
125
						<link>http://java.sun.com/j2se/1.5.0/docs/api/</link>
126
						<link>http://www.slf4j.org/api/</link>
127
					</links>
128
				</configuration>
129
			</plugin>
130
		</plugins>
131
	</reporting>
132
</project>
org.gvsig.jdk/tags/org.gvsig.jdk-1.0.1/.project
1
<?xml version="1.0" encoding="UTF-8"?>
2
<projectDescription>
3
	<name>org.gvsig.jdk</name>
4
	<comment></comment>
5
	<projects>
6
	</projects>
7
	<buildSpec>
8
	</buildSpec>
9
	<natures>
10
	</natures>
11
</projectDescription>
org.gvsig.jdk/tags/org.gvsig.jdk-1.0.1/org.gvsig.jdk.v1_4/src/main/java/org/gvsig/jdk/GeomUtilities.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 * 
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 * 
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 * 
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
 * MA  02110-1301, USA.
20
 * 
21
 */
22

  
23
/*
24
 * AUTHORS (In addition to CIT):
25
 * 2009 {Iver T.I.}   {Task}
26
 */
27

  
28
package org.gvsig.jdk;
29

  
30
import java.awt.geom.PathIterator;
31

  
32
import sun.awt.geom.Crossings;
33
import sun.awt.geom.Curve;
34

  
35

  
36

  
37
/**
38
 * This class contains some utility methods to access to some 
39
 * private classes of the OpenJDK. These classes have been copied
40
 * to this package and their visibility has been reduced. It is not
41
 * possible to access them without using this class. 
42
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
43
 */
44
public class GeomUtilities {
45

  
46
	/**
47
	 * Tests if the specified rectangular area is inside the boundary of
48
	 * a <code>Shape</code>.
49
	 * @param pi the path iterator of a shape
50
	 * @param x,&nbsp;y the specified coordinates
51
	 * @param w the width of the specified rectangular area
52
	 * @param h the height of the specified rectangular area
53
	 * @return <code>true</code> if this <code>Shape</code> contains
54
	 * the specified rectangluar area; <code>false</code> otherwise.
55
	 */
56
	public static boolean contains(PathIterator pi, double x, double y, double w, double h) {
57
		Crossings c = Crossings.findCrossings(pi,
58
				x, y, x+w, y+h);
59
		return (c != null && c.covers(y, y+h));
60
	}
61
	
62
	/**
63
	 * Tests if the interior of a <code>Shape</code> intersects the
64
	 * interior of a specified set of rectangular coordinates.
65
	 * @param pi the path iterator of a shape
66
	 * @param x,&nbsp;y the specified coordinates
67
	 * @param w the width of the specified rectangular coordinates
68
	 * @param h the height of the specified rectangular coordinates
69
	 * @return <code>true</code> if this <code>Shape</code> and the
70
	 * interior of the specified set of rectangular coordinates intersect
71
	 * each other; <code>false</code> otherwise.
72
	 */
73
	public static boolean intersects(PathIterator pi, double x, double y, double w, double h) {
74
		Crossings c = Crossings.findCrossings(pi,
75
				x, y, x+w, y+h);
76
		return (c == null || !c.isEmpty());
77
	}
78
	
79
	 /**
80
     * Calculates the number of times the given path
81
     * crosses the ray extending to the right from (px,py).
82
     * If the point lies on a part of the path,
83
     * then no crossings are counted for that intersection.
84
     * +1 is added for each crossing where the Y coordinate is increasing
85
     * -1 is added for each crossing where the Y coordinate is decreasing
86
     * The path must start with a SEG_MOVETO, otherwise an exception is
87
     * thrown.
88
     * The caller must check p[xy] for NaN values.
89
     * The caller may also reject infinite p[xy] values as well.
90
     * @param pi the path iterator of a shape
91
     * @param px the x coordinate
92
     * @param py the y coordinate
93
     * @return is the sum of all crossings for every segment in
94
     * the path
95
     */
96
	public static int pointCrossingsForPath(PathIterator pi, double px, double py){
97
		return Curve.crossingsForPath(pi, px, py);
98
	}
99

  
100
}
101

  
org.gvsig.jdk/tags/org.gvsig.jdk-1.0.1/org.gvsig.jdk.v1_4/src/main/java/org/gvsig/jdk/package.html
1
<?xml version="1.0" encoding="UTF-8" ?>
2
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
<html xmlns="http://www.w3.org/1999/xhtml">
4
<head>
5
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
6
<title>${package} package documentation</title>
7
</head>
8
<body>
9

  
10
	<p>TODO: Example library API description.</p>
11
	
12
	<p>See the <a href="http://java.sun.com/j2se/1.4.2/docs/tooldocs/windows/javadoc.html${symbol_pound}packagecomment">Javadoc Tool documentation about the package file</a></p>
13

  
14
</body>
15
</html>
org.gvsig.jdk/tags/org.gvsig.jdk-1.0.1/org.gvsig.jdk.v1_4/src/main/javadoc/overview.html
1
<?xml version="1.0" encoding="UTF-8" ?>
2
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
<html xmlns="http://www.w3.org/1999/xhtml">
4
<head>
5
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
6
<title>${artifactId} package documentation</title>
7
</head>
8
<body>
9

  
10
	<p>TODO: Example library API overview.</p>
11
	
12
	<p>See the <a href="http://java.sun.com/j2se/1.4.2/docs/tooldocs/windows/javadoc.html${symbol_pound}overviewcomment">Javadoc Tool documentation about the overview file</a></p>
13

  
14
</body>
15
</html>
org.gvsig.jdk/tags/org.gvsig.jdk-1.0.1/org.gvsig.jdk.v1_4/pom.xml
1
<?xml version="1.0" encoding="ISO-8859-1"?>
2

  
3
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4
	<modelVersion>4.0.0</modelVersion>
5
	<artifactId>org.gvsig.jdk.v1_4</artifactId>
6
	<packaging>jar</packaging>
7
	<name>org.gvsig.jdk.v1_4</name>
8
	<description>Private classes of the OpenJDK v1.4</description>
9
	<parent>
10
		<groupId>org.gvsig</groupId>
11
		<artifactId>org.gvsig.jdk</artifactId>
12
		<version>1.0.1-SNAPSHOT</version>
13
	</parent>
14
	<dependencies>
15
		<dependency>
16
			<groupId>org.gvsig</groupId>
17
			<artifactId>org.gvsig.tools.lib</artifactId>
18
		</dependency>
19
	</dependencies>
20

  
21
	<profiles>
22
		<profile>
23
			<id>windows-profile</id>
24
			<activation>
25
				<os>
26
                    <family>Windows</family>
27
				</os>
28
			</activation>
29
		    <build>
30
		        <plugins>
31
		            <plugin>
32
		                <groupId>org.apache.maven.plugins</groupId>
33
		                <artifactId>maven-compiler-plugin</artifactId>
34
		                <configuration>
35
		                  <verbose>true</verbose>
36
		                  <fork>true</fork>
37
		                  <executable>C:\j2sdk1.4.2_19\bin\javac</executable>
38
		                  <compilerVersion>1.4</compilerVersion>
39
		                  <source>1.4</source>
40
		                  <target>1.4</target>
41
		                </configuration>
42
		            </plugin>
43
		            <plugin>
44
		                <groupId>org.codehaus.mojo</groupId>
45
		                <artifactId>animal-sniffer-maven-plugin</artifactId>
46
		                <configuration>
47
		                    <skip>true</skip>
48
		                </configuration>
49
		            </plugin>
50
		    
51
		        </plugins>
52
		    </build>
53
		</profile>
54
		<profile>
55
			<id>linux-profile</id>
56
			<activation>
57
				<os>
58
                    <family>Linux</family>
59
				</os>
60
			</activation>
61
            <build>
62
		        <plugins>
63
		            <plugin>
64
		                <groupId>org.apache.maven.plugins</groupId>
65
		                <artifactId>maven-compiler-plugin</artifactId>
66
		                <configuration>
67
		                  <verbose>true</verbose>
68
		                  <fork>true</fork>
69
		                  <executable>/usr/lib/jvm/j2sdk1.4.2_19/bin/javac</executable>
70
		                  <compilerVersion>1.4</compilerVersion>
71
		                  <source>1.4</source>
72
		                  <target>1.4</target>
73
		                </configuration>
74
		            </plugin>
75
		            <plugin>
76
		                <groupId>org.codehaus.mojo</groupId>
77
		                <artifactId>animal-sniffer-maven-plugin</artifactId>
78
		                <configuration>
79
		                    <skip>true</skip>
80
		                </configuration>
81
		            </plugin>
82
		        </plugins>
83
		    </build>
84
		</profile>
85
	</profiles>
86
	
87
</project>
org.gvsig.jdk/tags/org.gvsig.jdk-1.0.1/org.gvsig.jdk.v1_6/src/main/javadoc/overview.html
1
<?xml version="1.0" encoding="UTF-8" ?>
2
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
<html xmlns="http://www.w3.org/1999/xhtml">
4
<head>
5
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
6
<title>${artifactId} package documentation</title>
7
</head>
8
<body>
9

  
10
	<p>TODO: Example library API overview.</p>
11
	
12
	<p>See the <a href="http://java.sun.com/j2se/1.4.2/docs/tooldocs/windows/javadoc.html${symbol_pound}overviewcomment">Javadoc Tool documentation about the overview file</a></p>
13

  
14
</body>
15
</html>
org.gvsig.jdk/tags/org.gvsig.jdk-1.0.1/org.gvsig.jdk.v1_6/src/main/java/org/gvsig/jdk/package.html
1
<?xml version="1.0" encoding="UTF-8" ?>
2
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
<html xmlns="http://www.w3.org/1999/xhtml">
4
<head>
5
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
6
<title>${package} package documentation</title>
7
</head>
8
<body>
9

  
10
	<p>TODO: Example library API description.</p>
11
	
12
	<p>See the <a href="http://java.sun.com/j2se/1.4.2/docs/tooldocs/windows/javadoc.html${symbol_pound}packagecomment">Javadoc Tool documentation about the package file</a></p>
13

  
14
</body>
15
</html>
org.gvsig.jdk/tags/org.gvsig.jdk-1.0.1/org.gvsig.jdk.v1_6/src/main/java/org/gvsig/jdk/GeomUtilities.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 * 
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 * 
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 * 
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
 * MA  02110-1301, USA.
20
 * 
21
 */
22

  
23
/*
24
 * AUTHORS (In addition to CIT):
25
 * 2009 {Iver T.I.}   {Task}
26
 */
27

  
28
package org.gvsig.jdk;
29

  
30
import java.awt.geom.PathIterator;
31

  
32
import org.gvsig.jdk.sun.awt.geom.Crossings;
33
import org.gvsig.jdk.sun.awt.geom.Curve;
34

  
35

  
36
/**
37
 * This class contains some utility methods to access to some 
38
 * private classes of the OpenJDK. These classes have been copied
39
 * to this package and their visibility has been reduced. It is not
40
 * possible to access them without using this class. 
41
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
42
 */
43
public class GeomUtilities {
44

  
45
	/**
46
	 * Tests if the specified rectangular area is inside the boundary of
47
	 * a <code>Shape</code>.
48
	 * @param pi the path iterator of a shape
49
	 * @param x,&nbsp;y the specified coordinates
50
	 * @param w the width of the specified rectangular area
51
	 * @param h the height of the specified rectangular area
52
	 * @return <code>true</code> if this <code>Shape</code> contains
53
	 * the specified rectangluar area; <code>false</code> otherwise.
54
	 */
55
	public static boolean contains(PathIterator pi, double x, double y, double w, double h) {
56
		Crossings c = Crossings.findCrossings(pi,
57
				x, y, x+w, y+h);
58
		return (c != null && c.covers(y, y+h));
59
	}
60
	
61
	/**
62
	 * Tests if the interior of a <code>Shape</code> intersects the
63
	 * interior of a specified set of rectangular coordinates.
64
	 * @param pi the path iterator of a shape
65
	 * @param x,&nbsp;y the specified coordinates
66
	 * @param w the width of the specified rectangular coordinates
67
	 * @param h the height of the specified rectangular coordinates
68
	 * @return <code>true</code> if this <code>Shape</code> and the
69
	 * interior of the specified set of rectangular coordinates intersect
70
	 * each other; <code>false</code> otherwise.
71
	 */
72
	public static boolean intersects(PathIterator pi, double x, double y, double w, double h) {
73
		Crossings c = Crossings.findCrossings(pi,
74
				x, y, x+w, y+h);
75
		return (c == null || !c.isEmpty());
76
	}
77
	
78
	 /**
79
     * Calculates the number of times the given path
80
     * crosses the ray extending to the right from (px,py).
81
     * If the point lies on a part of the path,
82
     * then no crossings are counted for that intersection.
83
     * +1 is added for each crossing where the Y coordinate is increasing
84
     * -1 is added for each crossing where the Y coordinate is decreasing
85
     * The path must start with a SEG_MOVETO, otherwise an exception is
86
     * thrown.
87
     * The caller must check p[xy] for NaN values.
88
     * The caller may also reject infinite p[xy] values as well.
89
     * @param pi the path iterator of a shape
90
     * @param px the x coordinate
91
     * @param py the y coordinate
92
     * @return is the sum of all crossings for every segment in
93
     * the path
94
     */
95
	public static int pointCrossingsForPath(PathIterator pi, double px, double py){
96
		return Curve.pointCrossingsForPath(pi, px, py);
97
	}
98

  
99
}
100

  
org.gvsig.jdk/tags/org.gvsig.jdk-1.0.1/org.gvsig.jdk.v1_6/src/main/java/org/gvsig/jdk/sun/awt/geom/Crossings.java
1
/*
2
 * Copyright 1998-2003 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.jdk.sun.awt.geom;
27

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

  
32
public abstract class Crossings {
33
    public static final boolean debug = false;
34

  
35
    int limit = 0;
36
    double yranges[] = new double[10];
37

  
38
    double xlo, ylo, xhi, yhi;
39

  
40
    Crossings(double xlo, double ylo, double xhi, double yhi) {
41
        this.xlo = xlo;
42
        this.ylo = ylo;
43
        this.xhi = xhi;
44
        this.yhi = yhi;
45
    }
46

  
47
    public final double getXLo() {
48
        return xlo;
49
    }
50

  
51
    public final double getYLo() {
52
        return ylo;
53
    }
54

  
55
    public final double getXHi() {
56
        return xhi;
57
    }
58

  
59
    public final double getYHi() {
60
        return yhi;
61
    }
62

  
63
    public abstract void record(double ystart, double yend, int direction);
64

  
65
    public void print() {
66
        System.out.println("Crossings [");
67
        System.out.println("  bounds = ["+ylo+", "+yhi+"]");
68
        for (int i = 0; i < limit; i += 2) {
69
            System.out.println("  ["+yranges[i]+", "+yranges[i+1]+"]");
70
        }
71
        System.out.println("]");
72
    }
73

  
74
    public final boolean isEmpty() {
75
        return (limit == 0);
76
    }
77

  
78
    public abstract boolean covers(double ystart, double yend);
79

  
80
    public static Crossings findCrossings(Vector curves,
81
                                          double xlo, double ylo,
82
                                          double xhi, double yhi)
83
    {
84
        Crossings cross = new EvenOdd(xlo, ylo, xhi, yhi);
85
        Enumeration enum_ = curves.elements();
86
        while (enum_.hasMoreElements()) {
87
            Curve c = (Curve) enum_.nextElement();
88
            if (c.accumulateCrossings(cross)) {
89
                return null;
90
            }
91
        }
92
        if (debug) {
93
            cross.print();
94
        }
95
        return cross;
96
    }
97

  
98
    public static Crossings findCrossings(PathIterator pi,
99
                                          double xlo, double ylo,
100
                                          double xhi, double yhi)
101
    {
102
        Crossings cross;
103
        if (pi.getWindingRule() == pi.WIND_EVEN_ODD) {
104
            cross = new EvenOdd(xlo, ylo, xhi, yhi);
105
        } else {
106
            cross = new NonZero(xlo, ylo, xhi, yhi);
107
        }
108
        // coords array is big enough for holding:
109
        //     coordinates returned from currentSegment (6)
110
        //     OR
111
        //         two subdivided quadratic curves (2+4+4=10)
112
        //         AND
113
        //             0-1 horizontal splitting parameters
114
        //             OR
115
        //             2 parametric equation derivative coefficients
116
        //     OR
117
        //         three subdivided cubic curves (2+6+6+6=20)
118
        //         AND
119
        //             0-2 horizontal splitting parameters
120
        //             OR
121
        //             3 parametric equation derivative coefficients
122
        double coords[] = new double[23];
123
        double movx = 0;
124
        double movy = 0;
125
        double curx = 0;
126
        double cury = 0;
127
        double newx, newy;
128
        while (!pi.isDone()) {
129
            int type = pi.currentSegment(coords);
130
            switch (type) {
131
            case PathIterator.SEG_MOVETO:
132
                if (movy != cury &&
133
                    cross.accumulateLine(curx, cury, movx, movy))
134
                {
135
                    return null;
136
                }
137
                movx = curx = coords[0];
138
                movy = cury = coords[1];
139
                break;
140
            case PathIterator.SEG_LINETO:
141
                newx = coords[0];
142
                newy = coords[1];
143
                if (cross.accumulateLine(curx, cury, newx, newy)) {
144
                    return null;
145
                }
146
                curx = newx;
147
                cury = newy;
148
                break;
149
            case PathIterator.SEG_QUADTO:
150
                newx = coords[2];
151
                newy = coords[3];
152
                if (cross.accumulateQuad(curx, cury, coords)) {
153
                    return null;
154
                }
155
                curx = newx;
156
                cury = newy;
157
                break;
158
            case PathIterator.SEG_CUBICTO:
159
                newx = coords[4];
160
                newy = coords[5];
161
                if (cross.accumulateCubic(curx, cury, coords)) {
162
                    return null;
163
                }
164
                curx = newx;
165
                cury = newy;
166
                break;
167
            case PathIterator.SEG_CLOSE:
168
                if (movy != cury &&
169
                    cross.accumulateLine(curx, cury, movx, movy))
170
                {
171
                    return null;
172
                }
173
                curx = movx;
174
                cury = movy;
175
                break;
176
            }
177
            pi.next();
178
        }
179
        if (movy != cury) {
180
            if (cross.accumulateLine(curx, cury, movx, movy)) {
181
                return null;
182
            }
183
        }
184
        if (debug) {
185
            cross.print();
186
        }
187
        return cross;
188
    }
189

  
190
    public boolean accumulateLine(double x0, double y0,
191
                                  double x1, double y1)
192
    {
193
        if (y0 <= y1) {
194
            return accumulateLine(x0, y0, x1, y1, 1);
195
        } else {
196
            return accumulateLine(x1, y1, x0, y0, -1);
197
        }
198
    }
199

  
200
    public boolean accumulateLine(double x0, double y0,
201
                                  double x1, double y1,
202
                                  int direction)
203
    {
204
        if (yhi <= y0 || ylo >= y1) {
205
            return false;
206
        }
207
        if (x0 >= xhi && x1 >= xhi) {
208
            return false;
209
        }
210
        if (y0 == y1) {
211
            return (x0 >= xlo || x1 >= xlo);
212
        }
213
        double xstart, ystart, xend, yend;
214
        double dx = (x1 - x0);
215
        double dy = (y1 - y0);
216
        if (y0 < ylo) {
217
            xstart = x0 + (ylo - y0) * dx / dy;
218
            ystart = ylo;
219
        } else {
220
            xstart = x0;
221
            ystart = y0;
222
        }
223
        if (yhi < y1) {
224
            xend = x0 + (yhi - y0) * dx / dy;
225
            yend = yhi;
226
        } else {
227
            xend = x1;
228
            yend = y1;
229
        }
230
        if (xstart >= xhi && xend >= xhi) {
231
            return false;
232
        }
233
        if (xstart > xlo || xend > xlo) {
234
            return true;
235
        }
236
        record(ystart, yend, direction);
237
        return false;
238
    }
239

  
240
    private Vector tmp = new Vector();
241

  
242
    public boolean accumulateQuad(double x0, double y0, double coords[]) {
243
        if (y0 < ylo && coords[1] < ylo && coords[3] < ylo) {
244
            return false;
245
        }
246
        if (y0 > yhi && coords[1] > yhi && coords[3] > yhi) {
247
            return false;
248
        }
249
        if (x0 > xhi && coords[0] > xhi && coords[2] > xhi) {
250
            return false;
251
        }
252
        if (x0 < xlo && coords[0] < xlo && coords[2] < xlo) {
253
            if (y0 < coords[3]) {
254
                record(Math.max(y0, ylo), Math.min(coords[3], yhi), 1);
255
            } else if (y0 > coords[3]) {
256
                record(Math.max(coords[3], ylo), Math.min(y0, yhi), -1);
257
            }
258
            return false;
259
        }
260
        Curve.insertQuad(tmp, x0, y0, coords);
261
        Enumeration enum_ = tmp.elements();
262
        while (enum_.hasMoreElements()) {
263
            Curve c = (Curve) enum_.nextElement();
264
            if (c.accumulateCrossings(this)) {
265
                return true;
266
            }
267
        }
268
        tmp.clear();
269
        return false;
270
    }
271

  
272
    public boolean accumulateCubic(double x0, double y0, double coords[]) {
273
        if (y0 < ylo && coords[1] < ylo &&
274
            coords[3] < ylo && coords[5] < ylo)
275
        {
276
            return false;
277
        }
278
        if (y0 > yhi && coords[1] > yhi &&
279
            coords[3] > yhi && coords[5] > yhi)
280
        {
281
            return false;
282
        }
283
        if (x0 > xhi && coords[0] > xhi &&
284
            coords[2] > xhi && coords[4] > xhi)
285
        {
286
            return false;
287
        }
288
        if (x0 < xlo && coords[0] < xlo &&
289
            coords[2] < xlo && coords[4] < xlo)
290
        {
291
            if (y0 <= coords[5]) {
292
                record(Math.max(y0, ylo), Math.min(coords[5], yhi), 1);
293
            } else {
294
                record(Math.max(coords[5], ylo), Math.min(y0, yhi), -1);
295
            }
296
            return false;
297
        }
298
        Curve.insertCubic(tmp, x0, y0, coords);
299
        Enumeration enum_ = tmp.elements();
300
        while (enum_.hasMoreElements()) {
301
            Curve c = (Curve) enum_.nextElement();
302
            if (c.accumulateCrossings(this)) {
303
                return true;
304
            }
305
        }
306
        tmp.clear();
307
        return false;
308
    }
309

  
310
    final static class EvenOdd extends Crossings {
311
        public EvenOdd(double xlo, double ylo, double xhi, double yhi) {
312
            super(xlo, ylo, xhi, yhi);
313
        }
314

  
315
        public final boolean covers(double ystart, double yend) {
316
            return (limit == 2 && yranges[0] <= ystart && yranges[1] >= yend);
317
        }
318

  
319
        public void record(double ystart, double yend, int direction) {
320
            if (ystart >= yend) {
321
                return;
322
            }
323
            int from = 0;
324
            // Quickly jump over all pairs that are completely "above"
325
            while (from < limit && ystart > yranges[from+1]) {
326
                from += 2;
327
            }
328
            int to = from;
329
            while (from < limit) {
330
                double yrlo = yranges[from++];
331
                double yrhi = yranges[from++];
332
                if (yend < yrlo) {
333
                    // Quickly handle insertion of the new range
334
                    yranges[to++] = ystart;
335
                    yranges[to++] = yend;
336
                    ystart = yrlo;
337
                    yend = yrhi;
338
                    continue;
339
                }
340
                // The ranges overlap - sort, collapse, insert, iterate
341
                double yll, ylh, yhl, yhh;
342
                if (ystart < yrlo) {
343
                    yll = ystart;
344
                    ylh = yrlo;
345
                } else {
346
                    yll = yrlo;
347
                    ylh = ystart;
348
                }
349
                if (yend < yrhi) {
350
                    yhl = yend;
351
                    yhh = yrhi;
352
                } else {
353
                    yhl = yrhi;
354
                    yhh = yend;
355
                }
356
                if (ylh == yhl) {
357
                    ystart = yll;
358
                    yend = yhh;
359
                } else {
360
                    if (ylh > yhl) {
361
                        ystart = yhl;
362
                        yhl = ylh;
363
                        ylh = ystart;
364
                    }
365
                    if (yll != ylh) {
366
                        yranges[to++] = yll;
367
                        yranges[to++] = ylh;
368
                    }
369
                    ystart = yhl;
370
                    yend = yhh;
371
                }
372
                if (ystart >= yend) {
373
                    break;
374
                }
375
            }
376
            if (to < from && from < limit) {
377
                System.arraycopy(yranges, from, yranges, to, limit-from);
378
            }
379
            to += (limit-from);
380
            if (ystart < yend) {
381
                if (to >= yranges.length) {
382
                    double newranges[] = new double[to+10];
383
                    System.arraycopy(yranges, 0, newranges, 0, to);
384
                    yranges = newranges;
385
                }
386
                yranges[to++] = ystart;
387
                yranges[to++] = yend;
388
            }
389
            limit = to;
390
        }
391
    }
392

  
393
    final static class NonZero extends Crossings {
394
        private int crosscounts[];
395

  
396
        public NonZero(double xlo, double ylo, double xhi, double yhi) {
397
            super(xlo, ylo, xhi, yhi);
398
            crosscounts = new int[yranges.length / 2];
399
        }
400

  
401
        public final boolean covers(double ystart, double yend) {
402
            int i = 0;
403
            while (i < limit) {
404
                double ylo = yranges[i++];
405
                double yhi = yranges[i++];
406
                if (ystart >= yhi) {
407
                    continue;
408
                }
409
                if (ystart < ylo) {
410
                    return false;
411
                }
412
                if (yend <= yhi) {
413
                    return true;
414
                }
415
                ystart = yhi;
416
            }
417
            return (ystart >= yend);
418
        }
419

  
420
        public void remove(int cur) {
421
            limit -= 2;
422
            int rem = limit - cur;
423
            if (rem > 0) {
424
                System.arraycopy(yranges, cur+2, yranges, cur, rem);
425
                System.arraycopy(crosscounts, cur/2+1,
426
                                 crosscounts, cur/2,
427
                                 rem/2);
428
            }
429
        }
430

  
431
        public void insert(int cur, double lo, double hi, int dir) {
432
            int rem = limit - cur;
433
            double oldranges[] = yranges;
434
            int oldcounts[] = crosscounts;
435
            if (limit >= yranges.length) {
436
                yranges = new double[limit+10];
437
                System.arraycopy(oldranges, 0, yranges, 0, cur);
438
                crosscounts = new int[(limit+10)/2];
439
                System.arraycopy(oldcounts, 0, crosscounts, 0, cur/2);
440
            }
441
            if (rem > 0) {
442
                System.arraycopy(oldranges, cur, yranges, cur+2, rem);
443
                System.arraycopy(oldcounts, cur/2,
444
                                 crosscounts, cur/2+1,
445
                                 rem/2);
446
            }
447
            yranges[cur+0] = lo;
448
            yranges[cur+1] = hi;
449
            crosscounts[cur/2] = dir;
450
            limit += 2;
451
        }
452

  
453
        public void record(double ystart, double yend, int direction) {
454
            if (ystart >= yend) {
455
                return;
456
            }
457
            int cur = 0;
458
            // Quickly jump over all pairs that are completely "above"
459
            while (cur < limit && ystart > yranges[cur+1]) {
460
                cur += 2;
461
            }
462
            if (cur < limit) {
463
                int rdir = crosscounts[cur/2];
464
                double yrlo = yranges[cur+0];
465
                double yrhi = yranges[cur+1];
466
                if (yrhi == ystart && rdir == direction) {
467
                    // Remove the range from the list and collapse it
468
                    // into the range being inserted.  Note that the
469
                    // new combined range may overlap the following range
470
                    // so we must not simply combine the ranges in place
471
                    // unless we are at the last range.
472
                    if (cur+2 == limit) {
473
                        yranges[cur+1] = yend;
474
                        return;
475
                    }
476
                    remove(cur);
477
                    ystart = yrlo;
478
                    rdir = crosscounts[cur/2];
479
                    yrlo = yranges[cur+0];
480
                    yrhi = yranges[cur+1];
481
                }
482
                if (yend < yrlo) {
483
                    // Just insert the new range at the current location
484
                    insert(cur, ystart, yend, direction);
485
                    return;
486
                }
487
                if (yend == yrlo && rdir == direction) {
488
                    // Just prepend the new range to the current one
489
                    yranges[cur] = ystart;
490
                    return;
491
                }
492
                // The ranges must overlap - (yend > yrlo && yrhi > ystart)
493
                if (ystart < yrlo) {
494
                    insert(cur, ystart, yrlo, direction);
495
                    cur += 2;
496
                    ystart = yrlo;
497
                } else if (yrlo < ystart) {
498
                    insert(cur, yrlo, ystart, rdir);
499
                    cur += 2;
500
                    yrlo = ystart;
501
                }
502
                // assert(yrlo == ystart);
503
                int newdir = rdir + direction;
504
                double newend = Math.min(yend, yrhi);
505
                if (newdir == 0) {
506
                    remove(cur);
507
                } else {
508
                    crosscounts[cur/2] = newdir;
509
                    yranges[cur++] = ystart;
510
                    yranges[cur++] = newend;
511
                }
512
                ystart = yrlo = newend;
513
                if (yrlo < yrhi) {
514
                    insert(cur, yrlo, yrhi, rdir);
515
                }
516
            }
517
            if (ystart < yend) {
518
                insert(cur, ystart, yend, direction);
519
            }
520
        }
521
    }
522
}
org.gvsig.jdk/tags/org.gvsig.jdk-1.0.1/org.gvsig.jdk.v1_6/src/main/java/org/gvsig/jdk/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.jdk.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
    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
}
org.gvsig.jdk/tags/org.gvsig.jdk-1.0.1/org.gvsig.jdk.v1_6/src/main/java/org/gvsig/jdk/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.jdk.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
    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]) {
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff