Skip to content

Commit 780c193

Browse files
authored
Merge branch 'main' into alert-autofix-3
2 parents 5aa3878 + 5b857f5 commit 780c193

11 files changed

Lines changed: 180 additions & 60 deletions

File tree

.github/workflows/codeql.yml

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
# For most projects, this workflow file will not need changing; you simply need
2+
# to commit it to your repository.
3+
#
4+
# You may wish to alter this file to override the set of languages analyzed,
5+
# or to provide custom queries or build logic.
6+
#
7+
# ******** NOTE ********
8+
# We have attempted to detect the languages in your repository. Please check
9+
# the `language` matrix defined below to confirm you have the correct set of
10+
# supported CodeQL languages.
11+
#
12+
name: "CodeQL Advanced"
13+
14+
on:
15+
push:
16+
branches: [ "main" ]
17+
pull_request:
18+
branches: [ "main" ]
19+
schedule:
20+
- cron: '31 18 * * 2'
21+
22+
jobs:
23+
analyze:
24+
name: Analyze (${{ matrix.language }})
25+
# Runner size impacts CodeQL analysis time. To learn more, please see:
26+
# - https://gh.io/recommended-hardware-resources-for-running-codeql
27+
# - https://gh.io/supported-runners-and-hardware-resources
28+
# - https://gh.io/using-larger-runners (GitHub.com only)
29+
# Consider using larger runners or machines with greater resources for possible analysis time improvements.
30+
runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }}
31+
permissions:
32+
# required for all workflows
33+
security-events: write
34+
35+
# required to fetch internal or private CodeQL packs
36+
packages: read
37+
38+
# only required for workflows in private repositories
39+
actions: read
40+
contents: read
41+
42+
strategy:
43+
fail-fast: false
44+
matrix:
45+
include:
46+
- language: actions
47+
build-mode: none
48+
- language: java-kotlin
49+
build-mode: manual
50+
- language: javascript-typescript
51+
build-mode: none
52+
- language: python
53+
build-mode: none
54+
# CodeQL supports the following values keywords for 'language': 'actions', 'c-cpp', 'csharp', 'go', 'java-kotlin', 'javascript-typescript', 'python', 'ruby', 'rust', 'swift'
55+
# Use `c-cpp` to analyze code written in C, C++ or both
56+
# Use 'java-kotlin' to analyze code written in Java, Kotlin or both
57+
# Use 'javascript-typescript' to analyze code written in JavaScript, TypeScript or both
58+
# To learn more about changing the languages that are analyzed or customizing the build mode for your analysis,
59+
# see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/customizing-your-advanced-setup-for-code-scanning.
60+
# If you are analyzing a compiled language, you can modify the 'build-mode' for that language to customize how
61+
# your codebase is analyzed, see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/codeql-code-scanning-for-compiled-languages
62+
steps:
63+
- name: Checkout repository
64+
uses: actions/checkout@v4
65+
66+
# Add any setup steps before running the `github/codeql-action/init` action.
67+
# This includes steps like installing compilers or runtimes (`actions/setup-node`
68+
# or others). This is typically only required for manual builds.
69+
# - name: Setup runtime (example)
70+
# uses: actions/setup-example@v1
71+
72+
# Initializes the CodeQL tools for scanning.
73+
- name: Initialize CodeQL
74+
uses: github/codeql-action/init@v4
75+
with:
76+
languages: ${{ matrix.language }}
77+
build-mode: ${{ matrix.build-mode }}
78+
# If you wish to specify custom queries, you can do so here or in a config file.
79+
# By default, queries listed here will override any specified in a config file.
80+
# Prefix the list here with "+" to use these queries and those in the config file.
81+
82+
# For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
83+
# queries: security-extended,security-and-quality
84+
85+
# If the analyze step fails for one of the languages you are analyzing with
86+
# "We were unable to automatically build your code", modify the matrix above
87+
# to set the build mode to "manual" for that language. Then modify this step
88+
# to build your code.
89+
# ℹ️ Command-line programs to run using the OS shell.
90+
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
91+
- name: Run manual build steps
92+
if: matrix.build-mode == 'manual'
93+
shell: bash
94+
run: |
95+
./gradlew assembleDebug
96+
97+
- name: Perform CodeQL Analysis
98+
uses: github/codeql-action/analyze@v4
99+
with:
100+
category: "/language:${{matrix.language}}"

