SPB Git forge

spb/ka-maps

Public
6commits 1branches 0releases
448.0 KBsize
maindefault branch
29 days agolast push
TypeScript 87.7% CSS 12.3%
2.0 KB · 64 lines typescript
Raw Blame History
1/**2 * Author: Simon-Pierre Boucher3 * Contact: contact@spboucher.ai4 * Project: Groupe Ka / Ka Maps5 *6 * bboxOfProperties + pointInPolygon — les briques géométriques de la7 * synchronisation liste ↔ carte (fitBounds sur les résultats, zone dessinée).8 */9import { describe, expect, it } from "vitest";10import { bboxOfProperties, pointInPolygon } from "../src/utils/geo.js";11import type { MapProperty } from "../src/types/index.js";1213const prop = (lat: number, lng: number): MapProperty => ({14  id: `${lat},${lng}`,15  appSource: "lou-ka",16  latitude: lat,17  longitude: lng,18  kind: "listing",19});2021describe("bboxOfProperties", () => {22  it("englobe tous les points", () => {23    const bbox = bboxOfProperties([prop(46.8, -71.2), prop(45.5, -73.6), prop(46.3, -72.5)]);24    expect(bbox).toEqual({ west: -73.6, south: 45.5, east: -71.2, north: 46.8 });25  });2627  it("ignore les coordonnées invalides (0,0 sentinelle)", () => {28    const bbox = bboxOfProperties([prop(0, 0), prop(46.8, -71.2)]);29    expect(bbox).toEqual({ west: -71.2, south: 46.8, east: -71.2, north: 46.8 });30  });3132  it("null quand rien n'est géolocalisé", () => {33    expect(bboxOfProperties([prop(0, 0)])).toBeNull();34    expect(bboxOfProperties([])).toBeNull();35  });36});3738describe("pointInPolygon", () => {39  // triangle autour du Vieux-Québec40  const ring: [number, number][] = [41    [-71.24, 46.80],42    [-71.20, 46.82],43    [-71.24, 46.83],44  ];4546  it("dedans", () => {47    expect(pointInPolygon(-71.228, 46.817, ring)).toBe(true);48  });4950  it("dehors", () => {51    expect(pointInPolygon(-71.30, 46.81, ring)).toBe(false);52    expect(pointInPolygon(-71.21, 46.79, ring)).toBe(false);53  });5455  it("polygone concave", () => {56    const u: [number, number][] = [57      [0, 0], [4, 0], [4, 4], [3, 4], [3, 1], [1, 1], [1, 4], [0, 4],58    ];59    expect(pointInPolygon(0.5, 2, u)).toBe(true);    // branche gauche du U60    expect(pointInPolygon(2, 2, u)).toBe(false);     // creux du U61    expect(pointInPolygon(3.5, 2, u)).toBe(true);    // branche droite62  });63});64