Let's learn geometry
TSQL

Image recognition? Sounds like a job made for SQL :)

WITH cte AS (
  SELECT LEN(data)-LEN(REPLACE(data,'#','')) c FROM test_t
)
SELECT 
  CASE WHEN COUNT(DISTINCT c)&gt;2                           THEN 'triangle' 
       WHEN SUM(CASE WHEN c=0 THEN 0 ELSE 1 END) = MAX(c) THEN 'square'
                                                          ELSE 'rectangle'
       END result
FROM cte;


An SQLfiddle with sample data and test.