/// <summary>Gets a value indicating whether a specific point is inside the region. /// </summary> /// <param name="x">The argument, i.e. a point of dimension <see cref="IMultiDimRegion.Dimension" />.</param> /// <param name="distance">The distance to the region represented by the current instance (output).</param> /// <param name="tolerance">This parameter will be ignored in this implementation.</param> /// <returns>A value indicating whether <paramref name="x" /> is inside the region and has some strictly positive distance to the region represented by the current instance.</returns> public PointRegionRelation GetDistance(double[] x, out double distance, double tolerance = MachineConsts.Epsilon) { distance = 0.0; PointRegionRelation state = PointRegionRelation.InsideOrBoundaryPoint; /* We do the matrix operation 'by hand'. This needs less memory - perhaps this method will be called often: */ for (int i = 0; i < m_InequalityMatrix.ColumnCount; i++) { double product = 0.0; for (int k = 0; k < Dimension; k++) { product += m_InequalityMatrix[k, i] * x[k]; } if (product < m_InequalityVector[i]) { distance += m_InequalityVector[i] - product; state = PointRegionRelation.Outside; } } return(state); }
/// <summary>Gets a value indicating whether a specific point is inside the region. /// </summary> /// <param name="x">The argument, i.e. a point of dimension <see cref="IMultiDimRegion.Dimension" />.</param> /// <param name="distance">The distance to the region represented by the current instance (output).</param> /// <param name="tolerance">Some tolerance to take into account.</param> /// <returns>A value indicating whether <paramref name="x" /> is inside the region and has some strictly positive distance to the region represented by the current instance.</returns> public PointRegionRelation GetDistance(double[] x, out double distance, double tolerance = MachineConsts.Epsilon) { distance = 0.0; PointRegionRelation state = PointRegionRelation.InsideOrBoundaryPoint; /* We do the matrix operation 'by hand'. This needs less memory: */ for (int i = 0; i < m_EqualityMatrix.ColumnCount; i++) { double product = 0.0; for (int k = 0; k < Dimension; k++) { product += m_EqualityMatrix[k, i] * x[k]; } if (Math.Abs(product - m_EqualityVector[i]) > tolerance) // 'if (product != m_EqualityVector[j])' + rounding errors { distance += Math.Abs(product - m_EqualityVector[i]); state = PointRegionRelation.Outside; } } return(state); }
/// <summary>Gets a value indicating whether a specific point is inside the region. /// </summary> /// <param name="x">The argument, i.e. a point of dimension <see cref="IMultiDimRegion.Dimension" />.</param> /// <param name="distance">The distance to the region represented by the current instance (output).</param> /// <param name="tolerance">This parameter will be ignored in this implementation.</param> /// <returns>A value indicating whether <paramref name="x" /> is inside the region and has some strictly positive distance to the region represented by the current instance.</returns> public PointRegionRelation GetDistance(double[] x, out double distance, double tolerance = MachineConsts.Epsilon) { distance = 0.0; PointRegionRelation pointRelation = PointRegionRelation.InsideOrBoundaryPoint; for (int j = 0; j < m_Dimension; j++) { double pointComponent = x[j]; if (pointComponent < m_LowerBounds[j]) { distance += m_LowerBounds[j] - pointComponent; pointRelation = PointRegionRelation.Outside; } if (m_UpperBounds[j] < pointComponent) { distance += pointComponent - m_UpperBounds[j]; pointRelation = PointRegionRelation.Outside; } } return(pointRelation); }