There are the following guarantees for coordinates of the points of any pattern:
Each implementation of this interface must fulfil both restriction. The point sets, satisfying these requirements, are called allowed points sets for patterns. Any attempt to create a pattern, the set of points of which is not allowed, leads to {@link TooLargePatternCoordinatesException}.
Note: though patterns are sets of real points, their coordinates are restricted by long-type constant {@link #MAX_COORDINATE}.
Also note: uniform-grid patterns must fulfil, in addition, two similar restrictions for their grid indexes. See more details in the comments to {@link UniformGridPattern} interface,the section "Grid index restrictions".
Below are two important theorems, following from these two restrictions.
Theorem I. If you round the coordinates of all points of a pattern, i.e. replace each pattern's point
The proof of this is complex enough. The paper (in Russian) contains such proof: see the theorem of rounding and the theorem of subtraction in this paper.
It means that you can freely use {@link #round()} method for any pattern:it always constructs another allowed pattern, both in terms of this interface and in terms in {@link UniformGridPattern}, and cannot throw {@link TooLargePatternCoordinatesException}.
Theorem II. If all points of a pattern are integer, i.e. for all pattern's points
Proof.
First of all, let's remind that the computer difference a⊖b, according IEEE 754 standard and Java language specification, is the nearest double value to the precise mathematical difference a−b. Because all pattern's points are integer, the restriction 2 allows to state that any difference xj−Xj can be represented precisely by double type (see the comments to {@link #MAX_COORDINATE} constant).So, we have
Now the proof is simple. If is enough to show that the restrictions will be satisfied for the coordinate index j. The restriction 2 is obvious: (mathematical) subtracting Xj does not change the (mathematical!) differences |xj1−xj2|. The new value of this coordinate for each point will be xj−Xj, where both (x0,x1,...,xn−1) and (X0,X1,...,Xn−1) are some points of the pattern; according the condition 2, this difference lies in range − {@link #MAX_COORDINATE}≤xj−Xj≤ {@link #MAX_COORDINATE}. In other words, the restriction 1 is also satisfied. This completes the proof.
Note: this proof is really correct only for patterns, consisting of integer points only. The reason is that all integer coordinates, fulfilling the restriction 1, and all their differences xj−Xj are represented precisely by double Java type. If a pattern contains non-integer points, the statement of this theorem is not true. For example, for 1-dimensional pattern, consisting of three points x1=2251799813685248.00 (= {@link #MAX_COORDINATE}/2), x2=−2251799813685248.00 (=− {@link #MAX_COORDINATE}/2) and x3=−2251799813685247.75 (=− {@link #MAX_COORDINATE}/2+0.25), subtracting the point x3 by Java “−” operator leads to the pattern x'1=4503599627370496.00 (= {@link #MAX_COORDINATE}) (computer subtraction of double values leads to rounding here), x'2=−0.25 and x'3=0.0, which obviously violates the mathematically precise restriction 2: |x'1−x'2|> {@link #MAX_COORDINATE}.
As a result, there is an obvious conclusion. If p is one of the {@link #points() points} ofsome integer pattern (see above), then the method pattern. {@link #shift(Point) shift}(p. {@link Point#symmetric() symmetric()}) always works successfully and never throw {@link TooLargePatternCoordinatesException}.
The classes, implementing this interface, are immutable and thread-safe: there are no ways to modify settings of the created instance.
AlgART Laboratory 2007–2014
@author Daniel Alievsky @version 1.2 @since JDK 1.5 | |
| |
| |
| |