Revision 35476

View differences:

branches/v2_0_0_prep/libraries/libFMap_geometries/src/org/gvsig/fmap/geom/operation/impl/DefaultGeometryOperationLibrary.java
1 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
*/
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 22

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

  
28 28
package org.gvsig.fmap.geom.operation.impl;
29 29

  
30 30
import org.gvsig.fmap.geom.Geometry.TYPES;
......
40 40
import org.gvsig.fmap.geom.operation.fromwkt.FromWKT;
41 41
import org.gvsig.fmap.geom.operation.isCCW.IsCCW;
42 42
import org.gvsig.fmap.geom.operation.perimeter.Perimeter;
43
import org.gvsig.fmap.geom.operation.perpendicular.Perpendicular;
44
import org.gvsig.fmap.geom.operation.perpendicular.PerpendicularPoint;
45
import org.gvsig.fmap.geom.operation.perpendicular.UnitVector;
43 46
import org.gvsig.fmap.geom.operation.relationship.Contains;
44 47
import org.gvsig.fmap.geom.operation.relationship.Crosses;
45 48
import org.gvsig.fmap.geom.operation.relationship.Disjoint;
......
67 70
        registerAsServiceOf(GeometryLibrary.class);
68 71
    }
69 72

  
70
	protected void doInitialize() throws LibraryException {
71
	}
73
    protected void doInitialize() throws LibraryException {
74
    }
72 75

  
73
	protected void doPostInitialize() throws LibraryException {
74
		
75
		// Validate there is any implementation registered.
76
		GeometryManager geometryManager = GeometryLocator.getGeometryManager();
77
		
78
		geometryManager.registerGeometryOperation(Contains.NAME, new Contains());
79
		geometryManager.registerGeometryOperation(Crosses.NAME, new Crosses());
80
		geometryManager.registerGeometryOperation(Disjoint.NAME, new Disjoint());
81
		geometryManager.registerGeometryOperation(Equals.NAME, new Equals());
82
		geometryManager.registerGeometryOperation(Intersects.NAME, new Intersects());
83
		geometryManager.registerGeometryOperation(Overlaps.NAME, new Overlaps());
84
		geometryManager.registerGeometryOperation(Touches.NAME, new Touches());
85
		geometryManager.registerGeometryOperation(Within.NAME, new Within());
86
		geometryManager.registerGeometryOperation(IsCCW.NAME, new IsCCW());
87
		geometryManager.registerGeometryOperation(FromWKT.NAME, new FromWKT());
88
		geometryManager.registerGeometryOperation(FromWKB.NAME, new FromWKB());
89
		geometryManager.registerGeometryOperation(Flip.NAME, new Flip());	
90
		geometryManager.registerGeometryOperation(EnsureOrientation.NAME,  new EnsureOrientation());		
91
		geometryManager.registerGeometryOperation(ToWKB.NAME,  new ToWKB());
92
		geometryManager.registerGeometryOperation(ToWKBNative.NAME,  new ToWKBNative());
93
		geometryManager.registerGeometryOperation(ToWKT.NAME, new ToWKT());
94
		geometryManager.registerGeometryOperation(PointDistance.NAME,  new PointDistance(), TYPES.POINT);
95
		geometryManager.registerGeometryOperation(ToJTS.NAME, new ToJTS());
96
		geometryManager.registerGeometryOperation(FromJTS.NAME, new FromJTS());
97
		geometryManager.registerGeometryOperation(PointGetAngle.NAME, new PointGetAngle());
98
		geometryManager.registerGeometryOperation(Out.NAME, new Out());
99
		geometryManager.registerGeometryOperation(Area.NAME, new Area());
100
	      geometryManager.registerGeometryOperation(Perimeter.NAME, new Perimeter());
101
	}	
