Revision 38785

View differences:

branches/v2_0_0_prep/libraries/libFMap_geometries/src-test/org/gvsig/fmap/geom/primitive/ArcTest.java
60 60
			e = e1;
61 61
		}
62 62
		Assert.assertTrue(e instanceof UnsupportedOperationException);
63
		
64
		Point center = (Point)manager.create(TYPES.POINT, SUBTYPES.GEOM2D);
65
		center.setCoordinateAt(0, 0);
66
		center.setCoordinateAt(1, 0);
67
		
63

  
64

  
68 65
		Point initPoint = (Point)manager.create(TYPES.POINT, SUBTYPES.GEOM2D);
69 66
		initPoint.setCoordinateAt(0, 1);
70 67
		initPoint.setCoordinateAt(1, 1);
68

  
69
		Point middle = (Point)manager.create(TYPES.POINT, SUBTYPES.GEOM2D);
70
		middle.setCoordinateAt(0, 0);
71
		middle.setCoordinateAt(1, 0);
71 72
		
73
		
72 74
		Point endPoint = (Point)manager.create(TYPES.POINT, SUBTYPES.GEOM2D);
73 75
		endPoint.setCoordinateAt(0, 0);
74 76
		endPoint.setCoordinateAt(1, 1);
75 77
		
76
		arc.setPoints(center, initPoint, endPoint);
78
		arc.setPoints(initPoint, middle, endPoint);
77 79
		
78 80
		assertEquals(0.5, arc.getCenterPoint().getX(), 0);
79
		assertEquals(0.5, arc.getCenterPoint().getX(), 0);
81
		assertEquals(0.5, arc.getCenterPoint().getY(), 0);
80 82
		assertEquals(1.0, arc.getInitPoint().getX(), 0);
81
		assertEquals(1.0, arc.getInitPoint().getX(), 0);
83
		assertEquals(1.0, arc.getInitPoint().getY(), 0);
82 84
		assertEquals(0, arc.getEndPoint().getX(), 0);
83
		assertEquals(0, arc.getEndPoint().getX(), 0);
85
		assertEquals(1, arc.getEndPoint().getY(), 0);
84 86
	}	
85 87
}
86 88

  
branches/v2_0_0_prep/libraries/libFMap_geometries/src/org/gvsig/fmap/geom/primitive/Arc.java
43 43
		
44 44
	/**
45 45
	 * Sets the three points to define an arc.
46
	 * @param midPoint
47
	 * The middle point of an arc.
46
	 * These are three ordered points that belong to the arc
47
	 * (none of them is the center of the ellipse/circle). Therefore
48
	 * they must not be aligned.
49
	 * 
48 50
	 * @param startPoint
49 51
	 * The start point of an arc.
52
     * @param midPoint
53
     * The middle point of an arc.
50 54
	 * @param endPoint
51 55
	 * The end point of an arc.
56
	 * @exception IllegalArgumentException if the three points are aligned or
57
	 * there is a repeated point.
58
	 * 
52 59
	 */
53
	void setPoints(Point midPoint, Point startPoint, Point endPoint);
60
	void setPoints(Point startPoint, Point midPoint, Point endPoint);
54 61
	
55 62
	/**
56 63
	 * Sets the values to define an arc.
......
68 75
	 */
69 76
	void setPoints (Point center, double radius, double startAngle, double angleExt);
70 77
	
78
	
71 79
	/**
72 80
	 * Return the first point that has been used to create the arc.
73 81
	 * @return
......
83 91
	Point getEndPoint();
84 92
	
85 93
	/**
86
	 * Return the center point that has been used to create the arc.
87
	 * @return
88
	 * The center point of the arc.
94
	 * Return the center of the arc, that is, the center of the ellipse/circle
95
	 * in which the arc is based.
96
	 * 
97
	 * @return The center of the arc.
89 98
	 */
90 99
	Point getCenterPoint();
91 100
		
branches/v2_0_0_prep/libraries/libFMap_geometries/src/org/gvsig/fmap/geom/primitive/impl/Arc2D.java
75 75
	private static final long serialVersionUID = 6416027005106924030L;
76 76

  
77 77
	private Point2D init;
78
	private Point2D center;
78
	
79
	/**
80
	 * This is the middle point (belongs to the arc), not the center
81
	 * of the circle/ellipse
82
	 */
83
	private Point2D middle;
79 84
	private Point2D end;
80 85
	
81 86
	private static final GeometryManager geomManager = GeometryLocator.getGeometryManager();
......
103 108
	protected Arc2D(GeometryType geometryType, String id, IProjection projection, GeneralPathX gpx, Point2D i,Point2D c, Point2D e) {
104 109
		super(geometryType, id, projection, gpx);
105 110
		init=i;
106
		center=c;
111
		middle=c;
107 112
		end=e;
108 113
	}	
109 114
	
......
111 116
	 * @see com.iver.cit.gvsig.fmap.core.FShape#cloneFShape()
