1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17 package org.apache.commons.geometry.euclidean.twod;
18
19 import java.text.MessageFormat;
20
21 import org.apache.commons.geometry.core.RegionLocation;
22 import org.apache.commons.geometry.core.Transform;
23 import org.apache.commons.geometry.core.partitioning.Split;
24
25 /** Class representing the span of a line in 2D Euclidean space. This is the set of all points
26 * contained by the line.
27 *
28 * <p>Instances of this class are guaranteed to be immutable.</p>
29 */
30 final class LineSpanningSubset extends LineConvexSubset {
31
32 /** Construct a new instance for the given line.
33 * @param line line to construct the span for
34 */
35 LineSpanningSubset(final Line line) {
36 super(line);
37 }
38
39 /** {@inheritDoc}
40 *
41 * <p>This method always returns {@code true}.</p>
42 */
43 @Override
44 public boolean isFull() {
45 return true;
46 }
47
48 /** {@inheritDoc}
49 *
50 * <p>This method always returns {@code true}.</p>
51 */
52 @Override
53 public boolean isInfinite() {
54 return true;
55 }
56
57 /** {@inheritDoc}
58 *
59 * <p>This method always returns {@code false}.</p>
60 */
61 @Override
62 public boolean isFinite() {
63 return false;
64 }
65
66 /** {@inheritDoc}
67 *
68 * <p>This method always returns {@link Double#POSITIVE_INFINITY}.</p>
69 */
70 @Override
71 public double getSize() {
72 return Double.POSITIVE_INFINITY;
73 }
74
75 /** {@inheritDoc}
76 *
77 * <p>This method always returns {@code null}.</p>
78 */
79 @Override
80 public Vector2D getCentroid() {
81 return null;
82 }
83
84 /** {@inheritDoc}
85 *
86 * <p>This method always returns {@code null}.</p>
87 */
88 @Override
89 public Vector2D getStartPoint() {
90 return null;
91 }
92
93 /** {@inheritDoc}
94 *
95 * <p>This method always returns {@link Double#NEGATIVE_INFINITY}.</p>
96 */
97 @Override
98 public double getSubspaceStart() {
99 return Double.NEGATIVE_INFINITY;
100 }
101
102 /** {@inheritDoc}
103 *
104 * <p>This method always returns {@code null}.</p>
105 */
106 @Override
107 public Vector2D getEndPoint() {
108 return null;
109 }
110
111 /** {@inheritDoc}
112 *
113 * <p>This method always returns {@link Double#POSITIVE_INFINITY}.</p>
114 */
115 @Override
116 public double getSubspaceEnd() {
117 return Double.POSITIVE_INFINITY;
118 }
119
120 /** {@inheritDoc}
121 *
122 * <p>This method always returns {@code null}.</p>
123 */
124 @Override
125 public Bounds2D getBounds() {
126 return null; // infinite; no bounds
127 }
128
129 /** {@inheritDoc} */
130 @Override
131 public LineSpanningSubset transform(final Transform<Vector2D> transform) {
132 return new LineSpanningSubset(getLine().transform(transform));
133 }
134
135 /** {@inheritDoc} */
136 @Override
137 public LineSpanningSubset reverse() {
138 return new LineSpanningSubset(getLine().reverse());
139 }
140
141 /** {@inheritDoc} */
142 @Override
143 public String toString() {
144 final Line line = getLine();
145
146 return MessageFormat.format(Line.TO_STRING_FORMAT,
147 getClass().getSimpleName(),
148 line.getOrigin(),
149 line.getDirection());
150 }
151
152 /** {@inheritDoc} */
153 @Override
154 RegionLocation classifyAbscissa(final double abscissa) {
155 return RegionLocation.INSIDE;
156 }
157
158 /** {@inheritDoc} */
159 @Override
160 double closestAbscissa(final double abscissa) {
161 return abscissa;
162 }
163
164 /** {@inheritDoc} */
165 @Override
166 Split<LineConvexSubset> splitOnIntersection(final Line splitter, final Vector2D intersection) {
167 final Line line = getLine();
168
169 final ReverseRay low = new ReverseRay(line, intersection);
170 final Ray high = new Ray(line, intersection);
171
172 return createSplitResult(splitter, low, high);
173 }
174 }