76
    protected void doPostInitialize() throws LibraryException {
77

  
78
        // Validate there is any implementation registered.
79
        GeometryManager geometryManager = GeometryLocator.getGeometryManager();
80

  
81
        geometryManager.registerGeometryOperation(Contains.NAME, new Contains());
82
        geometryManager.registerGeometryOperation(Crosses.NAME, new Crosses());
83
        geometryManager.registerGeometryOperation(Disjoint.NAME, new Disjoint());
84
        geometryManager.registerGeometryOperation(Equals.NAME, new Equals());
85
        geometryManager.registerGeometryOperation(Intersects.NAME, new Intersects());
86
        geometryManager.registerGeometryOperation(Overlaps.NAME, new Overlaps());
87
        geometryManager.registerGeometryOperation(Touches.NAME, new Touches());
88
        geometryManager.registerGeometryOperation(Within.NAME, new Within());
89
        geometryManager.registerGeometryOperation(IsCCW.NAME, new IsCCW());
90
        geometryManager.registerGeometryOperation(FromWKT.NAME, new FromWKT());
91
        geometryManager.registerGeometryOperation(FromWKB.NAME, new FromWKB());
92
        geometryManager.registerGeometryOperation(Flip.NAME, new Flip());	
93
        geometryManager.registerGeometryOperation(EnsureOrientation.NAME,  new EnsureOrientation());		
94
        geometryManager.registerGeometryOperation(ToWKB.NAME,  new ToWKB());
95
        geometryManager.registerGeometryOperation(ToWKBNative.NAME,  new ToWKBNative());
96
        geometryManager.registerGeometryOperation(ToWKT.NAME, new ToWKT());
97
        geometryManager.registerGeometryOperation(PointDistance.NAME,  new PointDistance(), TYPES.POINT);
98
        geometryManager.registerGeometryOperation(ToJTS.NAME, new ToJTS());
99
        geometryManager.registerGeometryOperation(FromJTS.NAME, new FromJTS());
100
        geometryManager.registerGeometryOperation(PointGetAngle.NAME, new PointGetAngle());
101
        geometryManager.registerGeometryOperation(Out.NAME, new Out());
102
        geometryManager.registerGeometryOperation(Area.NAME, new Area());
103
        geometryManager.registerGeometryOperation(Perimeter.NAME, new Perimeter());
104
        geometryManager.registerGeometryOperation(Perpendicular.NAME,  new Perpendicular(), TYPES.POINT);
105
        geometryManager.registerGeometryOperation(PerpendicularPoint.NAME,  new PerpendicularPoint(), TYPES.POINT);
106
        geometryManager.registerGeometryOperation(UnitVector.NAME,  new UnitVector(), TYPES.POINT);
107
    }	
102 108
}
branches/v2_0_0_prep/libraries/libFMap_geometries/src/org/gvsig/fmap/geom/operation/perpendicular/PerpendicularOperationContext.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
package org.gvsig.fmap.geom.operation.perpendicular;
23

  
24
import org.gvsig.fmap.geom.operation.GeometryOperationContext;
25
import org.gvsig.fmap.geom.primitive.Point;
26

  
27

  
28
/**
29
 * @author gvSIG Team
30
 * @version $Id$
31
 *
32
 */
33
public class PerpendicularOperationContext extends GeometryOperationContext {
34
    public static final String SECOND_POINT = "secondPoint";
35
    public static final String PERPENDICULAR_POINT = "perpendicularPoint";
36

  
37
    public PerpendicularOperationContext(Point secondPoint, Point perpendicularPoint) {
38
        this.setSecondPoint(secondPoint);
39
        this.setPerpendicularPoint(perpendicularPoint);      
40
    }    
41
    
42
    public void setSecondPoint(Point secondPoint) {
43
        this.setAttribute(SECOND_POINT, secondPoint);
44
    }
45

  
46
    public Point getSecondPoint() {
47
        return (Point) this.getAttribute(SECOND_POINT);
48
    }
49
    
50
    public void setPerpendicularPoint(Point perpendicularPoint) {
51
        this.setAttribute(PERPENDICULAR_POINT, perpendicularPoint);
52
    }
53

  
54
    public Point getPerpendicularPoint() {
55
        return (Point) this.getAttribute(PERPENDICULAR_POINT);
56
    }
57
}
0 58

  
branches/v2_0_0_prep/libraries/libFMap_geometries/src/org/gvsig/fmap/geom/operation/perpendicular/PerpendicularPoint.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
package org.gvsig.fmap.geom.operation.perpendicular;
23

  
24
import org.gvsig.fmap.geom.Geometry;
25
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
26
import org.gvsig.fmap.geom.GeometryLocator;
27
import org.gvsig.fmap.geom.GeometryManager;
28
import org.gvsig.fmap.geom.exception.CreateGeometryException;
29
import org.gvsig.fmap.geom.operation.GeometryOperation;
30
import org.gvsig.fmap.geom.operation.GeometryOperationContext;
31
import org.gvsig.fmap.geom.operation.GeometryOperationException;
32
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException;
33
import org.gvsig.fmap.geom.primitive.Point;
34

  
35

  
36
/**
37
 * Gets a point that is located to a concrete distance (attribute distance)
38
 * of a line and is located in a perpendicular line that intersects with other 
39
 * point (attribute perpendicularPoint).
40
 * 
41
 * @author gvSIG Team
42
 * @version $Id$
43
 *
44
 */
