Java源码示例:org.apache.commons.math3.geometry.partitioning.Region.Location
示例1
private static String getParamValue(final Parameter p, final String assignedValue, final boolean resolveIntervals) {
if (assignedValue == null) {
throw new IllegalArgumentException("Cannot determine true value for assigned param value " + assignedValue + " for parameter " + p.getName());
}
String interpretedValue = "";
if (p.isNumeric()) {
if (resolveIntervals) {
NumericParameterDomain np = (NumericParameterDomain) p.getDefaultDomain();
List<String> vals = SetUtil.unserializeList(assignedValue);
Interval interval = new Interval(Double.valueOf(vals.get(0)), Double.valueOf(vals.get(1)));
if (np.isInteger()) {
interpretedValue = String.valueOf((int) Math.round(interval.getBarycenter()));
} else {
interpretedValue = String.valueOf(interval.checkPoint((double) p.getDefaultValue(), 0.001) == Location.INSIDE ? (double) p.getDefaultValue() : interval.getBarycenter());
}
} else {
interpretedValue = assignedValue;
}
} else if (p.getDefaultDomain() instanceof CategoricalParameterDomain) {
interpretedValue = assignedValue;
} else {
throw new UnsupportedOperationException("No support for parameters of type " + p.getClass().getName());
}
return interpretedValue;
}
示例2
/** Get the intersection of the instance and another sub-line.
* <p>
* This method is related to the {@link Line#intersection(Line)
* intersection} method in the {@link Line Line} class, but in addition
* to compute the point along infinite lines, it also checks the point
* lies on both sub-line ranges.
* </p>
* @param subLine other sub-line which may intersect instance
* @param includeEndPoints if true, endpoints are considered to belong to
* instance (i.e. they are closed sets) and may be returned, otherwise endpoints
* are considered to not belong to instance (i.e. they are open sets) and intersection
* occurring on endpoints lead to null being returned
* @return the intersection point if there is one, null if the sub-lines don't intersect
*/
public Vector2D intersection(final SubLine subLine, final boolean includeEndPoints) {
// retrieve the underlying lines
Line line1 = (Line) getHyperplane();
Line line2 = (Line) subLine.getHyperplane();
// compute the intersection on infinite line
Vector2D v2D = line1.intersection(line2);
if (v2D == null) {
return null;
}
// check location of point with respect to first sub-line
Location loc1 = getRemainingRegion().checkPoint(line1.toSubSpace(v2D));
// check location of point with respect to second sub-line
Location loc2 = subLine.getRemainingRegion().checkPoint(line2.toSubSpace(v2D));
if (includeEndPoints) {
return ((loc1 != Location.OUTSIDE) && (loc2 != Location.OUTSIDE)) ? v2D : null;
} else {
return ((loc1 == Location.INSIDE) && (loc2 == Location.INSIDE)) ? v2D : null;
}
}
示例3
/** Get the intersection of the instance and another sub-line.
* <p>
* This method is related to the {@link Line#intersection(Line)
* intersection} method in the {@link Line Line} class, but in addition
* to compute the point along infinite lines, it also checks the point
* lies on both sub-line ranges.
* </p>
* @param subLine other sub-line which may intersect instance
* @param includeEndPoints if true, endpoints are considered to belong to
* instance (i.e. they are closed sets) and may be returned, otherwise endpoints
* are considered to not belong to instance (i.e. they are open sets) and intersection
* occurring on endpoints lead to null being returned
* @return the intersection point if there is one, null if the sub-lines don't intersect
*/
public Vector2D intersection(final SubLine subLine, final boolean includeEndPoints) {
// retrieve the underlying lines
Line line1 = (Line) getHyperplane();
Line line2 = (Line) subLine.getHyperplane();
// compute the intersection on infinite line
Vector2D v2D = line1.intersection(line2);
// check location of point with respect to first sub-line
Location loc1 = getRemainingRegion().checkPoint(line1.toSubSpace(v2D));
// check location of point with respect to second sub-line
Location loc2 = subLine.getRemainingRegion().checkPoint(line2.toSubSpace(v2D));
if (includeEndPoints) {
return ((loc1 != Location.OUTSIDE) && (loc2 != Location.OUTSIDE)) ? v2D : null;
} else {
return ((loc1 == Location.INSIDE) && (loc2 == Location.INSIDE)) ? v2D : null;
}
}
示例4
/** Get the intersection of the instance and another sub-line.
* <p>
* This method is related to the {@link Line#intersection(Line)
* intersection} method in the {@link Line Line} class, but in addition
* to compute the point along infinite lines, it also checks the point
* lies on both sub-line ranges.
* </p>
* @param subLine other sub-line which may intersect instance
* @param includeEndPoints if true, endpoints are considered to belong to
* instance (i.e. they are closed sets) and may be returned, otherwise endpoints
* are considered to not belong to instance (i.e. they are open sets) and intersection
* occurring on endpoints lead to null being returned
* @return the intersection point if there is one, null if the sub-lines don't intersect
*/
public Vector3D intersection(final SubLine subLine, final boolean includeEndPoints) {
// compute the intersection on infinite line
Vector3D v1D = line.intersection(subLine.line);
if (v1D == null) {
return null;
}
// check location of point with respect to first sub-line
Location loc1 = remainingRegion.checkPoint((Point<Euclidean1D>) line.toSubSpace((Point<Euclidean3D>) v1D));
// check location of point with respect to second sub-line
Location loc2 = subLine.remainingRegion.checkPoint((Point<Euclidean1D>) subLine.line.toSubSpace((Point<Euclidean3D>) v1D));
if (includeEndPoints) {
return ((loc1 != Location.OUTSIDE) && (loc2 != Location.OUTSIDE)) ? v1D : null;
} else {
return ((loc1 == Location.INSIDE) && (loc2 == Location.INSIDE)) ? v1D : null;
}
}
示例5
/** Get the intersection of the instance and another sub-line.
* <p>
* This method is related to the {@link Line#intersection(Line)
* intersection} method in the {@link Line Line} class, but in addition
* to compute the point along infinite lines, it also checks the point
* lies on both sub-line ranges.
* </p>
* @param subLine other sub-line which may intersect instance
* @param includeEndPoints if true, endpoints are considered to belong to
* instance (i.e. they are closed sets) and may be returned, otherwise endpoints
* are considered to not belong to instance (i.e. they are open sets) and intersection
* occurring on endpoints lead to null being returned
* @return the intersection point if there is one, null if the sub-lines don't intersect
*/
public Vector2D intersection(final SubLine subLine, final boolean includeEndPoints) {
// retrieve the underlying lines
Line line1 = (Line) getHyperplane();
Line line2 = (Line) subLine.getHyperplane();
// compute the intersection on infinite line
Vector2D v2D = line1.intersection(line2);
if (v2D == null) {
return null;
}
// check location of point with respect to first sub-line
Location loc1 = getRemainingRegion().checkPoint(line1.toSubSpace((Point<Euclidean2D>) v2D));
// check location of point with respect to second sub-line
Location loc2 = subLine.getRemainingRegion().checkPoint(line2.toSubSpace((Point<Euclidean2D>) v2D));
if (includeEndPoints) {
return ((loc1 != Location.OUTSIDE) && (loc2 != Location.OUTSIDE)) ? v2D : null;
} else {
return ((loc1 == Location.INSIDE) && (loc2 == Location.INSIDE)) ? v2D : null;
}
}
示例6
@Test
public void testIssue880Simplified() {
Vector2D[] vertices1 = new Vector2D[] {
new Vector2D( 90.13595870833188, 38.33604606376991),
new Vector2D( 90.14047850603913, 38.34600084496253),
new Vector2D( 90.11045289492762, 38.36801537312368),
new Vector2D( 90.10871471476526, 38.36878044144294),
new Vector2D( 90.10424901707671, 38.374300101757),
new Vector2D( 90.0979455456843, 38.373578376172475),
new Vector2D( 90.09081227075944, 38.37526295920463),
new Vector2D( 90.09081378927135, 38.375193883266434)
};
PolygonsSet set1 = new PolygonsSet(1.0e-10, vertices1);
Assert.assertEquals(Location.OUTSIDE, set1.checkPoint(new Vector2D(90.12, 38.32)));
Assert.assertEquals(Location.OUTSIDE, set1.checkPoint(new Vector2D(90.135, 38.355)));
}
示例7
@Test
public void testSplitAtEnd() {
ArcsSet set = new ArcsSet(1.0e-10);
Arc arc = new Arc(FastMath.PI, MathUtils.TWO_PI, 1.0e-10);
ArcsSet.Split split = set.split(arc);
for (double alpha = 0.01; alpha < MathUtils.TWO_PI; alpha += 0.01) {
S1Point p = new S1Point(alpha);
if (alpha > FastMath.PI) {
Assert.assertEquals(Location.OUTSIDE, split.getPlus().checkPoint(p));
Assert.assertEquals(Location.INSIDE, split.getMinus().checkPoint(p));
} else {
Assert.assertEquals(Location.INSIDE, split.getPlus().checkPoint(p));
Assert.assertEquals(Location.OUTSIDE, split.getMinus().checkPoint(p));
}
}
S1Point zero = new S1Point(0.0);
Assert.assertEquals(Location.BOUNDARY, split.getPlus().checkPoint(zero));
Assert.assertEquals(Location.BOUNDARY, split.getMinus().checkPoint(zero));
S1Point pi = new S1Point(FastMath.PI);
Assert.assertEquals(Location.BOUNDARY, split.getPlus().checkPoint(pi));
Assert.assertEquals(Location.BOUNDARY, split.getMinus().checkPoint(pi));
}
示例8
@Test
public void testPositiveOctantByVertices() {
double tol = 0.01;
double sinTol = FastMath.sin(tol);
SphericalPolygonsSet octant = new SphericalPolygonsSet(tol, S2Point.PLUS_I, S2Point.PLUS_J, S2Point.PLUS_K);
UnitSphereRandomVectorGenerator random =
new UnitSphereRandomVectorGenerator(3, new Well1024a(0xb8fc5acc91044308l));
for (int i = 0; i < 1000; ++i) {
Vector3D v = new Vector3D(random.nextVector());
if ((v.getX() > sinTol) && (v.getY() > sinTol) && (v.getZ() > sinTol)) {
Assert.assertEquals(Location.INSIDE, octant.checkPoint(new S2Point(v)));
} else if ((v.getX() < -sinTol) || (v.getY() < -sinTol) || (v.getZ() < -sinTol)) {
Assert.assertEquals(Location.OUTSIDE, octant.checkPoint(new S2Point(v)));
} else {
Assert.assertEquals(Location.BOUNDARY, octant.checkPoint(new S2Point(v)));
}
}
}
示例9
@Test
public void testPositiveOctantByVertices() {
double tol = 0.01;
double sinTol = FastMath.sin(tol);
SphericalPolygonsSet octant = new SphericalPolygonsSet(tol, S2Point.PLUS_I, S2Point.PLUS_J, S2Point.PLUS_K);
UnitSphereRandomVectorGenerator random =
new UnitSphereRandomVectorGenerator(3, new Well1024a(0xb8fc5acc91044308l));
for (int i = 0; i < 1000; ++i) {
Vector3D v = new Vector3D(random.nextVector());
if ((v.getX() > sinTol) && (v.getY() > sinTol) && (v.getZ() > sinTol)) {
Assert.assertEquals(Location.INSIDE, octant.checkPoint(new S2Point(v)));
} else if ((v.getX() < -sinTol) || (v.getY() < -sinTol) || (v.getZ() < -sinTol)) {
Assert.assertEquals(Location.OUTSIDE, octant.checkPoint(new S2Point(v)));
} else {
Assert.assertEquals(Location.BOUNDARY, octant.checkPoint(new S2Point(v)));
}
}
}
示例10
@Test
public void testEmpty() {
SphericalPolygonsSet empty =
(SphericalPolygonsSet) new RegionFactory<Sphere2D>().getComplement(new SphericalPolygonsSet(1.0e-10));
UnitSphereRandomVectorGenerator random =
new UnitSphereRandomVectorGenerator(3, new Well1024a(0x76d9205d6167b6ddl));
for (int i = 0; i < 1000; ++i) {
Vector3D v = new Vector3D(random.nextVector());
Assert.assertEquals(Location.OUTSIDE, empty.checkPoint(new S2Point(v)));
}
Assert.assertEquals(0, empty.getSize(), 1.0e-10);
Assert.assertEquals(0, empty.getBoundarySize(), 1.0e-10);
Assert.assertEquals(0, empty.getBoundaryLoops().size());
Assert.assertTrue(empty.getEnclosingCap().getRadius() < 0);
Assert.assertTrue(Double.isInfinite(empty.getEnclosingCap().getRadius()));
}
示例11
@Test
public void testIssue880Simplified() {
Vector2D[] vertices1 = new Vector2D[] {
new Vector2D( 90.13595870833188, 38.33604606376991),
new Vector2D( 90.14047850603913, 38.34600084496253),
new Vector2D( 90.11045289492762, 38.36801537312368),
new Vector2D( 90.10871471476526, 38.36878044144294),
new Vector2D( 90.10424901707671, 38.374300101757),
new Vector2D( 90.0979455456843, 38.373578376172475),
new Vector2D( 90.09081227075944, 38.37526295920463),
new Vector2D( 90.09081378927135, 38.375193883266434)
};
PolygonsSet set1 = new PolygonsSet(1.0e-10, vertices1);
Assert.assertEquals(Location.OUTSIDE, set1.checkPoint(new Vector2D(90.12, 38.32)));
Assert.assertEquals(Location.OUTSIDE, set1.checkPoint(new Vector2D(90.135, 38.355)));
}
示例12
/** Get the intersection of the instance and another sub-line.
* <p>
* This method is related to the {@link Line#intersection(Line)
* intersection} method in the {@link Line Line} class, but in addition
* to compute the point along infinite lines, it also checks the point
* lies on both sub-line ranges.
* </p>
* @param subLine other sub-line which may intersect instance
* @param includeEndPoints if true, endpoints are considered to belong to
* instance (i.e. they are closed sets) and may be returned, otherwise endpoints
* are considered to not belong to instance (i.e. they are open sets) and intersection
* occurring on endpoints lead to null being returned
* @return the intersection point if there is one, null if the sub-lines don't intersect
*/
public Vector2D intersection(final SubLine subLine, final boolean includeEndPoints) {
// retrieve the underlying lines
Line line1 = (Line) getHyperplane();
Line line2 = (Line) subLine.getHyperplane();
// compute the intersection on infinite line
Vector2D v2D = line1.intersection(line2);
// check location of point with respect to first sub-line
Location loc1 = getRemainingRegion().checkPoint(line1.toSubSpace(v2D));
// check location of point with respect to second sub-line
Location loc2 = subLine.getRemainingRegion().checkPoint(line2.toSubSpace(v2D));
if (includeEndPoints) {
return ((loc1 != Location.OUTSIDE) && (loc2 != Location.OUTSIDE)) ? v2D : null;
} else {
return ((loc1 == Location.INSIDE) && (loc2 == Location.INSIDE)) ? v2D : null;
}
}
示例13
/** Get the intersection of the instance and another sub-line.
* <p>
* This method is related to the {@link Line#intersection(Line)
* intersection} method in the {@link Line Line} class, but in addition
* to compute the point along infinite lines, it also checks the point
* lies on both sub-line ranges.
* </p>
* @param subLine other sub-line which may intersect instance
* @param includeEndPoints if true, endpoints are considered to belong to
* instance (i.e. they are closed sets) and may be returned, otherwise endpoints
* are considered to not belong to instance (i.e. they are open sets) and intersection
* occurring on endpoints lead to null being returned
* @return the intersection point if there is one, null if the sub-lines don't intersect
*/
public Vector3D intersection(final SubLine subLine, final boolean includeEndPoints) {
// compute the intersection on infinite line
Vector3D v1D = line.intersection(subLine.line);
// check location of point with respect to first sub-line
Location loc1 = remainingRegion.checkPoint(line.toSubSpace(v1D));
// check location of point with respect to second sub-line
Location loc2 = subLine.remainingRegion.checkPoint(subLine.line.toSubSpace(v1D));
if (includeEndPoints) {
return ((loc1 != Location.OUTSIDE) && (loc2 != Location.OUTSIDE)) ? v1D : null;
} else {
return ((loc1 == Location.INSIDE) && (loc2 == Location.INSIDE)) ? v1D : null;
}
}
示例14
/** Get the intersection of the instance and another sub-line.
* <p>
* This method is related to the {@link Line#intersection(Line)
* intersection} method in the {@link Line Line} class, but in addition
* to compute the point along infinite lines, it also checks the point
* lies on both sub-line ranges.
* </p>
* @param subLine other sub-line which may intersect instance
* @param includeEndPoints if true, endpoints are considered to belong to
* instance (i.e. they are closed sets) and may be returned, otherwise endpoints
* are considered to not belong to instance (i.e. they are open sets) and intersection
* occurring on endpoints lead to null being returned
* @return the intersection point if there is one, null if the sub-lines don't intersect
*/
public Vector2D intersection(final SubLine subLine, final boolean includeEndPoints) {
// retrieve the underlying lines
Line line1 = (Line) getHyperplane();
Line line2 = (Line) subLine.getHyperplane();
// compute the intersection on infinite line
Vector2D v2D = line1.intersection(line2);
// check location of point with respect to first sub-line
Location loc1 = getRemainingRegion().checkPoint(line1.toSubSpace(v2D));
// check location of point with respect to second sub-line
Location loc2 = subLine.getRemainingRegion().checkPoint(line2.toSubSpace(v2D));
if (includeEndPoints) {
return ((loc1 != Location.OUTSIDE) && (loc2 != Location.OUTSIDE)) ? v2D : null;
} else {
return ((loc1 == Location.INSIDE) && (loc2 == Location.INSIDE)) ? v2D : null;
}
}
示例15
/** Get the intersection of the instance and another sub-line.
* <p>
* This method is related to the {@link Line#intersection(Line)
* intersection} method in the {@link Line Line} class, but in addition
* to compute the point along infinite lines, it also checks the point
* lies on both sub-line ranges.
* </p>
* @param subLine other sub-line which may intersect instance
* @param includeEndPoints if true, endpoints are considered to belong to
* instance (i.e. they are closed sets) and may be returned, otherwise endpoints
* are considered to not belong to instance (i.e. they are open sets) and intersection
* occurring on endpoints lead to null being returned
* @return the intersection point if there is one, null if the sub-lines don't intersect
*/
public Vector3D intersection(final SubLine subLine, final boolean includeEndPoints) {
// compute the intersection on infinite line
Vector3D v1D = line.intersection(subLine.line);
if (v1D == null) {
return null;
}
// check location of point with respect to first sub-line
Location loc1 = remainingRegion.checkPoint(line.toSubSpace(v1D));
// check location of point with respect to second sub-line
Location loc2 = subLine.remainingRegion.checkPoint(subLine.line.toSubSpace(v1D));
if (includeEndPoints) {
return ((loc1 != Location.OUTSIDE) && (loc2 != Location.OUTSIDE)) ? v1D : null;
} else {
return ((loc1 == Location.INSIDE) && (loc2 == Location.INSIDE)) ? v1D : null;
}
}
示例16
/** Get the intersection of the instance and another sub-line.
* <p>
* This method is related to the {@link Line#intersection(Line)
* intersection} method in the {@link Line Line} class, but in addition
* to compute the point along infinite lines, it also checks the point
* lies on both sub-line ranges.
* </p>
* @param subLine other sub-line which may intersect instance
* @param includeEndPoints if true, endpoints are considered to belong to
* instance (i.e. they are closed sets) and may be returned, otherwise endpoints
* are considered to not belong to instance (i.e. they are open sets) and intersection
* occurring on endpoints lead to null being returned
* @return the intersection point if there is one, null if the sub-lines don't intersect
*/
public Vector2D intersection(final SubLine subLine, final boolean includeEndPoints) {
// retrieve the underlying lines
Line line1 = (Line) getHyperplane();
Line line2 = (Line) subLine.getHyperplane();
// compute the intersection on infinite line
Vector2D v2D = line1.intersection(line2);
if (v2D == null) {
return null;
}
// check location of point with respect to first sub-line
Location loc1 = getRemainingRegion().checkPoint(line1.toSubSpace(v2D));
// check location of point with respect to second sub-line
Location loc2 = subLine.getRemainingRegion().checkPoint(line2.toSubSpace(v2D));
if (includeEndPoints) {
return ((loc1 != Location.OUTSIDE) && (loc2 != Location.OUTSIDE)) ? v2D : null;
} else {
return ((loc1 == Location.INSIDE) && (loc2 == Location.INSIDE)) ? v2D : null;
}
}
示例17
@Test
public void testIssue880Simplified() {
Vector2D[] vertices1 = new Vector2D[] {
new Vector2D( 90.13595870833188, 38.33604606376991),
new Vector2D( 90.14047850603913, 38.34600084496253),
new Vector2D( 90.11045289492762, 38.36801537312368),
new Vector2D( 90.10871471476526, 38.36878044144294),
new Vector2D( 90.10424901707671, 38.374300101757),
new Vector2D( 90.0979455456843, 38.373578376172475),
new Vector2D( 90.09081227075944, 38.37526295920463),
new Vector2D( 90.09081378927135, 38.375193883266434)
};
PolygonsSet set1 = new PolygonsSet(1.0e-10, vertices1);
Assert.assertEquals(Location.OUTSIDE, set1.checkPoint(new Vector2D(90.12, 38.32)));
Assert.assertEquals(Location.OUTSIDE, set1.checkPoint(new Vector2D(90.135, 38.355)));
}
示例18
/** Get the intersection of the instance and another sub-line.
* <p>
* This method is related to the {@link Line#intersection(Line)
* intersection} method in the {@link Line Line} class, but in addition
* to compute the point along infinite lines, it also checks the point
* lies on both sub-line ranges.
* </p>
* @param subLine other sub-line which may intersect instance
* @param includeEndPoints if true, endpoints are considered to belong to
* instance (i.e. they are closed sets) and may be returned, otherwise endpoints
* are considered to not belong to instance (i.e. they are open sets) and intersection
* occurring on endpoints lead to null being returned
* @return the intersection point if there is one, null if the sub-lines don't intersect
*/
public Vector3D intersection(final SubLine subLine, final boolean includeEndPoints) {
// compute the intersection on infinite line
Vector3D v1D = line.intersection(subLine.line);
// check location of point with respect to first sub-line
Location loc1 = remainingRegion.checkPoint(line.toSubSpace(v1D));
// check location of point with respect to second sub-line
Location loc2 = subLine.remainingRegion.checkPoint(subLine.line.toSubSpace(v1D));
if (includeEndPoints) {
return ((loc1 != Location.OUTSIDE) && (loc2 != Location.OUTSIDE)) ? v1D : null;
} else {
return ((loc1 == Location.INSIDE) && (loc2 == Location.INSIDE)) ? v1D : null;
}
}
示例19
/** Get the intersection of the instance and another sub-line.
* <p>
* This method is related to the {@link Line#intersection(Line)
* intersection} method in the {@link Line Line} class, but in addition
* to compute the point along infinite lines, it also checks the point
* lies on both sub-line ranges.
* </p>
* @param subLine other sub-line which may intersect instance
* @param includeEndPoints if true, endpoints are considered to belong to
* instance (i.e. they are closed sets) and may be returned, otherwise endpoints
* are considered to not belong to instance (i.e. they are open sets) and intersection
* occurring on endpoints lead to null being returned
* @return the intersection point if there is one, null if the sub-lines don't intersect
*/
public Vector3D intersection(final SubLine subLine, final boolean includeEndPoints) {
// compute the intersection on infinite line
Vector3D v1D = line.intersection(subLine.line);
if (v1D == null) {
return null;
}
// check location of point with respect to first sub-line
Location loc1 = remainingRegion.checkPoint((Point<Euclidean1D>) line.toSubSpace((Point<Euclidean3D>) v1D));
// check location of point with respect to second sub-line
Location loc2 = subLine.remainingRegion.checkPoint((Point<Euclidean1D>) subLine.line.toSubSpace((Point<Euclidean3D>) v1D));
if (includeEndPoints) {
return ((loc1 != Location.OUTSIDE) && (loc2 != Location.OUTSIDE)) ? v1D : null;
} else {
return ((loc1 == Location.INSIDE) && (loc2 == Location.INSIDE)) ? v1D : null;
}
}
示例20
/** Get the intersection of the instance and another sub-line.
* <p>
* This method is related to the {@link Line#intersection(Line)
* intersection} method in the {@link Line Line} class, but in addition
* to compute the point along infinite lines, it also checks the point
* lies on both sub-line ranges.
* </p>
* @param subLine other sub-line which may intersect instance
* @param includeEndPoints if true, endpoints are considered to belong to
* instance (i.e. they are closed sets) and may be returned, otherwise endpoints
* are considered to not belong to instance (i.e. they are open sets) and intersection
* occurring on endpoints lead to null being returned
* @return the intersection point if there is one, null if the sub-lines don't intersect
*/
public Vector3D intersection(final SubLine subLine, final boolean includeEndPoints) {
// compute the intersection on infinite line
Vector3D v1D = line.intersection(subLine.line);
// check location of point with respect to first sub-line
Location loc1 = remainingRegion.checkPoint(line.toSubSpace(v1D));
// check location of point with respect to second sub-line
Location loc2 = subLine.remainingRegion.checkPoint(subLine.line.toSubSpace(v1D));
if (includeEndPoints) {
return ((loc1 != Location.OUTSIDE) && (loc2 != Location.OUTSIDE)) ? v1D : null;
} else {
return ((loc1 == Location.INSIDE) && (loc2 == Location.INSIDE)) ? v1D : null;
}
}
示例21
/** Get the intersection of the instance and another sub-line.
* <p>
* This method is related to the {@link Line#intersection(Line)
* intersection} method in the {@link Line Line} class, but in addition
* to compute the point along infinite lines, it also checks the point
* lies on both sub-line ranges.
* </p>
* @param subLine other sub-line which may intersect instance
* @param includeEndPoints if true, endpoints are considered to belong to
* instance (i.e. they are closed sets) and may be returned, otherwise endpoints
* are considered to not belong to instance (i.e. they are open sets) and intersection
* occurring on endpoints lead to null being returned
* @return the intersection point if there is one, null if the sub-lines don't intersect
*/
public Vector2D intersection(final SubLine subLine, final boolean includeEndPoints) {
// retrieve the underlying lines
Line line1 = (Line) getHyperplane();
Line line2 = (Line) subLine.getHyperplane();
// compute the intersection on infinite line
Vector2D v2D = line1.intersection(line2);
// check location of point with respect to first sub-line
Location loc1 = getRemainingRegion().checkPoint(line1.toSubSpace(v2D));
// check location of point with respect to second sub-line
Location loc2 = subLine.getRemainingRegion().checkPoint(line2.toSubSpace(v2D));
if (includeEndPoints) {
return ((loc1 != Location.OUTSIDE) && (loc2 != Location.OUTSIDE)) ? v2D : null;
} else {
return ((loc1 == Location.INSIDE) && (loc2 == Location.INSIDE)) ? v2D : null;
}
}
示例22
@Test
public void testSplitAtEnd() {
ArcsSet set = new ArcsSet(1.0e-10);
Arc arc = new Arc(FastMath.PI, MathUtils.TWO_PI, 1.0e-10);
ArcsSet.Split split = set.split(arc);
for (double alpha = 0.01; alpha < MathUtils.TWO_PI; alpha += 0.01) {
S1Point p = new S1Point(alpha);
if (alpha > FastMath.PI) {
Assert.assertEquals(Location.OUTSIDE, split.getPlus().checkPoint(p));
Assert.assertEquals(Location.INSIDE, split.getMinus().checkPoint(p));
} else {
Assert.assertEquals(Location.INSIDE, split.getPlus().checkPoint(p));
Assert.assertEquals(Location.OUTSIDE, split.getMinus().checkPoint(p));
}
}
S1Point zero = new S1Point(0.0);
Assert.assertEquals(Location.BOUNDARY, split.getPlus().checkPoint(zero));
Assert.assertEquals(Location.BOUNDARY, split.getMinus().checkPoint(zero));
S1Point pi = new S1Point(FastMath.PI);
Assert.assertEquals(Location.BOUNDARY, split.getPlus().checkPoint(pi));
Assert.assertEquals(Location.BOUNDARY, split.getMinus().checkPoint(pi));
}
示例23
@Test
public void testIssue880Simplified() {
Vector2D[] vertices1 = new Vector2D[] {
new Vector2D( 90.13595870833188, 38.33604606376991),
new Vector2D( 90.14047850603913, 38.34600084496253),
new Vector2D( 90.11045289492762, 38.36801537312368),
new Vector2D( 90.10871471476526, 38.36878044144294),
new Vector2D( 90.10424901707671, 38.374300101757),
new Vector2D( 90.0979455456843, 38.373578376172475),
new Vector2D( 90.09081227075944, 38.37526295920463),
new Vector2D( 90.09081378927135, 38.375193883266434)
};
PolygonsSet set1 = new PolygonsSet(1.0e-10, vertices1);
Assert.assertEquals(Location.OUTSIDE, set1.checkPoint(new Vector2D(90.12, 38.32)));
Assert.assertEquals(Location.OUTSIDE, set1.checkPoint(new Vector2D(90.135, 38.355)));
}
示例24
private void resolveNumericParameter(final ComponentInstance componentInstance, final Parameter parameter, final String parameterName, final List<String> parameterRefinement) {
ParameterRefinementConfiguration parameterRefinementConfiguration = this.componentParameters.get(componentInstance.getComponent()).get(parameter);
NumericParameterDomain parameterDomain = ((NumericParameterDomain) parameter.getDefaultDomain());
Interval currentInterval = null;
Interval nextInterval = new Interval(parameterDomain.getMin(), parameterDomain.getMax());
double parameterValue = Double.parseDouble(componentInstance.getParameterValues().get(parameterName));
double precision = parameterValue == 0 ? 0 : Math.ulp(parameterValue);
while (true) {
currentInterval = nextInterval;
parameterRefinement.add(this.serializeInterval(currentInterval));
List<Interval> refinement = Util.getNumericParameterRefinement(nextInterval, parameterValue, parameterDomain.isInteger(), parameterRefinementConfiguration);
if (refinement.isEmpty()) {
break;
}
for (Interval interval : refinement) {
if (interval.checkPoint(parameterValue, precision) == Location.INSIDE || interval.checkPoint(parameterValue, precision) == Location.BOUNDARY) {
nextInterval = interval;
break;
}
}
}
parameterRefinement.add(String.valueOf(parameterValue));
}
示例25
/**
* Discretizes the particular provided value. Discretization in this case means
* to replace the original value by a categorical value. The categorical value
* is simply the index of the interval the value was assigned to.
*
* @param value
* The (numeric) value to be discretized
* @param policy
* The policy that has to be used for discretization
* @return
*/
protected int discretize(final double value, final AttributeDiscretizationPolicy policy) {
List<Interval> intervals = policy.getIntervals();
// Find the interval to which the value belongs
for (Interval i : intervals) {
if (i.checkPoint(value, 0) != Location.OUTSIDE) {
return intervals.indexOf(i);
}
}
throw new IllegalStateException(String.format("Policy does not cover value %f", value));
}
示例26
/** Get the intersection of the instance and another sub-line.
* <p>
* This method is related to the {@link Line#intersection(Line)
* intersection} method in the {@link Line Line} class, but in addition
* to compute the point along infinite lines, it also checks the point
* lies on both sub-line ranges.
* </p>
* @param subLine other sub-line which may intersect instance
* @param includeEndPoints if true, endpoints are considered to belong to
* instance (i.e. they are closed sets) and may be returned, otherwise endpoints
* are considered to not belong to instance (i.e. they are open sets) and intersection
* occurring on endpoints lead to null being returned
* @return the intersection point if there is one, null if the sub-lines don't intersect
*/
public Vector2D intersection(final SubLine subLine, final boolean includeEndPoints) {
// retrieve the underlying lines
Line line1 = (Line) getHyperplane();
Line line2 = (Line) subLine.getHyperplane();
// compute the intersection on infinite line
Vector2D v2D = line1.intersection(line2);
// FIX
// if (v2D == null) {
// return null;
// }
// check location of point with respect to first sub-line
Location loc1 = getRemainingRegion().checkPoint(line1.toSubSpace(v2D));
// check location of point with respect to second sub-line
Location loc2 = subLine.getRemainingRegion().checkPoint(line2.toSubSpace(v2D));
if (includeEndPoints) {
return ((loc1 != Location.OUTSIDE) && (loc2 != Location.OUTSIDE)) ? v2D : null;
} else {
return ((loc1 == Location.INSIDE) && (loc2 == Location.INSIDE)) ? v2D : null;
}
}
示例27
/** Get the intersection of the instance and another sub-line.
* <p>
* This method is related to the {@link Line#intersection(Line)
* intersection} method in the {@link Line Line} class, but in addition
* to compute the point along infinite lines, it also checks the point
* lies on both sub-line ranges.
* </p>
* @param subLine other sub-line which may intersect instance
* @param includeEndPoints if true, endpoints are considered to belong to
* instance (i.e. they are closed sets) and may be returned, otherwise endpoints
* are considered to not belong to instance (i.e. they are open sets) and intersection
* occurring on endpoints lead to null being returned
* @return the intersection point if there is one, null if the sub-lines don't intersect
*/
public Vector2D intersection(final SubLine subLine, final boolean includeEndPoints) {
// retrieve the underlying lines
Line line1 = (Line) getHyperplane();
Line line2 = (Line) subLine.getHyperplane();
// compute the intersection on infinite line
Vector2D v2D = line1.intersection(line2);
if (v2D == null) {
return null;
}
// FIX
// if (v2D == null) {
// return null;
// }
// check location of point with respect to first sub-line
Location loc1 = getRemainingRegion().checkPoint(line1.toSubSpace(v2D));
// check location of point with respect to second sub-line
Location loc2 = subLine.getRemainingRegion().checkPoint(line2.toSubSpace(v2D));
if (includeEndPoints) {
return ((loc1 != Location.OUTSIDE) && (loc2 != Location.OUTSIDE)) ? v2D : null;
} else {
return ((loc1 == Location.INSIDE) && (loc2 == Location.INSIDE)) ? v2D : null;
}
}
示例28
@Test
public void testSimplyConnected() {
Vector2D[][] vertices = new Vector2D[][] {
new Vector2D[] {
new Vector2D(36.0, 22.0),
new Vector2D(39.0, 32.0),
new Vector2D(19.0, 32.0),
new Vector2D( 6.0, 16.0),
new Vector2D(31.0, 10.0),
new Vector2D(42.0, 16.0),
new Vector2D(34.0, 20.0),
new Vector2D(29.0, 19.0),
new Vector2D(23.0, 22.0),
new Vector2D(33.0, 25.0)
}
};
PolygonsSet set = buildSet(vertices);
Assert.assertEquals(Region.Location.OUTSIDE, set.checkPoint(new Vector2D(50.0, 30.0)));
checkPoints(Region.Location.INSIDE, set, new Vector2D[] {
new Vector2D(30.0, 15.0),
new Vector2D(15.0, 20.0),
new Vector2D(24.0, 25.0),
new Vector2D(35.0, 30.0),
new Vector2D(19.0, 17.0)
});
checkPoints(Region.Location.OUTSIDE, set, new Vector2D[] {
new Vector2D(50.0, 30.0),
new Vector2D(30.0, 35.0),
new Vector2D(10.0, 25.0),
new Vector2D(10.0, 10.0),
new Vector2D(40.0, 10.0),
new Vector2D(50.0, 15.0),
new Vector2D(30.0, 22.0)
});
checkPoints(Region.Location.BOUNDARY, set, new Vector2D[] {
new Vector2D(30.0, 32.0),
new Vector2D(34.0, 20.0)
});
checkVertices(set.getVertices(), vertices);
}
示例29
/** Check a point with respect to the arc.
* @param point point to check
* @return a code representing the point status: either {@link
* Location#INSIDE}, {@link Location#OUTSIDE} or {@link Location#BOUNDARY}
*/
public Location checkPoint(final double point) {
final double normalizedPoint = MathUtils.normalizeAngle(point, middle);
if (normalizedPoint < lower - tolerance || normalizedPoint > upper + tolerance) {
return Location.OUTSIDE;
} else if (normalizedPoint > lower + tolerance && normalizedPoint < upper - tolerance) {
return Location.INSIDE;
} else {
return (getSize() >= MathUtils.TWO_PI - tolerance) ? Location.INSIDE : Location.BOUNDARY;
}
}
示例30
@Test
public void testMultiple() {
RegionFactory<Sphere1D> factory = new RegionFactory<Sphere1D>();
ArcsSet set = (ArcsSet)
factory.intersection(factory.union(factory.difference(new ArcsSet(1.0, 6.0, 1.0e-10),
new ArcsSet(3.0, 5.0, 1.0e-10)),
new ArcsSet(0.5, 2.0, 1.0e-10)),
new ArcsSet(0.0, 5.5, 1.0e-10));
Assert.assertEquals(3.0, set.getSize(), 1.0e-10);
Assert.assertEquals(Region.Location.OUTSIDE, set.checkPoint(new S1Point(0.0)));
Assert.assertEquals(Region.Location.OUTSIDE, set.checkPoint(new S1Point(4.0)));
Assert.assertEquals(Region.Location.OUTSIDE, set.checkPoint(new S1Point(6.0)));
Assert.assertEquals(Region.Location.INSIDE, set.checkPoint(new S1Point(1.2)));
Assert.assertEquals(Region.Location.INSIDE, set.checkPoint(new S1Point(5.25)));
Assert.assertEquals(Region.Location.BOUNDARY, set.checkPoint(new S1Point(0.5)));
Assert.assertEquals(Region.Location.BOUNDARY, set.checkPoint(new S1Point(3.0)));
Assert.assertEquals(Region.Location.BOUNDARY, set.checkPoint(new S1Point(5.0)));
Assert.assertEquals(Region.Location.BOUNDARY, set.checkPoint(new S1Point(5.5)));
List<Arc> list = set.asList();
Assert.assertEquals(2, list.size());
Assert.assertEquals( 0.5, list.get(0).getInf(), 1.0e-10);
Assert.assertEquals( 3.0, list.get(0).getSup(), 1.0e-10);
Assert.assertEquals( 5.0, list.get(1).getInf(), 1.0e-10);
Assert.assertEquals( 5.5, list.get(1).getSup(), 1.0e-10);
}