コード例 #1
0
    def test_interpolate(self):
        # Straignt line x=y
        coords = [
            Coordinate(0.0, 0.0),
            Coordinate(0.4, 0.4),
            Coordinate(0.8, 0.8),
            Coordinate(1.2, 1.2),
        ]
        s = Surface(coords)
        for i in range(100):
            val = i / 100.0
            result = s.interpolate(val)
            assert result == Coordinate(val, val)

        # horizontal line y=0.5
        coords = [
            Coordinate(0.0, 0.5),
            Coordinate(0.4, 0.5),
            Coordinate(0.8, 0.5),
            Coordinate(1.2, 0.5),
        ]
        s = Surface(coords)
        for i in range(100):
            val = i / 100.0
            result = s.interpolate(val)
            assert result == Coordinate(val, 0.5)
コード例 #2
0
    def test_interpolate_new_surface(self):
        coords = [
            Coordinate(0.0, 0.0),
            Coordinate(0.4, 0.2),
            Coordinate(0.8, 0.4),
            Coordinate(1.2, 0.6),
        ]
        # make same surface
        s1 = Surface(coords)
        s2 = Surface(coords)
        length = 500
        s3 = Surface.interpolate_new_surface(s1, s2, 10, 3, length)

        assert len(s3.coordinates) == length

        # test each original coordinate to see if it's the same
        # doesn't validate correctly on an interpolated foil but
        # works on our linear example
        for c in s1.coordinates:
            assert c == s3.interpolate(c.x)
        # also only works on our contrived example
        for i in range(len(s1.coordinates) - 1):
            c1 = coords[i]
            c2 = coords[i + 1]
            c3 = c1 + c2
            c3 = c3 * 0.5
            assert s1.interpolate(c3.x) == s3.interpolate(c3.x)