45
public class PerpendicularPoint extends GeometryOperation{
46
    public static final String NAME = "perpendicularPoint";
47
    private static GeometryManager geomManager = GeometryLocator.getGeometryManager();
48
    public static final int CODE = geomManager.getGeometryOperationCode(NAME);
49
   
50
    @Override
51
    public Object invoke(Geometry geom, GeometryOperationContext ctx)
52
        throws GeometryOperationException {
53
      
54
        Point perpendicularPoint = (Point)ctx.getAttribute(PerpendicularPointOperationContext.PERPENDICULAR_POINT); 
55
        double dist = (Double)ctx.getAttribute(PerpendicularPointOperationContext.DISTANCE);
56
        
57
        try {
58
            Point[] p = (Point[])geom.invokeOperation(Perpendicular.CODE, ctx);
59
            Point unit = (Point)geom.invokeOperation(UnitVector.CODE, ctx);
60
            return  geomManager.createPoint(perpendicularPoint.getX() + (unit.getX() * dist),
61
                perpendicularPoint.getY() + (unit.getY() * dist), SUBTYPES.GEOM2D);
62
        } catch (GeometryOperationNotSupportedException e) {
63
            throw new GeometryOperationException(e);
64
        } catch (CreateGeometryException e) {
65
            throw new GeometryOperationException(e);
66
        }
67
    }
68
   
69
    public int getOperationIndex() {      
70
        return CODE;
71
    }    
72
}
0 73

  
branches/v2_0_0_prep/libraries/libFMap_geometries/src/org/gvsig/fmap/geom/operation/perpendicular/UnitVectorOperationContext.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
package org.gvsig.fmap.geom.operation.perpendicular;
23

  
24
import org.gvsig.fmap.geom.operation.GeometryOperationContext;
25
import org.gvsig.fmap.geom.primitive.Point;
26

  
27

  
28
/**
29
 * @author gvSIG Team
30
 * @version $Id$
31
 *
32
 */
33
public class UnitVectorOperationContext  extends GeometryOperationContext {
34
    public static final String SECOND_POINT = "secondPoint";
35
   
36
    public UnitVectorOperationContext(Point secondPoint) {
37
        this.setSecondPoint(secondPoint);       
38
    }    
39
    
40
    public void setSecondPoint(Point secondPoint) {
41
        this.setAttribute(SECOND_POINT, secondPoint);
42
    }
43

  
44
    public Point getSecondPoint() {
45
        return (Point) this.getAttribute(SECOND_POINT);
46
    }   
47
}
0 48

  
branches/v2_0_0_prep/libraries/libFMap_geometries/src/org/gvsig/fmap/geom/operation/perpendicular/Perpendicular.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
package org.gvsig.fmap.geom.operation.perpendicular;
23

  
24
import org.gvsig.fmap.geom.Geometry;
25
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
26
import org.gvsig.fmap.geom.GeometryLocator;
27
import org.gvsig.fmap.geom.GeometryManager;
28
import org.gvsig.fmap.geom.exception.CreateGeometryException;
29
import org.gvsig.fmap.geom.operation.GeometryOperation;
30
import org.gvsig.fmap.geom.operation.GeometryOperationContext;
31
import org.gvsig.fmap.geom.operation.GeometryOperationException;
32
import org.gvsig.fmap.geom.primitive.Point;
33

  
34

  
35
/**
36
 * Gets a couple of points that defines a line that is perpendicular to other line
37
 * and intersects with a point.
38
 * @author gvSIG Team
39
 * @version $Id$
40
 *
41
 */
