Statistics
| Revision:

root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / core / FPolyline2DM.java @ 24154

History | View | Annotate | Download (3.34 KB)

1
package com.iver.cit.gvsig.fmap.core;
2

    
3
import java.awt.Component;
4

    
5
//import com.iver.andami.PluginServices;
6

    
7

    
8
/* gvSIG. Sistema de Informaci�n Geogr�fica de la Generalitat Valenciana
9
 *
10
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
11
 *
12
 * This program is free software; you can redistribute it and/or
13
 * modify it under the terms of the GNU General Public License
14
 * as published by the Free Software Foundation; either version 2
15
 * of the License, or (at your option) any later version.
16
 *
17
 * This program is distributed in the hope that it will be useful,
18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
 * GNU General Public License for more details.
21
 *
22
 * You should have received a copy of the GNU General Public License
23
 * along with this program; if not, write to the Free Software
24
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
25
 *
26
 * For more information, contact:
27
 *
28
 *  Generalitat Valenciana
29
 *   Conselleria d'Infraestructures i Transport
30
 *   Av. Blasco Ib��ez, 50
31
 *   46010 VALENCIA
32
 *   SPAIN
33
 *
34
 *      +34 963862235
35
 *   gvsig@gva.es
36
 *      www.gvsig.gva.es
37
 *
38
 *    or
39
 *
40
 *   IVER T.I. S.A
41
 *   Salamanca 50
42
 *   46005 Valencia
43
 *   Spain
44
 *
45
 *   +34 963163400
46
 *   dac@iver.es
47
 */
48
/* CVS MESSAGES:
49
 *
50
 * $Id: FPolyline2DM.java,v 1.1 2007/10/19 10:03:45 jorpiell Exp $
51
 * $Log: FPolyline2DM.java,v $
52
 * Revision 1.1  2007/10/19 10:03:45  jorpiell
53
 * First commit
54
 *
55
 *
56
 */
57
/**
58
 * This object represents a polyline with the M coordinate.
59
 * @author Jorge Piera LLodr� (jorge.piera@iver.es)
60
 */
61
public class FPolyline2DM extends FPolyline2D implements FShapeM{
62
        private static final long serialVersionUID = -617233536274899782L;
63
        double[] pM = null;
64

    
65
        FPolyline2DM(GeneralPathX gpx, double[] pM) {
66
                super(gpx);        
67
                this.pM = pM;
68
        }
69

    
70
        /*
71
         * (non-Javadoc)
72
         * @see com.iver.cit.gvsig.fmap.core.FShapeDS#getMs()
73
         */
74
        public double[] getMs() {
75
                return pM;
76
        }
77
        
78
        /*
79
         * (non-Javadoc)
80
         * @see com.iver.cit.gvsig.fmap.core.FPolyline3D#getShapeType()
81
         */
82
        public int getShapeType() {
83
                return FShape.LINE | FShape.M;
84
        }
85
        
86
        /*
87
         * (non-Javadoc)
88
         * @see com.iver.cit.gvsig.fmap.core.FPolyline3D#cloneFShape()
89
         */
90
        public FShape cloneFShape() {
91
                return new FPolyline2DM((GeneralPathX) gp.clone(), (double[]) pM);
92
        }
93

    
94
        /*
95
         * (non-Javadoc)
96
         * @see com.iver.cit.gvsig.fmap.core.FShapeM#setMAt(int, double)
97
         */
98
        public void setMAt(int i, double value) {
99
                if (i < pM.length){
100
                        pM[i] = value;                
101
                }
102
        }
103

    
104
        /*
105
         * (non-Javadoc)
106
         * @see com.iver.cit.gvsig.fmap.core.FShapeM#isDecreasing()
107
         */
108
        public boolean isDecreasing() {
109
                return (pM[0] > pM[pM.length-1]);
110
        }
111
        
112
        public void revertMs(){
113
                double totalDistance = Math.abs(pM[0] - pM[pM.length-1]);        
114
                double[] percentages = new double[pM.length];
115
                for (int i=1 ; i<percentages.length ; i++)
116
                {
117
                        percentages [i] = (Math.abs(pM[i]-pM[i-1]))/totalDistance;
118
                }                
119
                //The first value
120
                double pm0 = pM[0];                
121
                if (!isDecreasing()){
122
                        pM[0] = pM[pM.length-1];
123
                        for (int i=1 ; i<pM.length-1 ; i++)
124
                        {
125
                                double increasing = percentages[i] * totalDistance;
126
                                pM[i] = pM[i-1] - increasing;                                
127
                        }
128
                }else{
129
                        pM[0] = pM[pM.length-1];
130
                        for (int i=1 ; i<pM.length-1 ; i++)
131
                        {
132
                                double decreasing = percentages[i] * totalDistance;
133
                                pM[i] = pM[i-1] + decreasing;                                
134
                        }
135
                }
136
                pM[pM.length-1] = pm0;        
137
        }
138
}