112 117
	 */
113 118
	public FShape cloneFShape() {
114
		Arc2D arc = new Arc2D(getGeometryType(), id, projection, (GeneralPathX) gp.clone(),init,center,end);
119
		Arc2D arc = new Arc2D(getGeometryType(), id, projection, (GeneralPathX) gp.clone(),init,middle,end);
115 120
		return arc;
116 121
	}
117 122
	
......
169 174
		ArrayList handlers = new ArrayList();
170 175

  
171 176
		handlers.add(new InitSelHandler(0, init.getX(), init.getY()));
172
		handlers.add(new CenterSelHandler(1, center.getX(), center.getY()));
177
		handlers.add(new CenterSelHandler(1, middle.getX(), middle.getY()));
173 178
		handlers.add(new EndSelHandler(2, end.getX(), end.getY()));
174 179

  
175 180
		return (Handler[]) handlers.toArray(new Handler[0]);
......
188 193
		 * @param y DOCUMENT ME!
189 194
		 */
190 195
		public CenterSelHandler(int i, double x, double y) {
191
			center = new Point2D.Double(x, y);
196
		    middle = new Point2D.Double(x, y);
192 197
			index = i;
193 198
		}
194 199

  
......
203 208
		public void move(double x, double y) {
204 209
		}
205 210
		public void setPoint(Point2D p){
206
			center=p;
211
		    middle=p;
207 212
		}
208 213
		public Point2D getPoint(){
209
			return center;
214
			return middle;
210 215
		}
211 216

  
212 217
		/**
213 218
		 * @see org.gvsig.fmap.geom.handler.Handler#set(double, double)
214 219
		 */
215 220
		public void set(double x, double y) {
216
			center=new Point2D.Double(x,y);
217
			java.awt.geom.Arc2D arco = UtilFunctions.createArc(init, center, end);
221
		    middle=new Point2D.Double(x,y);
222
			java.awt.geom.Arc2D arco = UtilFunctions.createArc(init, middle, end);
218 223
			gp = new GeneralPathX(arco.getPathIterator(null));
219 224
		}
220 225
	}
......
247 252
		 */
248 253
		public void move(double x, double y) {
249 254
			Point2D mediop=new Point2D.Double((init.getX()+end.getX())/2,(init.getY()+end.getY())/2);
250
			double dist=mediop.distance(center);
255
			double dist=mediop.distance(middle);
251 256
			init=new Point2D.Double(init.getX()+x,init.getY()+y);
252 257

  
253 258
			mediop=new Point2D.Double((init.getX()+end.getX())/2,(init.getY()+end.getY())/2);
......
255 260
			if (UtilFunctions.getAngle(end,init)<=Math.PI){
256 261
				dist=-dist;
257 262
			}
258
			center=UtilFunctions.getPoint(mediop,perp[1],dist);
263
			middle=UtilFunctions.getPoint(mediop,perp[1],dist);
259 264

  
260
			java.awt.geom.Arc2D arco = UtilFunctions.createArc(init,center, end);
265
			java.awt.geom.Arc2D arco = UtilFunctions.createArc(init,middle, end);
261 266
			gp=new GeneralPathX(arco.getPathIterator(null));
262 267
		}
