Skip to content

Commit

Permalink
Use constant for extent
Browse files Browse the repository at this point in the history
  • Loading branch information
tschumpr committed Apr 25, 2024
1 parent e0c44df commit 3a88023
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions src/Geopilot.Api/ContextExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ internal static class ContextExtensions
internal const string NameClaim = "name";
internal const string EmailClaim = "email";

private static readonly double[] extentCh = new double[] { 7.536621, 46.521076, 9.398804, 47.476376 };

/// <summary>
/// Retreives the user that matches the provided principal from the database.
/// Automatically updates the user information in the database if it has changed.
Expand Down Expand Up @@ -99,19 +101,13 @@ public static void SeedOrganisations(this Context context)

public static Geometry GetExtent()
{
// Reference extent for Switzerland
var longMinRef = 7.536621;
var latMinRef = 46.521076;
var longMaxRef = 9.398804;
var latMaxRef = 47.476376;

var longDiffHalf = (longMaxRef - longMinRef) / 2;
var latDiffHalf = (latMaxRef - latMinRef) / 2;

var longMin = new Faker().Random.Double(longMinRef, longMinRef + longDiffHalf);
var latMin = new Faker().Random.Double(latMinRef, latMinRef + latDiffHalf);
var longMax = new Faker().Random.Double(longMaxRef - longDiffHalf, longMaxRef);
var latMax = new Faker().Random.Double(latMaxRef - latDiffHalf, latMaxRef);
var longDiffHalf = (extentCh[2] - extentCh[0]) / 2;
var latDiffHalf = (extentCh[3] - extentCh[1]) / 2;

var longMin = new Faker().Random.Double(extentCh[0], extentCh[0] + longDiffHalf);
var latMin = new Faker().Random.Double(extentCh[1], extentCh[1] + latDiffHalf);
var longMax = new Faker().Random.Double(extentCh[2] - longDiffHalf, extentCh[2]);
var latMax = new Faker().Random.Double(extentCh[3] - latDiffHalf, extentCh[3]);

return GeometryFactory.Default.CreatePolygon(new Coordinate[]
{
Expand Down

0 comments on commit 3a88023

Please sign in to comment.