Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Optimize and simplify forceMinimize() visible area algorithm
A diagram for understanding the algorithm: +————————————————————————————————+ | | | D | | +--------------------|——————+ | | | | | +----+--------------+ | C | | : : | | | | : : +- - - - - +-----|------|————+ | : : . : | | | | : : . : | | | | : : . 1 2 3 : | | | | : : . 1 2 3 : | | | | : : . 1 2 3 : | | | | : +--------------------|——————+ | | : : 1 2 : | | | : : 1 2 : | | | : : 1 2 : | | +————————————————————————————————+ | | : 1 | | | B : 1 | A | +————————+——————————+ | | | +————————————————————————————+ (I(A, B, ...) is the area of the intersection of the rectangles.) (1) = I(A, B) (2) = I(A, B, D) (3) = I(A, B, C, D) VisibleArea(A) = Area(A) - (1) + (2) - (3) + ... The algorithm was and is (for four rectangles): VisibleArea(A) = = Area(A) - I(A, B) - I(A, C) - I(A, D) + I(A, B, C) + I(A, B, D) + I(A, C, D) - I(A, B, C, D) = Area(A) - I(A, B) + I(A, B, C) - I(A, B, C, D) + I(A, B, D) - I(A, C) + I(A, C, D) - I(A, D) This implementation exploits the fact that I(A, B, C) = I(I(A, B), C), and passes the result of I(A, B) to the computation of I(A, B, C).
- Loading branch information