42
public class Perpendicular extends GeometryOperation{
43
    public static final String NAME = "perpendicular";
44
    private static GeometryManager geomManager = GeometryLocator.getGeometryManager();
45
    public static final int CODE = geomManager.getGeometryOperationCode(NAME);
46
   
47
    @Override
48
    public Object invoke(Geometry geom, GeometryOperationContext ctx)
49
        throws GeometryOperationException {
50
        Point point1 = (Point)geom;
51
        Point point2 = (Point)ctx.getAttribute(PerpendicularOperationContext.SECOND_POINT);
52
        Point perpendicularPoint = (Point)ctx.getAttribute(PerpendicularOperationContext.PERPENDICULAR_POINT);        
53
        
54
        if ((point2.getY() - point1.getY()) == 0) {
55
            try {
56
                return new Point[] {
57
                    geomManager.createPoint(perpendicularPoint.getX(), 0, SUBTYPES.GEOM2D),
58
                    geomManager.createPoint(perpendicularPoint.getX(), 1, SUBTYPES.GEOM2D)
59
                };
60
            } catch (CreateGeometryException e) {
61
                throw new GeometryOperationException(e);
62
            }
63
        }
64

  
65
        //Pendiente de la recta perpendicular
66
        double m = (point1.getX() - point2.getX()) / (point2.getY() - point1.getY());
67

  
68
        //b de la funcion de la recta perpendicular
69
        double b = perpendicularPoint.getY() - (m * perpendicularPoint.getX());
70

  
71
        //Obtenemos un par de puntos
72
        try {
73
            return new Point[] {
74
                geomManager.createPoint(0, (m * 0) + b, SUBTYPES.GEOM2D),
75
                geomManager.createPoint(1000, (m * 1000) + b, SUBTYPES.GEOM2D)
76
            };
77
        } catch (CreateGeometryException e) {
78
            throw new GeometryOperationException(e);
79
        }
80
    }
81
   
82
    public int getOperationIndex() {      
83
        return CODE;
84
    }    
85
}
0 86

  
branches/v2_0_0_prep/libraries/libFMap_geometries/src/org/gvsig/fmap/geom/operation/perpendicular/PerpendicularPointOperationContext.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
package org.gvsig.fmap.geom.operation.perpendicular;
23

  
24
import org.gvsig.fmap.geom.operation.GeometryOperationContext;
25
import org.gvsig.fmap.geom.primitive.Point;
26

  
27

  
28
/**
29
 * @author gvSIG Team
30
 * @version $Id$
31
 */
