For the purpose of this challenge a rectangular piece of ASCII art is Mondrian if it looks the same upside down.
What does "looks the same" mean?
A feature is any orthogonally connected region of at last 5 characters. A Mondrian feature is any feature that appears in the same picture upside down. (This includes the possibility of the feature being rotationally symmetric in which case the feature counts as its own upside-down appearance.)
A picture is Mondrian if each of its characters is part of at least one Mondrian feature.
Your task:
Write a function or program that given a rectangle of ASCII characters returns it upside down if it is Mondrian and unchanged otherwise. If the entire picture is rotationally symmetric (such that it is Mondrian but has no upside-down state) the program or function should die horribly. You are free to choose amongst crash, hang, run forever, error out or simply end without output.
You may assume that the input is a clean rectangle of size at least 2x2.
This is code-golf. Standard rules apply, except despite this more or less being a binary decision you cannot do the usual truthy / falsy shenanigans.
You can take input in any reasonable format, e.g. newline separated string, list of lines, array of characters, but must output in the same format.
More clarifications on "upside down":
We mean (180-degree) rotation, not mirroring.
Characters are atoms, for example
p
upside down isp
, notd
.
Also: Features are allowed to overlap. (They do in both Mondrian examples below.)
Examples:
Mondrian:
-+-----+--
| |
=#=====#==
-+-----+--
*|./*
-+=+-
=#-#=
.|*/.
Explanation (possible list of Mondrian features) for 2nd example:
-+=+-
=#-#=
*
-
=
.|*
./*
=
-
*
Not Mondrian:
-___---
//O////
~/|\.~~
./ \...
Mondrian impostor (not Mondrian):
----
||||
----
||||
~~~~
Die horribly:
-
/ \
|
\
|
\ /
-