263 268
		public void setPoint(Point2D p){
......
302 307
		 */
303 308
		public void move(double x, double y) {
304 309
			Point2D mediop=new Point2D.Double((init.getX()+end.getX())/2,(init.getY()+end.getY())/2);
305
			double dist=mediop.distance(center);
310
			double dist=mediop.distance(middle);
306 311
			end=new Point2D.Double(end.getX()+x,end.getY()+y);
307 312

  
308 313
			mediop=new Point2D.Double((init.getX()+end.getX())/2,(init.getY()+end.getY())/2);
......
310 315
			if (UtilFunctions.getAngle(end,init)<=Math.PI){
311 316
				dist=-dist;
312 317
			}
313
			center=UtilFunctions.getPoint(mediop,perp[1],dist);
318
			middle=UtilFunctions.getPoint(mediop,perp[1],dist);
314 319

  
315
			java.awt.geom.Arc2D arco = UtilFunctions.createArc(init,center, end);
320
			java.awt.geom.Arc2D arco = UtilFunctions.createArc(init,middle, end);
316 321
			gp=new GeneralPathX(arco.getPathIterator(null));
317 322
		}
318 323
		public void setPoint(Point2D p){
......
358 363
		 */
359 364
		public void move(double x, double y) {
360 365
			Point2D mediop=new Point2D.Double((init.getX()+end.getX())/2,(init.getY()+end.getY())/2);
361
			double dist=mediop.distance(center);
366
			double dist=mediop.distance(middle);
362 367
			init=new Point2D.Double(init.getX()+x,init.getY()+y);
363 368

  
364 369
			mediop=new Point2D.Double((init.getX()+end.getX())/2,(init.getY()+end.getY())/2);
......
366 371
			if (UtilFunctions.getAngle(end,init)<=Math.PI){
367 372
				dist=-dist;
368 373
			}
369
			center=UtilFunctions.getPoint(mediop,perp[1],dist);
374
			middle=UtilFunctions.getPoint(mediop,perp[1],dist);
370 375

  
371
			java.awt.geom.Arc2D arco = UtilFunctions.createArc(init,center, end);
376
			java.awt.geom.Arc2D arco = UtilFunctions.createArc(init,middle, end);
372 377
			gp=new GeneralPathX(arco.getPathIterator(null));
373 378
		}
374 379
		public void setPoint(Point2D p){
......
383 388
		 */
384 389
		public void set(double x, double y) {
385 390
			Point2D mediop=new Point2D.Double((init.getX()+end.getX())/2,(init.getY()+end.getY())/2);
386
			double dist=mediop.distance(center);
391
			double dist=mediop.distance(middle);
387 392
			init=new Point2D.Double(x,y);
388 393

  
389 394
			mediop=new Point2D.Double((init.getX()+end.getX())/2,(init.getY()+end.getY())/2);
......
392 397
				dist=-dist;
393 398
			}
394 399
			///center=TrigonometricalFunctions.getPoint(mediop,perp[1],dist);
395
			java.awt.geom.Arc2D arco = UtilFunctions.createArc(init,center, end);
400
			java.awt.geom.Arc2D arco = UtilFunctions.createArc(init,middle, end);
396 401
			gp=new GeneralPathX(arco.getPathIterator(null));
397 402
		}
398 403
	}
......
425 430
		 */
426 431
		public void move(double x, double y) {
427 432
			Point2D mediop=new Point2D.Double((init.getX()+end.getX())/2,(init.getY()+end.getY())/2);
428
			double dist=mediop.distance(center);
433
			double dist=mediop.distance(middle);
429 434
			end=new Point2D.Double(end.getX()+x,end.getY()+y);
430 435

  
431 436
			mediop=new Point2D.Double((init.getX()+end.getX())/2,(init.getY()+end.getY())/2);
......
433 438
			if (UtilFunctions.getAngle(end,init)<=Math.PI){
434 439
				dist=-dist;
435 440
			}
436
			center=UtilFunctions.getPoint(mediop,perp[1],dist);
441
			middle=UtilFunctions.getPoint(mediop,perp[1],dist);
437 442

  
438
			java.awt.geom.Arc2D arco = UtilFunctions.createArc(init,center, end);
443
			java.awt.geom.Arc2D arco = UtilFunctions.createArc(init,middle, end);
439 444
			gp=new GeneralPathX(arco.getPathIterator(null));
440 445
		}
441 446
		public void setPoint(Point2D p){
......
450 455
		 */
451 456
		public void set(double x, double y) {
452 457
			Point2D mediop=new Point2D.Double((init.getX()+end.getX())/2,(init.getY()+end.getY())/2);
453
			double dist=mediop.distance(center);
458
			double dist=mediop.distance(middle);
454 459
			end=new Point2D.Double(x,y);
455 460

  
456 461
			mediop=new Point2D.Double((init.getX()+end.getX())/2,(init.getY()+end.getY())/2);
......
459 464
				dist=-dist;
460 465
			}
461 466
			///center=TrigonometricalFunctions.getPoint(mediop,perp[1],dist);
462
			java.awt.geom.Arc2D arco = UtilFunctions.createArc(init,center, end);
467
			java.awt.geom.Arc2D arco = UtilFunctions.createArc(init,middle, end);
463 468
			gp=new GeneralPathX(arco.getPathIterator(null));
464 469
		}
465 470
	}
......
497 502
			throw new IllegalArgumentException();
498 503
		}
499 504
		this.gp = new GeneralPathX(arco.getPathIterator(null));
500
		this.center = p1;
501
		this.init = p2;
505
		this.init = p1;
506
        this.middle = p2;
502 507
		this.end = p3;
503 508
	}
504 509

  
......
529 534

  
530 535
		setPoints(p1, p2, p3);		
531 536
	}
537
	
532 538

  
539

  
533 540
	/* (non-Javadoc)
534 541
	 * @see org.gvsig.fmap.geom.primitive.Curve2D#setPoints(org.gvsig.fmap.geom.primitive.Point, org.gvsig.fmap.geom.primitive.Point)
535 542
	 */
......
555 562
	 * @see org.gvsig.fmap.geom.primitive.Arc#getCenterPoint()
556 563
	 */
557 564
	public Point getCenterPoint() {
558
		Point2D p = UtilFunctions.getCenter(init, center,end);
565
		Point2D p = UtilFunctions.getCenter(init, middle,end);
559 566
		try {
560 567
			return new org.gvsig.fmap.geom.primitive.impl.Point2D(p.getX(), p.getY());
561 568
		} catch (Exception e) {
562 569
			return  null;
563 570
		}
564
	}		
571
	}
572

  
573
		
565 574
}

Also available in: Unified diff