Revision 29972

View differences:

branches/v2_0_0_prep/libraries/libFMap_geometries/src/org/gvsig/fmap/geom/aggregate/impl/BaseMultiPrimitive.java
11 11
import org.cresques.cts.ICoordTrans;
12 12
import org.cresques.cts.IProjection;
13 13
import org.gvsig.fmap.geom.Geometry;
14
import org.gvsig.fmap.geom.GeometryManager;
14 15
import org.gvsig.fmap.geom.aggregate.MultiPrimitive;
15 16
import org.gvsig.fmap.geom.handler.Handler;
17
import org.gvsig.fmap.geom.operation.GeometryOperationException;
16 18
import org.gvsig.fmap.geom.primitive.Envelope;
17 19
import org.gvsig.fmap.geom.primitive.FShape;
18 20
import org.gvsig.fmap.geom.primitive.GeneralPathX;
19 21
import org.gvsig.fmap.geom.primitive.Primitive;
20 22
import org.gvsig.fmap.geom.primitive.impl.AbstractPrimitive;
21 23
import org.gvsig.fmap.geom.type.GeometryType;
24
import org.slf4j.Logger;
25
import org.slf4j.LoggerFactory;
22 26

  
23 27
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
24 28
 *
......
78 82
public abstract class BaseMultiPrimitive extends AbstractPrimitive implements
79 83
		MultiPrimitive {
80 84
	private static final long serialVersionUID = 8023609161647736932L;
85
	
86
	private static final Logger logger = LoggerFactory.getLogger(GeometryManager.class);
87

  
81 88
	protected ArrayList geometries = null;
82 89
	
83 90
	/**
......
112 119
	 * @see java.awt.Shape#contains(double, double)
113 120
	 */
114 121
	public boolean contains(double x, double y) {
122
		
115 123
		boolean bResul;
116 124
		for (int i = 0; i < getPrimitivesNumber(); i++) {
117
			bResul = ((Geometry)geometries.get(i)).contains(x, y);
125

  
126
			try {
127
				bResul = containsPoint(
128
						(Geometry)geometries.get(i), x, y);
129
			} catch (GeometryOperationException e) {
130
				logger.error("While doing contains: " + e.getMessage(), e);
131
				bResul = true;
132
			}
133

  
118 134
			if (bResul)
119 135
				return true;
120 136
		}
......
138 154
	public boolean contains(Point2D p) {
139 155
		boolean bResul;
140 156
		for (int i = 0; i < getPrimitivesNumber(); i++) {
141
			bResul = ((Geometry)geometries.get(i)).contains(p);
157
			try {
158
				bResul = containsPoint(
159
						(Geometry)geometries.get(i),
160
						p.getX(), p.getY());
161
			} catch (GeometryOperationException e) {
162
				logger.error("While doing contains: " + e.getMessage(), e);
163
				bResul = true;
164
			}
142 165
			if (bResul)
143 166
				return true;
144 167
		}
......
153 176
	public boolean contains(Rectangle2D r) {
154 177
		boolean bResul;
155 178
		for (int i = 0; i < getPrimitivesNumber(); i++) {
156
			bResul = ((Geometry)geometries.get(i)).contains(r);
179
			
180
			try {
181
				bResul = containsRectangle(
182
						(Geometry)geometries.get(i),
183
						r.getMinX(), r.getMinY(), r.getWidth(), r.getHeight());
184
			} catch (GeometryOperationException e) {
185
				logger.error("While doing contains: " + e.getMessage(), e);
186
				bResul = true;
187
			}
188
			
189
			
157 190
			if (bResul)
158 191
				return true;
159 192
		}
......
176 209
	 *      double, double, double)
177 210
	 */
178 211
	public boolean fastIntersects(double x, double y, double w, double h) {
212
		
213
		boolean resp = false;
179 214
		for (int i = 0; i < getPrimitivesNumber(); i++) {
180
			if (((Geometry)geometries.get(i)).intersects(x, y, w, h))
215
			
216
			Geometry geom = (Geometry) geometries.get(i);
217
			
218
			try {
219
				resp = intersectsRectangle(geom, x, y, w, h);
220
			} catch (GeometryOperationException e) {
221
				logger.error("While doing fast intersects: " + e.getMessage(), e);
222
				resp = true;
223
			}
224
			
225
			if (resp) {
181 226
				return true;
227
			}
228
			
229
				
230
				
182 231
		}
183 232
		return false;
184 233
	}
185 234

  
235

  
186 236
	/*
187 237
	 * (non-Javadoc)
188 238
	 *
......
310 360
	public boolean intersects(double x, double y, double w, double h) {
311 361
		boolean bResul;
312 362
		for (int i = 0; i < getPrimitivesNumber(); i++) {
313
			bResul = ((Geometry)geometries.get(i)).contains(x, y, w, h);
363

  
364
			try {
365
				bResul = containsRectangle((Geometry)geometries.get(i), x, y, w, h);
366
			} catch (GeometryOperationException e) {
367
				logger.error("While doing contains: " + e.getMessage(), e);
368
				bResul = true;
369
			}
314 370
			if (bResul)
315 371
				return true;
316 372
		}
317 373
		return false;
318 374
	}
319 375

  
376

  
320 377
	/*
321 378
	 * (non-Javadoc)
322 379
	 *
......
419 476
	public void addPrimitive(Primitive primitive) {
420 477
		geometries.add(primitive);
421 478
	}
479
	
480

  
481

  
482

  
483

  
422 484
}
branches/v2_0_0_prep/libraries/libFMap_geometries/src/org/gvsig/fmap/geom/primitive/impl/Curve2D.java
136 136
	 */
137 137
	private void setPoints(Point2D startPoint, Point2D endPoint) {
138 138
		Line2D line = UtilFunctions.createLine(startPoint, endPoint);
139
		setGeneralPath(new GeneralPathX(line));
139
		setGeneralPath(new GeneralPathX(line.getPathIterator(null)));
140 140
	}
141 141

  
142 142
	/* (non-Javadoc)
branches/v2_0_0_prep/libraries/libFMap_geometries/src/org/gvsig/fmap/geom/primitive/impl/EllipticArc2D.java
390 390
			double angle = UtilFunctions.getAngle(axis1Start, axis1End);
391 391
			AffineTransform mT = AffineTransform.getRotateInstance(angle, axis1Start
392 392
					.getX(), axis1Start.getY());
393
			gp = new GeneralPathX(arc);
393
			gp = new GeneralPathX(arc.getPathIterator(null));
394 394
			gp.transform(mT);
395 395

  
396 396
		}
......
460 460
			double angle = UtilFunctions.getAngle(axis1Start, axis1End);
461 461
			AffineTransform mT = AffineTransform.getRotateInstance(angle, axis1Start
462 462
					.getX(), axis1Start.getY());
463
			gp = new GeneralPathX(arc);
463
			gp = new GeneralPathX(arc.getPathIterator(null));
464 464
			gp.transform(mT);
465 465

  
466 466
		}
......
525 525
			double angle = UtilFunctions.getAngle(axis1Start, axis1End);
526 526
			AffineTransform mT = AffineTransform.getRotateInstance(angle, axis1Start
527 527
					.getX(), axis1Start.getY());
528
			gp = new GeneralPathX(arc);
528
			gp = new GeneralPathX(arc.getPathIterator(null));
529 529
			gp.transform(mT);
530 530
		}
531 531
	}
......
573 573
				Arc2D.OPEN);
574 574
		AffineTransform mT = AffineTransform.getRotateInstance(angle,
575 575
				center.getX(), center.getY());
576
		GeneralPathX gp = new GeneralPathX(arc);
576
		GeneralPathX gp = new GeneralPathX(arc.getPathIterator(null));
577 577
		gp.transform(mT);
578 578

  
579 579
		this.gp = gp;
branches/v2_0_0_prep/libraries/libFMap_geometries/src/org/gvsig/fmap/geom/primitive/impl/Ellipse2D.java
341 341
			double angle = UtilFunctions.getAngle(init, end);
342 342
			AffineTransform mT = AffineTransform.getRotateInstance(angle, init
343 343
					.getX(), init.getY());
344
			gp = new GeneralPathX(arc);
344
			gp = new GeneralPathX(arc.getPathIterator(null));
345 345
			gp.transform(mT);
346 346

  
347 347
		}
......
411 411
			double angle = UtilFunctions.getAngle(init, end);
412 412
			AffineTransform mT = AffineTransform.getRotateInstance(angle, init
413 413
					.getX(), init.getY());
414
			gp = new GeneralPathX(arc);
414
			gp = new GeneralPathX(arc.getPathIterator(null));
415 415
			gp.transform(mT);
416 416

  
417 417
		}
......
476 476
			double angle = UtilFunctions.getAngle(init, end);
477 477
			AffineTransform mT = AffineTransform.getRotateInstance(angle, init
478 478
					.getX(), init.getY());
479
			gp = new GeneralPathX(arc);
479
			gp = new GeneralPathX(arc.getPathIterator(null));
480 480
			gp.transform(mT);
481 481
		}
482 482
	}
......
520 520
		double angle = UtilFunctions.getAngle(axis1Start, axis1End);
521 521
		AffineTransform mT = AffineTransform.getRotateInstance(angle,
522 522
				axis1Start.getX(), axis1Start.getY());
523
		GeneralPathX gp = new GeneralPathX(arc);
523
		GeneralPathX gp = new GeneralPathX(arc.getPathIterator(null));
524 524
		gp.transform(mT);
525
		this.gp = new GeneralPathX(gp);
525
		this.gp = new GeneralPathX(gp.getPathIterator(null));
526 526
		this.init = axis1Start;
527 527
		this.end = axis1End;
528 528
		this.ydist = axis2Length;		
branches/v2_0_0_prep/libraries/libFMap_geometries/src/org/gvsig/fmap/geom/primitive/impl/Circle2D.java
261 261
			Arc2D.Double arc = new Arc2D.Double(center.getX() - radio, center
262 262
					.getY()
263 263
					- radio, 2 * radio, 2 * radio, 0, 360, Arc2D.OPEN);
264
			gp = new GeneralPathX(arc);
264
			gp = new GeneralPathX(arc.getPathIterator(null));
265 265

  
266 266
		}
267 267
	}
......
310 310
			Arc2D.Double arc = new Arc2D.Double(center.getX() - radio, center
311 311
					.getY()
312 312
					- radio, 2 * radio, 2 * radio, 0, 360, Arc2D.OPEN);
313
			gp = new GeneralPathX(arc);
313
			gp = new GeneralPathX(arc.getPathIterator(null));
314 314
		}
315 315
	}
316 316

  
......
350 350
			new java.awt.geom.Arc2D.Double(center.getX() - radious, _center
351 351
				.getY()
352 352
				- radious, 2 * radious, 2 * radious, 0, 360, Arc2D.OPEN);
353
		this.gp = new GeneralPathX(arc);
353
		this.gp = new GeneralPathX(arc.getPathIterator(null));
354 354
		this.center = _center;
355 355
		this.radio = radious;	
356 356
	}
......
384 384
			new java.awt.geom.Arc2D.Double(center.getX() - radious, center
385 385
				.getY()
386 386
				- radious, 2 * radious, 2 * radious, 0, 360, Arc2D.OPEN);
387
		this.gp = new GeneralPathX(arc);
387
		this.gp = new GeneralPathX(arc.getPathIterator(null));
388 388
		this.center = center;
389 389
		this.radio = radious;	
390 390
		
branches/v2_0_0_prep/libraries/libFMap_geometries/src/org/gvsig/fmap/geom/primitive/impl/Arc2D.java
215 215
		public void set(double x, double y) {
216 216
			center=new Point2D.Double(x,y);
217 217
			java.awt.geom.Arc2D arco = UtilFunctions.createArc(init, center, end);
218
			gp = new GeneralPathX(arco);
218
			gp = new GeneralPathX(arco.getPathIterator(null));
219 219
		}
220 220
	}
221 221

  
......
258 258
			center=UtilFunctions.getPoint(mediop,perp[1],dist);
259 259

  
260 260
			java.awt.geom.Arc2D arco = UtilFunctions.createArc(init,center, end);
261
			gp=new GeneralPathX(arco);
261
			gp=new GeneralPathX(arco.getPathIterator(null));
262 262
		}
263 263
		public void setPoint(Point2D p){
264 264
			init=p;
......
313 313
			center=UtilFunctions.getPoint(mediop,perp[1],dist);
314 314

  
315 315
			java.awt.geom.Arc2D arco = UtilFunctions.createArc(init,center, end);
316
			gp=new GeneralPathX(arco);
316
			gp=new GeneralPathX(arco.getPathIterator(null));
317 317
		}
318 318
		public void setPoint(Point2D p){
319 319
			end=p;
......
369 369
			center=UtilFunctions.getPoint(mediop,perp[1],dist);
370 370

  
371 371
			java.awt.geom.Arc2D arco = UtilFunctions.createArc(init,center, end);
372
			gp=new GeneralPathX(arco);
372
			gp=new GeneralPathX(arco.getPathIterator(null));
373 373
		}
374 374
		public void setPoint(Point2D p){
375 375
			init=p;
......
393 393
			}
394 394
			///center=TrigonometricalFunctions.getPoint(mediop,perp[1],dist);
395 395
			java.awt.geom.Arc2D arco = UtilFunctions.createArc(init,center, end);
396
			gp=new GeneralPathX(arco);
396
			gp=new GeneralPathX(arco.getPathIterator(null));
397 397
		}
398 398
	}
399 399

  
......
436 436
			center=UtilFunctions.getPoint(mediop,perp[1],dist);
437 437

  
438 438
			java.awt.geom.Arc2D arco = UtilFunctions.createArc(init,center, end);
439
			gp=new GeneralPathX(arco);
439
			gp=new GeneralPathX(arco.getPathIterator(null));
440 440
		}
441 441
		public void setPoint(Point2D p){
442 442
			end=p;
......
460 460
			}
461 461
			///center=TrigonometricalFunctions.getPoint(mediop,perp[1],dist);
462 462
			java.awt.geom.Arc2D arco = UtilFunctions.createArc(init,center, end);
463
			gp=new GeneralPathX(arco);
463
			gp=new GeneralPathX(arco.getPathIterator(null));
464 464
		}
465 465
	}
466 466

  
......
496 496
		if (arco == null) {
497 497
			throw new IllegalArgumentException();
498 498
		}
499
		this.gp = new GeneralPathX(arco);
499
		this.gp = new GeneralPathX(arco.getPathIterator(null));
500 500
		this.center = p1;
501 501
		this.init = p2;
502 502
		this.end = p3;
branches/v2_0_0_prep/libraries/libFMap_geometries/src/org/gvsig/fmap/geom/primitive/impl/AbstractPrimitive.java
12 12
import org.gvsig.fmap.geom.GeometryLocator;
13 13
import org.gvsig.fmap.geom.GeometryManager;
14 14
import org.gvsig.fmap.geom.handler.Handler;
15
import org.gvsig.fmap.geom.operation.GeometryOperation;
15 16
import org.gvsig.fmap.geom.operation.GeometryOperationContext;
16 17
import org.gvsig.fmap.geom.operation.GeometryOperationException;
17 18
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException;
19
import org.gvsig.fmap.geom.operation.relationship.DefaultRelationshipGeometryOperationContext;
20
import org.gvsig.fmap.geom.primitive.Envelope;
18 21
import org.gvsig.fmap.geom.primitive.FShape;
19 22
import org.gvsig.fmap.geom.primitive.GeneralPathX;
20 23
import org.gvsig.fmap.geom.primitive.Primitive;
21 24
import org.gvsig.fmap.geom.type.GeometryType;
25
import org.slf4j.Logger;
26
import org.slf4j.LoggerFactory;
22 27

  
23 28

  
24 29
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
......
77 82
 * @author Jorge Piera Llodr? (jorge.piera@iver.es)
78 83
 */
79 84
public abstract class AbstractPrimitive implements Primitive, FShape, Serializable {
85
	
86
	private static final Logger logger = LoggerFactory.getLogger(GeometryManager.class);
87

  
80 88
	private static final long serialVersionUID = -4334977368955260872L;
81 89
	protected String id = null;
82 90
	protected IProjection projection = null;
......
197 205
	 * @see org.gvsig.fmap.geom.Geometry#fastIntersects(double, double, double, double)
198 206
	 */
199 207
	public boolean fastIntersects(double x, double y, double w, double h) {
200
		return intersects(x,y,w,h);
208

  
209
		boolean resp = true;
210
		
211
		try {
212
			resp = intersectsRectangle(this, x, y, w, h);
213
		} catch (GeometryOperationException e) {
214
			logger.error("While doing fastintersects: " + e.getMessage(), e);
215
		}
216
		
217
		return resp;
201 218
	}
202 219

  
203 220
	/*
......
414 431
	}
415 432
	
416 433
	
434
	
435
	
436
	
437
	
438
	
439
	
440
	/**
441
	 * Utility method
442
	 * @param geometry
443
	 * @param x
444
	 * @param y
445
	 * @return
446
	 * @throws GeometryOperationException
447
	 */
448
	protected boolean containsPoint(Geometry geom, double x, double y) throws GeometryOperationException {
449
		
450
		// exclude disjoint 
451
		Envelope env = geom.getEnvelope();
452
		if (x > env.getMaximum(0)) return false; 
453
		if (y > env.getMaximum(1)) return false; 
454
		if (x < env.getMinimum(0)) return false; 
455
		if (y < env.getMinimum(1)) return false; 
456
		
457
		// boxes overlap, need long version
458
		
459
		Geometry geompoint = null;
460
		try {
461
			geompoint = GeometryLocator.getGeometryManager().createPoint(x, y, SUBTYPES.GEOM2D);
462
		} catch (Exception e1) {
463
			throw new GeometryOperationException(geom.getType(), GeometryOperation.OPERATION_CONTAINS_CODE, e1);
464
		}
465
		
466
		DefaultRelationshipGeometryOperationContext drgoc =
467
			new DefaultRelationshipGeometryOperationContext(geompoint);
468
		
469
		Object resp = null;
470
		boolean respboolean = true;
471
		try {
472
			resp = geom.invokeOperation(GeometryOperation.OPERATION_CONTAINS_CODE, drgoc);
473
			respboolean = ((Boolean) resp).booleanValue();
474
		} catch (Exception e) {
475
			throw new GeometryOperationException(geom.getType(), GeometryOperation.OPERATION_CONTAINS_CODE, e);
476
		}
477

  
478
		return respboolean;
479
	}
480

  
481
	/**
482
	 * 
483
	 * @param geometry
484
	 * @param x
485
	 * @param y
486
	 * @param w
487
	 * @param h
488
	 * @return
489
	 */
490
	protected boolean containsRectangle(Geometry geom, double x, double y,
491
			double w, double h) throws GeometryOperationException {
492
		
493
		
494
		// exclude disjoint boxes
495
		Envelope env = geom.getEnvelope();
496
		if (x > env.getMaximum(0)) return false; 
497
		if ((x+w) < env.getMinimum(0)) return false; 
498
		if (y > env.getMaximum(1)) return false; 
499
		if ((y+h) < env.getMinimum(1)) return false; 
500
		
501
		if (w == 0 && h == 0) {
502
			return  containsPoint(geom, x, y); 
503
		}
504
		
505
		// boxes overlap, need long version
506
		Geometry rectgeom = null;
507
		GeneralPathX gpx = new GeneralPathX();
508
		gpx.moveTo(x, y);
509
		gpx.lineTo(x+w, y);
510
		gpx.lineTo(x+w, y+h);
511
		gpx.lineTo(x, y+h);
512
		gpx.lineTo(x, y);
513
		
514
		try {
515
			rectgeom = GeometryLocator.getGeometryManager().createSurface(gpx, SUBTYPES.GEOM2D);
516
		} catch (Exception e1) {
517
			throw new GeometryOperationException(geom.getType(), GeometryOperation.OPERATION_CONTAINS_CODE, e1);
518
		}
519
		
520
		DefaultRelationshipGeometryOperationContext drgoc =
521
			new DefaultRelationshipGeometryOperationContext(rectgeom);
522
		
523
		Object resp = null;
524
		boolean respboolean = true;
525
		try {
526
			resp = geom.invokeOperation(GeometryOperation.OPERATION_CONTAINS_CODE, drgoc);
527
			respboolean = ((Boolean) resp).booleanValue();
528
		} catch (Exception e) {
529
			throw new GeometryOperationException(geom.getType(), GeometryOperation.OPERATION_CONTAINS_CODE, e);
530
		}
531

  
532
		return respboolean;
533
	}
534
	
535

  
536
	/**
537
	 * 
538
	 * @param geom
539
	 * @param x
540
	 * @param y
541
	 * @param w
542
	 * @param h
543
	 * @return
544
	 */
545
	protected boolean intersectsRectangle(Geometry geom, double x, double y,
546
			double w, double h) throws GeometryOperationException {
547
		
548
		// exclude disjoint boxes
549
		Envelope env = geom.getEnvelope();
550
		if (x > env.getMaximum(0)) return false; 
551
		if ((x+w) < env.getMinimum(0)) return false; 
552
		if (y > env.getMaximum(1)) return false; 
553
		if ((y+h) < env.getMinimum(1)) return false; 
554
		
555
		// boxes overlap, need long version
556
		Geometry rectgeom = null;
557
		GeneralPathX gpx = new GeneralPathX();
558
		gpx.moveTo(x, y);
559
		gpx.lineTo(x+w, y);
560
		gpx.lineTo(x+w, y+h);
561
		gpx.lineTo(x, y+h);
562
		gpx.lineTo(x, y);
563
		
564
		try {
565
			rectgeom = GeometryLocator.getGeometryManager().createSurface(gpx, SUBTYPES.GEOM2D);
566
		} catch (Exception e1) {
567
			throw new GeometryOperationException(geom.getType(), GeometryOperation.OPERATION_INTERSECTS_CODE, e1);
568
		}
569
		
570
		DefaultRelationshipGeometryOperationContext drgoc =
571
			new DefaultRelationshipGeometryOperationContext(rectgeom);
572
		
573
		Object resp = null;
574
		boolean respboolean = true;
575
		try {
576
			resp = geom.invokeOperation(GeometryOperation.OPERATION_INTERSECTS_CODE, drgoc);
577
			respboolean = ((Boolean) resp).booleanValue();
578
		} catch (Exception e) {
579
			throw new GeometryOperationException(geom.getType(), GeometryOperation.OPERATION_INTERSECTS_CODE, e);
580
		}
581

  
582
		return respboolean;
583

  
584

  
585
	}
586

  
587
	
588
	
417 589
}
branches/v2_0_0_prep/libraries/libFMap_geometries/src/org/gvsig/fmap/geom/primitive/GeneralPathX.java
206 206
     * taken from the specified <code>Shape</code> object.
207 207
     * @param s the specified <code>Shape</code> object
208 208
     */
209
    public GeneralPathX(Shape s) {
209
    public GeneralPathX(PathIterator piter) { // Shape s) {
210 210
	// this(WIND_NON_ZERO, INIT_SIZE, INIT_SIZE);
211 211
    	this(WIND_EVEN_ODD, INIT_SIZE, INIT_SIZE);
212
	PathIterator pi = s.getPathIterator(null);
213
	setWindingRule(pi.getWindingRule());
214
	append(pi, false);
212
	// PathIterator pi = s.getPathIterator(null);
213
	setWindingRule(piter.getWindingRule());
214
	append(piter, false);
215 215
    }
216 216

  
217 217
    private void needRoom(int newTypes, int newCoords, boolean needMove) {
......
412 412
     * initial <code>moveTo</code> segment into a <code>lineTo</code>
413 413
     * segment to connect the new geometry to the existing path
414 414
     */
415
    /*
415 416
    public void append(Shape s, boolean connect) {
416 417
	PathIterator pi = s.getPathIterator(null);
417 418
        append(pi,connect);
418 419
    }
420
    */
419 421

  
420 422
    /**
421 423
     * Appends the geometry of the specified
......
900 902
			}
901 903
		}
902 904
		reset();
903
		append(newGp, false);
905
		append(newGp.getPathIterator(null), false);
904 906
	}
905 907
    /**
906 908
     * Check if the first part is CCW.
branches/v2_0_0_prep/libraries/libFMap_geometries/src/org/gvsig/fmap/geom/util/Converter.java
61 61
import org.gvsig.fmap.geom.exception.CreateGeometryException;
62 62
import org.gvsig.fmap.geom.primitive.GeneralPathX;
63 63
import org.gvsig.fmap.geom.primitive.Surface;
64
import org.gvsig.fmap.geom.primitive.impl.Point2D;
65 64
import org.slf4j.Logger;
66 65
import org.slf4j.LoggerFactory;
67 66

  
......
810 809

  
811 810
		for (int i = 0; i < mls.getNumGeometries(); i++) {
812 811
			LineString lineString = (LineString) mls.getGeometryN(i);
813
			path.append(toShape(lineString), false);
812
			path.append(toShape(lineString).getPathIterator(null), false);
814 813
		}
815 814

  
816 815
		//BasicFeatureRenderer expects LineStrings and MultiLineStrings to be
......
870 869

  
871 870
	for (int i = 0; i < mp.getNumGeometries(); i++) {
872 871
		Polygon polygon = (Polygon) mp.getGeometryN(i);
873
		path.append(toShape(polygon), false);
872
		path.append(toShape(polygon).getPathIterator(null), false);
874 873
	}
875 874

  
876 875
	//BasicFeatureRenderer expects LineStrings and MultiLineStrings to be
branches/v2_0_0_prep/libraries/libFMap_geometries/src/org/gvsig/fmap/geom/operation/GeometryOperation.java
1 1
package org.gvsig.fmap.geom.operation;
2 2

  
3 3
import org.gvsig.fmap.geom.Geometry;
4
import org.gvsig.fmap.geom.GeometryLocator;
4 5

  
5 6
/**
6 7
 * Every geometry operation that is registered dynamically must extend this class.<br>
......
31 32
 */
32 33
public abstract class GeometryOperation {
33 34
	
35
	
36
	// Constants for well-known operations to avoid dependency between geometry model and
37
	// operations.
38
	public static final String OPERATION_INTERSECTS_NAME = "intersects";
39
	public static final String OPERATION_CONTAINS_NAME = "contains";
40
	
41
	public static int OPERATION_INTERSECTS_CODE =
42
		GeometryLocator.getGeometryManager().getGeometryOperationCode(OPERATION_INTERSECTS_NAME);;
43
	public static int OPERATION_CONTAINS_CODE =
44
		GeometryLocator.getGeometryManager().getGeometryOperationCode(OPERATION_CONTAINS_NAME);;
45
	
46
	
47
	
48
	
49
	
50
	
34 51
	/**
35 52
	 * Invokes this operation given the geometry and context 
36 53
	 * @param geom Geometry to which apply this operation
branches/v2_0_0_prep/libraries/libFMap_geometries/src/org/gvsig/fmap/geom/operation/flip/Flip.java
81 81
    		}
82 82
    	}
83 83
    	generalPathX.reset();
84
    	generalPathX.append(newGp, false);	
84
    	generalPathX.append(newGp.getPathIterator(null), false);	
85 85
    	
86 86
		return null;		
87 87
	}
branches/v2_0_0_prep/libraries/libFMap_geometries/src/org/gvsig/fmap/geom/impl/Geometry2D.java
36 36

  
37 37
import org.cresques.cts.ICoordTrans;
38 38
import org.gvsig.fmap.geom.Geometry;
39
import org.gvsig.fmap.geom.GeometryLocator;
40
import org.gvsig.fmap.geom.GeometryManager;
41
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
39 42
import org.gvsig.fmap.geom.handler.Handler;
43
import org.gvsig.fmap.geom.operation.GeometryOperation;
40 44
import org.gvsig.fmap.geom.operation.GeometryOperationContext;
41 45
import org.gvsig.fmap.geom.operation.GeometryOperationException;
42 46
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException;
47
import org.gvsig.fmap.geom.operation.relationship.DefaultRelationshipGeometryOperationContext;
43 48
import org.gvsig.fmap.geom.primitive.Envelope;
44
import org.gvsig.fmap.geom.primitive.FShape;
45 49
import org.gvsig.fmap.geom.primitive.GeneralPathX;
46
import org.gvsig.fmap.geom.primitive.Primitive;
47 50
import org.gvsig.fmap.geom.type.GeometryType;
51
import org.slf4j.Logger;
52
import org.slf4j.LoggerFactory;
48 53

  
49 54
/**
50 55
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
51 56
 */
52 57
public class Geometry2D implements Geometry{
58
	
59
	private static final Logger logger = LoggerFactory.getLogger(GeometryManager.class);
60
	
53 61
	private Geometry geometry = null;
54 62
		
55 63
	/**
......
194 202
	 * @see java.awt.Shape#contains(java.awt.geom.Point2D)
195 203
	 */
196 204
	public boolean contains(Point2D p) {
197
		return geometry.contains(p);
205
		
206
		
207
		
208
		try {
209
			return containsPoint(geometry, p.getX(), p.getY());
210
		} catch (GeometryOperationException e) {
211
			logger.error("While doing contains: " + e.getMessage(), e);
212
			return true;
213
		}
198 214
	}
199 215

  
200 216
	/* (non-Javadoc)
201 217
	 * @see java.awt.Shape#contains(java.awt.geom.Rectangle2D)
202 218
	 */
203 219
	public boolean contains(Rectangle2D r) {
204
		return geometry.contains(r);
220
		try {
221
			return containsRectangle(geometry,
222
					r.getMinX(),
223
					r.getMinY(),
224
					r.getWidth(),
225
					r.getHeight());
226
		} catch (GeometryOperationException e) {
227
			logger.error("While doing contains: " + e.getMessage(), e);
228
			return true;
229
		}
205 230
	}
206 231

  
207 232
	/* (non-Javadoc)
208 233
	 * @see java.awt.Shape#contains(double, double)
209 234
	 */
210 235
	public boolean contains(double x, double y) {
211
		return geometry.contains(x, y);
236
		try {
237
			return containsPoint(geometry, x, y);
238
		} catch (GeometryOperationException e) {
239
			logger.error("While doing contains: " + e.getMessage(), e);
240
			return true;
241
		}
212 242
	}
213 243

  
214 244
	/* (non-Javadoc)
215 245
	 * @see java.awt.Shape#contains(double, double, double, double)
216 246
	 */
217 247
	public boolean contains(double x, double y, double w, double h) {
218
		return geometry.contains(x, y, w, h);
248
		try {
249
			return containsRectangle(geometry, x, y, w, h);
250
		} catch (GeometryOperationException e) {
251
			logger.error("While doing contains: " + e.getMessage(), e);
252
			return true;
253
		}
219 254
	}
220 255

  
221 256
	/* (non-Javadoc)
......
229 264
	 * @see java.awt.Shape#intersects(double, double, double, double)
230 265
	 */
231 266
	public boolean intersects(double x, double y, double w, double h) {
232
		return geometry.intersects(x, y, w, h);
267
		try {
268
			return intersectsRectangle(geometry, x, y, w, h);
269
		} catch (GeometryOperationException e) {
270
			logger.error("While doing intersects: " + e.getMessage(), e);
271
			return true;
272
		}
233 273
	}
234 274

  
235 275
	/* (non-Javadoc)
......
239 279
		return geometry.compareTo(arg0);
240 280
	}
241 281
	
282
	
283
	
284
	
285
	
286
	
287
	
288
	
289
	
290
	/**
291
	 * Utility method
292
	 * @param geometry
293
	 * @param x
294
	 * @param y
295
	 * @return
296
	 * @throws GeometryOperationException
297
	 */
298
	protected boolean containsPoint(Geometry geom, double x, double y) throws GeometryOperationException {
299
		
300
		// exclude disjoint 
301
		Envelope env = geom.getEnvelope();
302
		if (x > env.getMaximum(0)) return false; 
303
		if (y > env.getMaximum(1)) return false; 
304
		if (x < env.getMinimum(0)) return false; 
305
		if (y < env.getMinimum(1)) return false; 
306
		
307
		// boxes overlap, need long version
308
		
309
		Geometry geompoint = null;
310
		try {
311
			geompoint = GeometryLocator.getGeometryManager().createPoint(x, y, SUBTYPES.GEOM2D);
312
		} catch (Exception e1) {
313
			throw new GeometryOperationException(geom.getType(), GeometryOperation.OPERATION_CONTAINS_CODE, e1);
314
		}
315
		
316
		DefaultRelationshipGeometryOperationContext drgoc =
317
			new DefaultRelationshipGeometryOperationContext(geompoint);
318
		
319
		Object resp = null;
320
		boolean respboolean = true;
321
		try {
322
			resp = geom.invokeOperation(GeometryOperation.OPERATION_CONTAINS_CODE, drgoc);
323
			respboolean = ((Boolean) resp).booleanValue();
324
		} catch (Exception e) {
325
			throw new GeometryOperationException(geom.getType(), GeometryOperation.OPERATION_CONTAINS_CODE, e);
326
		}
242 327

  
328
		return respboolean;
329
	}
330

  
331
	/**
332
	 * 
333
	 * @param geometry
334
	 * @param x
335
	 * @param y
336
	 * @param w
337
	 * @param h
338
	 * @return
339
	 */
340
	protected boolean containsRectangle(Geometry geom, double x, double y,
341
			double w, double h) throws GeometryOperationException {
342
		
343
		
344
		// exclude disjoint boxes
345
		Envelope env = geom.getEnvelope();
346
		if (x > env.getMaximum(0)) return false; 
347
		if ((x+w) < env.getMinimum(0)) return false; 
348
		if (y > env.getMaximum(1)) return false; 
349
		if ((y+h) < env.getMinimum(1)) return false; 
350
		
351
		if (w == 0 && h == 0) {
352
			return  containsPoint(geom, x, y); 
353
		}
354
		
355
		// boxes overlap, need long version
356
		Geometry rectgeom = null;
357
		GeneralPathX gpx = new GeneralPathX();
358
		gpx.moveTo(x, y);
359
		gpx.lineTo(x+w, y);
360
		gpx.lineTo(x+w, y+h);
361
		gpx.lineTo(x, y+h);
362
		gpx.lineTo(x, y);
363
		
364
		try {
365
			rectgeom = GeometryLocator.getGeometryManager().createSurface(gpx, SUBTYPES.GEOM2D);
366
		} catch (Exception e1) {
367
			throw new GeometryOperationException(geom.getType(), GeometryOperation.OPERATION_CONTAINS_CODE, e1);
368
		}
369
		
370
		DefaultRelationshipGeometryOperationContext drgoc =
371
			new DefaultRelationshipGeometryOperationContext(rectgeom);
372
		
373
		Object resp = null;
374
		boolean respboolean = true;
375
		try {
376
			resp = geom.invokeOperation(GeometryOperation.OPERATION_CONTAINS_CODE, drgoc);
377
			respboolean = ((Boolean) resp).booleanValue();
378
		} catch (Exception e) {
379
			throw new GeometryOperationException(geom.getType(), GeometryOperation.OPERATION_CONTAINS_CODE, e);
380
		}
381

  
382
		return respboolean;
383
	}
384
	
385

  
386
	/**
387
	 * 
388
	 * @param geom
389
	 * @param x
390
	 * @param y
391
	 * @param w
392
	 * @param h
393
	 * @return
394
	 */
395
	protected boolean intersectsRectangle(Geometry geom, double x, double y,
396
			double w, double h) throws GeometryOperationException {
397
		
398
		// exclude disjoint boxes
399
		Envelope env = geom.getEnvelope();
400
		if (x > env.getMaximum(0)) return false; 
401
		if ((x+w) < env.getMinimum(0)) return false; 
402
		if (y > env.getMaximum(1)) return false; 
403
		if ((y+h) < env.getMinimum(1)) return false; 
404
		
405
		// boxes overlap, need long version
406
		Geometry rectgeom = null;
407
		GeneralPathX gpx = new GeneralPathX();
408
		gpx.moveTo(x, y);
409
		gpx.lineTo(x+w, y);
410
		gpx.lineTo(x+w, y+h);
411
		gpx.lineTo(x, y+h);
412
		gpx.lineTo(x, y);
413
		
414
		try {
415
			rectgeom = GeometryLocator.getGeometryManager().createSurface(gpx, SUBTYPES.GEOM2D);
416
		} catch (Exception e1) {
417
			throw new GeometryOperationException(geom.getType(), GeometryOperation.OPERATION_INTERSECTS_CODE, e1);
418
		}
419
		
420
		DefaultRelationshipGeometryOperationContext drgoc =
421
			new DefaultRelationshipGeometryOperationContext(rectgeom);
422
		
423
		Object resp = null;
424
		boolean respboolean = true;
425
		try {
426
			resp = geom.invokeOperation(GeometryOperation.OPERATION_INTERSECTS_CODE, drgoc);
427
			respboolean = ((Boolean) resp).booleanValue();
428
		} catch (Exception e) {
429
			throw new GeometryOperationException(geom.getType(), GeometryOperation.OPERATION_INTERSECTS_CODE, e);
430
		}
431

  
432
		return respboolean;
433

  
434

  
435
	}
436

  
243 437
}
244 438

  
branches/v2_0_0_prep/libraries/libFMap_geometries/pom.xml
158 158
						<artifactId>maven-compiler-plugin</artifactId>
159 159
						<configuration>
160 160
							<excludes>
161
								<exclude>**/operation/*/*</exclude>
161
								<exclude>**/operation/fromwkb/*</exclude>
162
								<exclude>**/operation/impl/*</exclude>
162 163
							</excludes>
164

  
163 165
							<testExcludes>
164
								<exclude>**/operation/*/*</exclude>
166
								<exclude>**/**</exclude>
165 167
							</testExcludes>
168

  
166 169
						</configuration>
167 170
					</plugin>
168 171
					<plugin>
......
173 176
						<groupId>org.apache.maven.plugins</groupId>
174 177
						<artifactId>maven-jar-plugin</artifactId>
175 178
						<configuration>
179

  
180
							<includes>
181
								<include>**/**</include>
182
							</includes>
176 183
							<excludes>
177
								<exclude>**/operation/*/*</exclude>
178
								<exclude>**/impl/**</exclude>
184
								<exclude>**/operation/distance/*</exclude>
185
								<exclude>**/operation/ensureOrientation/*</exclude>
186
								<exclude>**/operation/flip/*</exclude>
187
								<exclude>**/operation/fromwkb/*</exclude>
188
								<exclude>**/operation/fromwkt/*</exclude>
189
								<exclude>**/operation/impl/*</exclude>
190
								<exclude>**/operation/isCCW/*</exclude>
191
								<exclude>**/operation/relationship/*</exclude>
192
								<exclude>**/operation/tojts/*</exclude>
193
								<exclude>**/operation/towkb/*</exclude>
194
								<exclude>**/operation/towkt/*</exclude>
195
								<exclude>**/operation/utils/*</exclude>
196
								<!--  <exclude>**/impl/**</exclude> -->
179 197
							</excludes>
180 198
						</configuration>
181 199
						<executions>
......
187 205
								</goals>
188 206
								<configuration>
189 207
									<classifier>impl</classifier>
208
									<includes>
209
										<include>**/impl/**</include>
210
									</includes>
190 211
									<excludes>
191 212
										<exclude>**/operation/impl/**</exclude>
192 213
									</excludes>
193
									<includes>
194
										<include>**/impl/**</include>
195
									</includes>
196 214
								</configuration>
197 215
							</execution>
216
							
198 217
							<execution>
199 218
								<id>operation</id>
200 219
								<phase>package</phase>
......
203 222
								</goals>
204 223
								<configuration>
205 224
									<classifier>operation</classifier>
206
									<excludes>
207
										<exclude>**/operation/fromwkb/**</exclude>
208
									</excludes>
209 225
									<includes>
210 226
										<include>**/operation/*/*</include>
211 227
									</includes>
228
									<excludes>
229
										<exclude>**/operation/fromwkb/*</exclude>
230
									</excludes>
212 231
								</configuration>
213 232
							</execution>
233
							
214 234
						</executions>
215 235
					</plugin>
216 236
				</plugins>

Also available in: Unified diff