| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
package org.locationtech.jts.edgegraph; |
| 14 |
|
| 15 |
import org.locationtech.jts.geom.Coordinate; |
| 16 |
|
| 17 |
/** |
| 18 |
* A {@link HalfEdge} which supports |
| 19 |
* marking edges with a boolean flag. |
| 20 |
* Useful for algorithms which perform graph traversals. |
| 21 |
* |
| 22 |
* @author Martin Davis |
| 23 |
* |
| 24 |
*/ |
| 25 |
public class MarkHalfEdge extends HalfEdge |
| 26 |
{ |
| 27 |
/** |
| 28 |
* Tests whether the given edge is marked. |
| 29 |
* |
| 30 |
* @param e the edge to test |
| 31 |
* @return true if the edge is marked |
| 32 |
*/ |
| 33 |
public static boolean isMarked(HalfEdge e) |
| 34 |
{ |
| 35 |
return ((MarkHalfEdge) e).isMarked(); |
| 36 |
} |
| 37 |
|
| 38 |
/** |
| 39 |
* Marks the given edge. |
| 40 |
* |
| 41 |
* @param e the edge to mark |
| 42 |
*/ |
| 43 |
public static void mark(HalfEdge e) |
| 44 |
{ |
| 45 |
((MarkHalfEdge) e).mark(); |
| 46 |
} |
| 47 |
|
| 48 |
/** |
| 49 |
* Sets the mark for the given edge to a boolean value. |
| 50 |
* |
| 51 |
* @param e the edge to set |
| 52 |
* @param isMarked the mark value |
| 53 |
*/ |
| 54 |
public static void setMark(HalfEdge e, boolean isMarked) |
| 55 |
{ |
| 56 |
((MarkHalfEdge) e).setMark(isMarked); |
| 57 |
} |
| 58 |
|
| 59 |
/** |
| 60 |
* Sets the mark for the given edge pair to a boolean value. |
| 61 |
* |
| 62 |
* @param e an edge of the pair to update |
| 63 |
* @param isMarked the mark value to set |
| 64 |
*/ |
| 65 |
public static void setMarkBoth(HalfEdge e, boolean isMarked) |
| 66 |
{ |
| 67 |
((MarkHalfEdge) e).setMark(isMarked); |
| 68 |
((MarkHalfEdge) e.sym()).setMark(isMarked); |
| 69 |
} |
| 70 |
|
| 71 |
/** |
| 72 |
* Marks the edges in a pair. |
| 73 |
* |
| 74 |
* @param e an edge of the pair to mark |
| 75 |
*/ |
| 76 |
public static void markBoth(HalfEdge e) { |
| 77 |
((MarkHalfEdge) e).mark(); |
| 78 |
((MarkHalfEdge) e.sym()).mark(); |
| 79 |
} |
| 80 |
|
| 81 |
private boolean isMarked = false; |
| 82 |
|
| 83 |
/** |
| 84 |
* Creates a new marked edge. |
| 85 |
* |
| 86 |
* @param orig the coordinate of the edge origin |
| 87 |
*/ |
| 88 |
public MarkHalfEdge(Coordinate orig) { |
| 89 |
super(orig); |
| 90 |
} |
| 91 |
|
| 92 |
/** |
| 93 |
* Tests whether this edge is marked. |
| 94 |
* |
| 95 |
* @return true if this edge is marked |
| 96 |
*/ |
| 97 |
public boolean isMarked() |
| 98 |
{ |
| 99 |
return isMarked ; |
| 100 |
} |
| 101 |
|
| 102 |
/** |
| 103 |
* Marks this edge. |
| 104 |
* |
| 105 |
*/ |
| 106 |
public void mark() |
| 107 |
{ |
| 108 |
isMarked = true; |
| 109 |
} |
| 110 |
|
| 111 |
/** |
| 112 |
* Sets the value of the mark on this edge. |
| 113 |
* |
| 114 |
* @param isMarked the mark value to set |
| 115 |
*/ |
| 116 |
public void setMark(boolean isMarked) |
| 117 |
{ |
| 118 |
this.isMarked = isMarked; |
| 119 |
} |
| 120 |
|
| 121 |
|
| 122 |
} |
| 123 |
|