32
public class PerpendicularPointOperationContext extends GeometryOperationContext {
33
    public static final String SECOND_POINT = "secondPoint";
34
    public static final String PERPENDICULAR_POINT = "perpendicularPoint";
35
    public static final String DISTANCE = "distance";
36

  
37
    public PerpendicularPointOperationContext(Point secondPoint, Point perpendicularPoint, double distance) {
38
        this.setSecondPoint(secondPoint);
39
        this.setPerpendicularPoint(perpendicularPoint);
40
        this.setDistance(distance);
41
    }    
42
    
43
    public void setSecondPoint(Point secondPoint) {
44
        this.setAttribute(SECOND_POINT, secondPoint);
45
    }
46

  
47
    public Point getSecondPoint() {
48
        return (Point) this.getAttribute(SECOND_POINT);
49
    }
50
    
51
    public void setPerpendicularPoint(Point perpendicularPoint) {
52
        this.setAttribute(PERPENDICULAR_POINT, perpendicularPoint);
53
    }
54

  
55
    public Point getPerpendicularPoint() {
56
        return (Point) this.getAttribute(PERPENDICULAR_POINT);
57
    }
58
    
59
    public double getDistance() {
60
        return (Double) this.getAttribute(DISTANCE);
61
    }
62

  
63
    public void setDistance(double distance) {
64
        this.setAttribute(DISTANCE, distance);
65
    }
66
}
0 67

  
branches/v2_0_0_prep/libraries/libFMap_geometries/src/org/gvsig/fmap/geom/operation/perpendicular/UnitVector.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
package org.gvsig.fmap.geom.operation.perpendicular;
23

  
24
import java.awt.geom.Point2D;
25

  
26
import org.gvsig.fmap.geom.Geometry;
27
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
28
import org.gvsig.fmap.geom.GeometryLocator;
29
import org.gvsig.fmap.geom.GeometryManager;
30
import org.gvsig.fmap.geom.exception.CreateGeometryException;
31
import org.gvsig.fmap.geom.operation.GeometryOperation;
32
import org.gvsig.fmap.geom.operation.GeometryOperationContext;
33
import org.gvsig.fmap.geom.operation.GeometryOperationException;
34
import org.gvsig.fmap.geom.primitive.Point;
35

  
36

  
37
/**
38
 * Returns an unit vector from two points.
39
 * 
40
 * @author gvSIG Team
41
 * @version $Id$
42
 *
43
 */
44
public class UnitVector extends GeometryOperation{
45
    public static final String NAME = "perpendicular";
46
    private static GeometryManager geomManager = GeometryLocator.getGeometryManager();
47
    public static final int CODE = geomManager.getGeometryOperationCode(NAME);
48

  
49
    public Object invoke(Geometry geom, GeometryOperationContext ctx)
50
        throws GeometryOperationException {
51
        Point point1 = (Point)geom;
52
        Point point2 = (Point)ctx.getAttribute(PerpendicularOperationContext.SECOND_POINT);
53

  
54
        Point2D paux = new Point2D.Double(point2.getX() - point1.getX(),
55
            point2.getY() - point1.getY());
56

  
57
        double v = Math.sqrt(Math.pow(paux.getX(), 2d) +
58
            Math.pow(paux.getY(), 2d));
59

  
60
        paux = new Point2D.Double(paux.getX() / v, paux.getY() / v);
61

  
62
        try{
63
            return  geomManager.createPoint(paux.getX() / v, paux.getY() / v, SUBTYPES.GEOM2D);
64
        } catch (CreateGeometryException e) {
65
            throw new GeometryOperationException(e);
66
        }
67
    }
68

  
69
    public int getOperationIndex() {      
70
        return CODE;
71
    }    
72
}
0 73

  
branches/v2_0_0_prep/libraries/libFMap_geometries/src/org/gvsig/fmap/geom/util/UtilFunctions.java
152 152
	 * 		  distinto a p2
153 153
	 *
154 154
	 * @return Array con dos puntos que definen la recta resultante
155
	 * @deprecated 
156
	 *         use the perpendicular operation
155 157
	 */
156 158
	public static Point2D[] getPerpendicular(Point2D p1, Point2D p2,
157 159
		Point2D perp) {
......
193 195
	 * @param dist Distancia del punto que se quiere obtener a la recta p1-p2
194 196
	 *
195 197
	 * @return DOCUMENT ME!
198
	 * @deprecated
199
	 *         Use the perpendicularPoint operation
196 200
	 */
197 201
	public static Point2D getPerpendicularPoint(Point2D p1, Point2D p2,
198 202
		Point2D perpPoint, double dist) {
......
210 214
	 * @param p2 punto destino.
211 215
	 *
212 216
	 * @return vector unitario.
217
	 * @deprecated
218
	 *         use the UnitVector operation
213 219
	 */
214 220
	public static Point2D getUnitVector(Point2D p1, Point2D p2) {
215 221
		Point2D paux = new Point2D.Double(p2.getX() - p1.getX(),

Also available in: Unified diff