.github/workflows/nightly.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
name: Nightly
2+
permissions:
3+
contents: read
24

35
on:
46
schedule:

app/build.gradle.kts

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -99,23 +99,6 @@ android {
9999
applicationIdSuffix = ".nightly_release"
100100
versionNameSuffix = "-nightly-release-${LocalDate.now()}"
101101
}
102-
103-
// ------- DEPRECATED -------
104-
105-
// Legacy debug build for GitHub
106-
create("dev") {
107-
initWith(getByName("debug"))
108-
signingConfig = signingConfigs.getByName("dev")
109-
applicationIdSuffix = ".dev"
110-
versionNameSuffix = "-dev"
111-
}
112-
// Legacy release build for GitHub
113-
create("legacyGithub") {
114-
initWith(getByName("release"))
115-
signingConfig = signingConfigs.getByName("dev")
116-
applicationIdSuffix = ".github"
117-
versionNameSuffix = "-github"
118-
}
119102
}
120103
testOptions {
121104
unitTests.all {

app/src/androidTest/java/com/kylecorry/trail_sense/weather/infrastructure/subsystem/WeatherSubsystemTest.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -260,12 +260,12 @@ internal class WeatherSubsystemTest {
260260
false
261261
)
262262
actual = actual.copy(
263-
start = actual.start.convertTo(TemperatureUnits.F),
264-
end = actual.end.convertTo(TemperatureUnits.F)
263+
start = actual.start.convertTo(TemperatureUnits.Fahrenheit),
264+
end = actual.end.convertTo(TemperatureUnits.Fahrenheit)
265265
)
266266
val expected = Range(
267-
Temperature.from(day.low.toFloat(), TemperatureUnits.F),
268-
Temperature.from(day.high.toFloat(), TemperatureUnits.F)
267+
Temperature.from(day.low.toFloat(), TemperatureUnits.Fahrenheit),
268+
Temperature.from(day.high.toFloat(), TemperatureUnits.Fahrenheit)
269269
)
270270

271271
errors.add(actual.start.value - expected.start.value)

app/src/main/java/com/kylecorry/trail_sense/tools/map/ui/MapView.kt

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -159,21 +159,17 @@ class MapView(context: Context, attrs: AttributeSet? = null) : CanvasView(contex
159159
val center = mapCenterPixels
160160

161161
// Always render the hemispheres closest to the map center
162-
val newCoordinate = Coordinate(
163-
coordinate.latitude,
164-
mapCenter.longitude + deltaAngle(
162+
val projected = projection.toPixels(
163+
coordinate.latitude, mapCenter.longitude + deltaAngle(
165164
mapCenter.longitude.toFloat(),
166165
coordinate.longitude.toFloat()
167166
)
168167
)
169168

170-
val projected = projection.toPixels(newCoordinate)
171-
172169
val x = (projected.x - center.x) * (Geology.EARTH_AVERAGE_RADIUS / metersPerPixel)
173170
val y =
174171
(center.y - projected.y) * (Geology.EARTH_AVERAGE_RADIUS / metersPerPixel) // Y inverted
175172

176-
// TODO: Replace PixelCoordinate with Vector2
177173
return PixelCoordinate(
178174
x.toFloat() + width / 2f,
179175
y.toFloat() + height / 2f

app/src/main/java/com/kylecorry/trail_sense/tools/paths/map_layers/PathLayer.kt

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,18 @@ class PathLayer : IAsyncLayer, IPathLayer {
5858
private val runner = CoroutineQueueRunner()
5959
private val scope = CoroutineScope(Dispatchers.Default)
6060

61+
private val factory = PathLineDrawerFactory()
62+
6163
private var currentScale = 1f
6264

6365
private var backgroundColor: Int? = null
6466

67+
private var lastHeight = 0
68+
private var lastWidth = 0
69+
private var cachedBounds = Rectangle(0f, 0f, 0f, 0f)
70+
71+
private var filterEpsilon = 0f
72+
6573
fun setPreferences(prefs: PathMapLayerPreferences) {
6674
_percentOpacity = prefs.opacity.get() / 100f
6775
backgroundColor = when (prefs.backgroundColor.get()) {
@@ -96,20 +104,23 @@ class PathLayer : IAsyncLayer, IPathLayer {
96104
}
97105

98106
override fun draw(drawer: ICanvasDrawer, map: IMapView) {
107+
if (filterEpsilon == 0f) {
108+
filterEpsilon = drawer.dp(1.5f)
109+
}
110+
99111
val scale = map.layerScale
100112
currentScale = map.metersPerPixel
101113
if (!pathsRendered && !renderInProgress) {
102114
val renderer = ClippedPathRenderer(
103115
getBounds(drawer),
104116
map::toPixel,
105-
drawer.dp(1.5f)
117+
filterEpsilon
106118
)
107119
renderInBackground(renderer)
108120
}
109121

110122
// Make a copy of the rendered paths
111123
synchronized(lock) {
112-
val factory = PathLineDrawerFactory()
113124
val values = renderedPaths.values
114125
for (path in values) {
115126
// Don't draw empty paths
@@ -316,21 +327,19 @@ class PathLayer : IAsyncLayer, IPathLayer {
316327
pathObj: Path?
317328
): RenderedPath = onDefault {
318329
val points = path.points.map { it.coordinate }
319-
synchronized(lock) {
320-
lineObj.clear()
321-
pathObj?.reset()
322-
val before = currentScale
323-
renderer.render(points, lineObj)
324-
.copy(
325-
style = path.style,
326-
color = path.color,
327-
// A best guess at what scale the path was rendered at
328-
renderedScale = (before + currentScale) / 2f,
329-
originalPath = path,
330-
path = pathObj?.also {
331-
it.drawLines(lineObj.toFloatArray(), shouldRenderSmoothPaths)
332-
})
333-
}
330+
lineObj.clear()
331+
pathObj?.reset()
332+
val before = currentScale
333+
val rendered = renderer.render(points, lineObj)
334+
rendered.copy(
335+
style = path.style,
336+
color = path.color,
337+
// A best guess at what scale the path was rendered at
338+
renderedScale = (before + currentScale) / 2f,
339+
originalPath = path,
340+
path = pathObj?.also {
341+
it.drawLines(rendered.line, shouldRenderSmoothPaths)
342+
})
334343
}
335344

336345
override fun invalidate() {
@@ -343,9 +352,14 @@ class PathLayer : IAsyncLayer, IPathLayer {
343352
}
344353

345354
private fun getBounds(drawer: ICanvasDrawer): Rectangle {
346-
// Rotating by map rotation wasn't working around 90/270 degrees - this is a workaround
347-
// It will just render slightly more of the path than needed, but never less (since 45 is when the area is at its largest)
348-
return drawer.getBounds(45f)
355+
if (drawer.canvas.height != lastHeight || drawer.canvas.width != lastWidth) {
356+
lastHeight = drawer.canvas.height
357+
lastWidth = drawer.canvas.width
358+
// Rotating by map rotation wasn't working around 90/270 degrees - this is a workaround
359+
// It will just render slightly more of the path than needed, but never less (since 45 is when the area is at its largest)
360+
cachedBounds = drawer.getBounds(45f)
361+
}
362+
return cachedBounds
349363
}
350364

351365
override fun setHasUpdateListener(listener: (() -> Unit)?) {

app/src/main/java/com/kylecorry/trail_sense/tools/paths/ui/drawing/PathLineDrawerFactory.kt

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,20 @@ import com.kylecorry.trail_sense.tools.paths.domain.LineStyle
44

55
class PathLineDrawerFactory {
66

7+
private val cache = mutableMapOf<LineStyle, IPathLineDrawerStrategy>()
8+
9+
710
fun create(style: LineStyle): IPathLineDrawerStrategy {
8-
return when (style) {
9-
LineStyle.Solid -> SolidPathLineDrawerStrategy()
10-
LineStyle.Dotted -> DottedPathLineDrawerStrategy()
11-
LineStyle.Arrow -> ArrowPathLineDrawerStrategy()
12-
LineStyle.Dashed -> DashedPathLineDrawerStrategy()
13-
LineStyle.Square -> SquarePathLineDrawerStrategy()
14-
LineStyle.Diamond -> DiamondPathLineDrawerStrategy()
15-
LineStyle.Cross -> CrossPathLineDrawerStrategy()
11+
return cache.getOrPut(style) {
12+
when (style) {
13+
LineStyle.Solid -> SolidPathLineDrawerStrategy()
14+
LineStyle.Dotted -> DottedPathLineDrawerStrategy()
15+
LineStyle.Arrow -> ArrowPathLineDrawerStrategy()
16+
LineStyle.Dashed -> DashedPathLineDrawerStrategy()
17+
LineStyle.Square -> SquarePathLineDrawerStrategy()
18+
LineStyle.Diamond -> DiamondPathLineDrawerStrategy()
19+
LineStyle.Cross -> CrossPathLineDrawerStrategy()
20+
}
1621
}
1722
}
1823

app/src/main/java/com/kylecorry/trail_sense/tools/photo_maps/domain/projections/CalibratedProjection.kt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,21 @@ class CalibratedProjection(
3737
}
3838

3939
override fun toPixels(coordinate: Coordinate): Vector2 {
40+
return toPixels(coordinate.latitude, coordinate.longitude)
41+
}
4042

43+
override fun toPixels(
44+
latitude: Double,
45+
longitude: Double
46+
): Vector2 {
4147
if (left == null || top == null || bottom == null) {
4248
return Vector2(0f, 0f)
4349
}
4450

45-
val coords = if (coordinate.longitude < 0 && bounds.west > 0) {
46-
projection.toPixels(coordinate.copy(longitude = coordinate.longitude + 360))
51+
val coords = if (longitude < 0 && bounds.west > 0) {
52+
projection.toPixels(latitude, longitude + 360)
4753
} else {
48-
projection.toPixels(coordinate)
54+
projection.toPixels(latitude, longitude)
4955
}
5056

5157
val x = left.first.x + width * norm(coords.x, bottomLeft.x, topRight.x)

app/src/main/java/com/kylecorry/trail_sense/tools/photo_maps/domain/projections/PhotoMapProjection.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ class PhotoMapProjection(
2626
return projection.toPixels(location)
2727
}
2828

29+
override fun toPixels(
30+
latitude: Double,
31+
longitude: Double
32+
): Vector2 {
33+
return projection.toPixels(latitude, longitude)
34+
}
35+
2936
private fun calculateProjection(): IMapProjection {
3037
val rotatedSize = map.calibratedSize(usePdf)
3138
val calibrationPoints = rotationService.getCalibrationPoints()

app/src/main/java/com/kylecorry/trail_sense/tools/photo_maps/domain/projections/RotatedProjection.kt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,14 @@ class RotatedProjection(
2020
}
2121

2222
override fun toPixels(location: Coordinate): Vector2 {
23-
val unrotated = projection.toPixels(location)
23+
return toPixels(location.latitude, location.longitude)
24+
}
25+
26+
override fun toPixels(
27+
latitude: Double,
28+
longitude: Double
29+
): Vector2 {
30+
val unrotated = projection.toPixels(latitude, longitude)
2431
return unrotated.rotateInRect(-rotation, rotatedSize, size)
2532
}
2633
}

0 commit comments

Comments
 (0)