Skip to content

Wrong Union for single variable sampling #377

Description

@dario-coscia

Describe the bug
When doing the unions of 1D segments the Union class fails

To Reproduce

from matplotlib import pyplot as plt
from pina.geometry import CartesianDomain, Union

# Voglio creare un dominio definitio come l'unione di due segmenti
# s1: {x:[0,4], y: 2.} e s2: {x:[4], y:[0,2]}

# Definisico s1 e lo visualizzo
s1 = CartesianDomain({'x':[0,4], 'y':2})
pts_s1 = s1.sample(n=100, mode='random')
plt.scatter(pts_s1.extract(['x']), pts_s1.extract(['y']))
plt.savefig("s1")
plt.close()

# Definisco s2 e lo visualizzo
s2 = CartesianDomain({'x':4, 'y':[0,2]})
pts_s2 = s2.sample(n=100, mode='random')
plt.scatter(pts_s2.extract(['x']), pts_s2.extract(['y']))
plt.savefig("s2")
plt.close()

# Visualizzo s1 e s2 insieme
plt.scatter(pts_s1.extract(['x']), pts_s1.extract(['y']))
plt.scatter(pts_s2.extract(['x']), pts_s2.extract(['y']))
plt.savefig("s1_s2")
plt.close()

# Definisco l'unione dei due segmenti e visualizzo
union = Union([s1, s2])
pts_union = union.sample(n=1000, mode='random')
plt.scatter(pts_union.extract(['x']), pts_union.extract(['y']))
plt.savefig("union")
plt.close()

Expected behavior
s1_s2.png picture should be the same as union.png

Output
Different pictures.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions