11package core
22
3+ import core.models.Line
4+ import core.models.Point
35import core.processors.BinaryProcessor
6+ import utils.exceptions.LineNotFoundException
47import java.awt.Color
58import java.awt.image.BufferedImage
69import java.io.File
10+ import java.util.*
711import javax.imageio.ImageIO
812
913/* *
@@ -13,33 +17,69 @@ import javax.imageio.ImageIO
1317class Graph (file : File ) {
1418 val image: BufferedImage
1519 val cache: BufferedImage
20+ val mark: Array <Array <Boolean >>
1621
1722 init {
1823 image = ImageIO .read(file)
1924 cache = ImageIO .read(file)
25+ mark = Array (cache.height, {
26+ Array (cache.width, { false })
27+ })
2028 init ()
2129 }
2230
2331 fun init () {
2432 (0 .. image.width - 1 ).forEach { x ->
2533 (0 .. image.height - 1 ).forEach { y ->
26- image.setRGB(
27- x, y,
28- getBin(x, y)
29- )
34+ image.setRGB(x, y, color(x, y))
35+ mark[x][y] = this [x, y]
3036 }
3137 }
3238 }
3339
40+ /* *
41+ * please handle an exception
42+ */
43+ fun findLine (x : Int , y : Int ) {
44+ var line = ArrayList <Line >()
45+ if (! mark[x][y]) throw LineNotFoundException (x, y)
46+ // deprecated
47+ // var max = Max(x, y, -1.0)
48+ // (-1..1).forEach { x ->
49+ // (-1..1).forEach { y ->
50+ // if (x == 0 && y == 0) return
51+ // var p = Point(x, y)
52+ //
53+ // }
54+ // }
55+ }
56+
57+ fun findLine (point : Point ) = findLine(point.x, point.y)
58+
3459 /* *
3560 * @param x x in image
3661 * @param y y in image
3762 * @return black or white
3863 */
39- private fun getBin (x : Int , y : Int ) =
40- if (BinaryProcessor .getGray(cache.getRGB( x, y)) > average )
64+ private fun color (x : Int , y : Int ) =
65+ if (get( x, y))
4166 Color .WHITE .rgb
4267 else
4368 Color .BLACK .rgb
4469
70+ private fun color (point : Point ) =
71+ color(point.x, point.y)
72+
73+ operator fun get (x : Int , y : Int ) =
74+ BinaryProcessor .getGray(cache.getRGB(x, y)) > average
75+
76+ operator fun get (point : Point ) = this [point.x, point.y]
77+
78+ private fun isLine (x : Point , y : Point ): Boolean {
79+ // tOdO
80+ return true
81+ }
82+
83+ data class Max (val x : Int , val y : Int , val length : Double )
84+
4585}
0 commit comments