• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2011 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.google.common.geometry;
18 
19 /**
20  * An abstract directed edge from one S2Point to another S2Point.
21  *
22  * @author kirilll@google.com (Kirill Levin)
23  */
24 public final class S2Edge {
25 
26   private final S2Point start;
27   private final S2Point end;
28 
S2Edge(S2Point start, S2Point end)29   public S2Edge(S2Point start, S2Point end) {
30     this.start = start;
31     this.end = end;
32   }
33 
getStart()34   public S2Point getStart() {
35     return start;
36   }
37 
getEnd()38   public S2Point getEnd() {
39     return end;
40   }
41 
42   @Override
toString()43   public String toString() {
44     return String.format("Edge: (%s -> %s)\n   or [%s -> %s]",
45         start.toDegreesString(), end.toDegreesString(), start, end);
46   }
47 
48   @Override
hashCode()49   public int hashCode() {
50     return getStart().hashCode() - getEnd().hashCode();
51   }
52 
53   @Override
equals(Object o)54   public boolean equals(Object o) {
55     if (o == null || !(o instanceof S2Edge)) {
56       return false;
57     }
58     S2Edge other = (S2Edge) o;
59     return getStart().equals(other.getStart()) && getEnd().equals(other.getEnd());
60   }
61 }
62