Class SweepLineEvent

 1  
 2  
 3  
 4 /*
 5  * Copyright (c) 2016 Vivid Solutions.
 6  *
 7  * All rights reserved. This program and the accompanying materials
 8  * are made available under the terms of the Eclipse Public License 2.0
 9  * and Eclipse Distribution License v. 1.0 which accompanies this distribution.
10  * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v20.html
11  * and the Eclipse Distribution License is available at
12  *
13  * http://www.eclipse.org/org/documents/edl-v10.php.
14  */
15 package org.locationtech.jts.index.sweepline;
16  
17 /**
18  * @version 1.7
19  */
20 public class SweepLineEvent
21   implements Comparable
22 {
23   public static final int INSERT = 1;
24   public static final int DELETE = 2;
25  
26   private double xValue;
27   private int eventType;
28   private SweepLineEvent insertEvent// null if this is an INSERT event
29   private int deleteEventIndex;
30  
31   SweepLineInterval sweepInt;
32   public SweepLineEvent(double x, SweepLineEvent insertEvent, SweepLineInterval sweepInt)
33   {
34     xValue = x;
35     this.insertEvent = insertEvent;
36     this.eventType = INSERT;
37     if (insertEvent != null)
38       eventType = DELETE;
39     this.sweepInt = sweepInt;
40   }
41  
42   public boolean isInsert() { return insertEvent == null; }
43   public boolean isDelete() { return insertEvent != null; }
44   public SweepLineEvent getInsertEvent() { return insertEvent; }
45   public int getDeleteEventIndex() { return deleteEventIndex; }
46   public void setDeleteEventIndex(int deleteEventIndex) { this.deleteEventIndex = deleteEventIndex; }
47  
48   SweepLineInterval getInterval() { return sweepInt; }
49  
50   /**
51    * ProjectionEvents are ordered first by their x-value, and then by their eventType.
52    * It is important that Insert events are sorted before Delete events, so that
53    * items whose Insert and Delete events occur at the same x-value will be
54    * correctly handled.
55    */
56   public int compareTo(Object o) {
57     SweepLineEvent pe = (SweepLineEvent) o;
58     if (xValue < pe.xValue) return  -1;
59     if (xValue > pe.xValue) return   1;
60     if (eventType < pe.eventType) return  -1;
61     if (eventType > pe.eventType) return   1;
62     return 0;
63   }
64  
65  
66 }
67