Mercurial > gemma
view pkg/octree/plane2d_test.go @ 2130:f3aabc05f9b2
Fix constraints on waterway profiles
staging_done in the UNIQUE constraint had no effect, because the
exclusion constraint prevented two rows with equal location and
validity anyhow. Adding staging_done to the exclusion constraint
makes the UNIQUE constraint checking only a corner case of what
the exclusion constraint checks. Thus, remove the UNIQUE constraint.
Casting staging_done to int is needed because there is no appropriate
operator class for booleans. Casting to smallint or even bit would have
been better (i.e. should result in smaller index size), but that would
have required creating such a CAST, in addition.
author | Tom Gottfried <tom@intevation.de> |
---|---|
date | Wed, 06 Feb 2019 15:42:32 +0100 |
parents | a244b18cb916 |
children |
line wrap: on
line source
// This is Free Software under GNU Affero General Public License v >= 3.0 // without warranty, see README.md and license for details. // // SPDX-License-Identifier: AGPL-3.0-or-later // License-Filename: LICENSES/AGPL-3.0.txt // // Copyright (C) 2018 by via donau // – Österreichische Wasserstraßen-Gesellschaft mbH // Software engineering by Intevation GmbH // // Author(s): // * Sascha L. Teichmann <sascha.teichmann@intevation.de> package octree import ( "math" "testing" ) func TestIntersection(t *testing.T) { table := []struct { a [4]float64 b [4]float64 intersects bool x, y float64 }{ {[4]float64{-1, -1, 1, 1}, [4]float64{-1, 1, 1, -1}, true, 0, 0}, {[4]float64{0, 0, 1, 1}, [4]float64{0, 1, 1, 0}, true, 0.5, 0.5}, {[4]float64{0, 0, 1, 0}, [4]float64{0, 1, 1, 1}, false, 0, 0}, } for _, e := range table { p1 := NewPlane2D(e.a[0], e.a[1], e.a[2], e.a[3]) p2 := NewPlane2D(e.b[0], e.b[1], e.b[2], e.b[3]) x, y, intersects := p1.Intersection(p2) if intersects != e.intersects { t.Fatalf("Have %t want %t\n", intersects, e.intersects) } if e.intersects { if math.Abs(e.x-x) > epsPlane || math.Abs(e.y-y) > epsPlane { t.Fatalf("Have (%f, %f)t want (%f, %f)\n", x, y, e.x, e.y) } } } }