File tree 2 files changed +7
-7
lines changed
2 files changed +7
-7
lines changed Original file line number Diff line number Diff line change @@ -30,13 +30,13 @@ map over the range of changing values for one half of our pair, while the other
30
30
``` kotlin
31
31
fun Line.isHorizontal () = this .first.first == this .second.first
32
32
fun Line.isVertical () = this .first.second == this .second.second
33
- fun Line.getHorizontalPoints () = (this .first.second.progressionBetween (this .second.second)).map { y -> this .first.first to y }
34
- fun Line.getVerticalPoints () = (this .first.first.progressionBetween (this .second.first)).map { x -> x to this .first.second }
33
+ fun Line.getHorizontalPoints () = (this .first.second.progressionTo (this .second.second)).map { y -> this .first.first to y }
34
+ fun Line.getVerticalPoints () = (this .first.first.progressionTo (this .second.first)).map { x -> x to this .first.second }
35
35
```
36
- Those that know Kotlin might be wondering what ` progressionBetween ()` is. Frustratingly, Kotlin only honors ranges/progressions
36
+ Those that know Kotlin might be wondering what ` progressionTo ()` is. Frustratingly, Kotlin only honors ranges/progressions
37
37
that are defined in the correct order, so I made this convenience method to sort it out.
38
38
``` kotlin
39
- fun Int.progressionBetween (i : Int ): IntProgression =
39
+ fun Int.progressionTo (i : Int ): IntProgression =
40
40
if (this > i) { i.. this }
41
41
else { i downTo this }
42
42
```
Original file line number Diff line number Diff line change @@ -10,14 +10,14 @@ fun main() {
10
10
typealias Point = Pair <Int , Int >
11
11
typealias Line = Pair <Point , Point >
12
12
13
- fun Int.progressionBetween (i : Int ): IntProgression =
13
+ fun Int.progressionTo (i : Int ): IntProgression =
14
14
if (this > i) { i.. this }
15
15
else { i downTo this }
16
16
17
17
fun Line.isHorizontal () = this .first.first == this .second.first
18
18
fun Line.isVertical () = this .first.second == this .second.second
19
- fun Line.getHorizontalPoints () = (this .first.second.progressionBetween (this .second.second)).map { y -> this .first.first to y }
20
- fun Line.getVerticalPoints () = (this .first.first.progressionBetween (this .second.first)).map { x -> x to this .first.second }
19
+ fun Line.getHorizontalPoints () = (this .first.second.progressionTo (this .second.second)).map { y -> this .first.first to y }
20
+ fun Line.getVerticalPoints () = (this .first.first.progressionTo (this .second.first)).map { x -> x to this .first.second }
21
21
fun Line.get45DegreePoints () = getVerticalPoints().map { it.first }.zip(getHorizontalPoints().map { it.second })
22
22
23
23
fun Line.getAllPoints (allow45degree : Boolean ): List <Point > =
You can’t perform that action at this time.
0 commit comments