Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Different values after using == operator #108

Open
jogoe222 opened this issue Dec 10, 2022 · 1 comment
Open

Different values after using == operator #108

jogoe222 opened this issue Dec 10, 2022 · 1 comment

Comments

@jogoe222
Copy link

I'm doing the following:

my_poly8 = sg.Polygon([sg.Point2(7.8324275, 48.0067807),
                       sg.Point2(7.8325995, 48.0066757),
                       sg.Point2(7.8329729, 48.0069493),
                       sg.Point2(7.8327973, 48.0070572)])

skeleton = sg.skeleton.create_interior_straight_skeleton(my_poly8)
skeleton2 = sg.skeleton.create_interior_straight_skeleton(my_poly8)

print([(float(h.vertex.point.x()),
        float(h.vertex.point.x())) for h in skeleton.halfedges] == \
      [(float(h.vertex.point.x()),
        float(h.vertex.point.x())) for h in skeleton2.halfedges])

for h in skeleton.halfedges:
    h.vertex.point == h.vertex.point

print([(float(h.vertex.point.x()),
        float(h.vertex.point.x())) for h in skeleton.halfedges] == \
      [(float(h.vertex.point.x()),
        float(h.vertex.point.x())) for h in skeleton2.halfedges])

And the first print statement prints True as one would expect, given that the skeletons were calculated from the exact same polygon. However, after the loop where points get compared to each other the following print statement prints False, though one would expect that the comparison has no effect on the values.
The same happens if instead of comparing the points themselves the values using .x() and .y() get compared. It does not happen, however, if the floating point values get compared like float(h.vertex.point.x()) == float(h.vertex.point.x()).

When I print the values like this

l1 = [h for h in skeleton.halfedges]    
l2 = [h for h in skeleton2.halfedges]    

for i in range(len(l1)):
    x1, y1, time1 = (float(l1[i].vertex.point.x()),
                     float(l1[i].vertex.point.y()),
                     float(l1[i].vertex.time))
    x2, y2, time2 = (float(l2[i].vertex.point.x()),
                     float(l2[i].vertex.point.y()),
                     float(l2[i].vertex.time))
    if x1 == x2 and y1 == y2 and time1 == time2:
        print('Equal:', (x1, y1, time1), '--', (x2, y2, time2))
    else:
        print('Unequal:', (x1, y1, time1), '--', (x2, y2, time2))

I get the following:

Equal: (7.8324275, 48.0067807, 0.0) -- (7.8324275, 48.0067807, 0.0)
Equal: (7.8327973, 48.0070572, 0.0) -- (7.8327973, 48.0070572, 0.0)
Equal: (7.8325995, 48.0066757, 0.0) -- (7.8325995, 48.0066757, 0.0)
Equal: (7.8324275, 48.0067807, 0.0) -- (7.8324275, 48.0067807, 0.0)
Equal: (7.8329729, 48.0069493, 0.0) -- (7.8329729, 48.0069493, 0.0)
Equal: (7.8325995, 48.0066757, 0.0) -- (7.8325995, 48.0066757, 0.0)
Equal: (7.8327973, 48.0070572, 0.0) -- (7.8327973, 48.0070572, 0.0)
Equal: (7.8329729, 48.0069493, 0.0) -- (7.8329729, 48.0069493, 0.0)
Unequal: (7.832594741461895, 48.00678856190903, 9.385126534434371e-05) -- (7.8325947414618895, 48.00678856190903, 9.385126534434371e-05)
Equal: (7.8324275, 48.0067807, 0.0) -- (7.8324275, 48.0067807, 0.0)
Unequal: (7.832594741461895, 48.00678856190903, 9.385126534434371e-05) -- (7.8325947414618895, 48.00678856190903, 9.385126534434371e-05)
Equal: (7.8325995, 48.0066757, 0.0) -- (7.8325995, 48.0066757, 0.0)
Unequal: (7.832802530957059, 48.00694236500672, 9.510177268401894e-05) -- (7.8328025309570535, 48.00694236500672, 9.510177268401894e-05)
Equal: (7.8329729, 48.0069493, 0.0) -- (7.8329729, 48.0069493, 0.0)
Unequal: (7.832802530957059, 48.00694236500672, 9.510177268401894e-05) -- (7.8328025309570535, 48.00694236500672, 9.510177268401894e-05)
Equal: (7.8327973, 48.0070572, 0.0) -- (7.8327973, 48.0070572, 0.0)
Unequal: (7.832802530957059, 48.00694236500672, 9.510177268401894e-05) -- (7.8328025309570535, 48.00694236500672, 9.510177268401894e-05)
Unequal: (7.832594741461895, 48.00678856190903, 9.385126534434371e-05) -- (7.8325947414618895, 48.00678856190903, 9.385126534434371e-05)

I can't make any sense of the (apparently?) changed values but it only seems to affect the vertices where time > 0 but I'm still wondering why the values are different just from a simple comparison.

My version of scikit-geometry is 0.1.2 (which is the version available on Anaconda) on Python 3.9.12.

@geographika
Copy link
Contributor

I can't create the above running your above script on a recent build of scikit-geometry and using CGAL 5.6 (on Windows):
However you probably shouldn't be relying on comparing float values for equality - https://stackoverflow.com/questions/5595425/what-is-the-best-way-to-compare-floats-for-almost-equality-in-python

Equal: (7.8324275, 48.0067807, 0.0) -- (7.8324275, 48.0067807, 0.0)
Equal: (7.8327973, 48.0070572, 0.0) -- (7.8327973, 48.0070572, 0.0)
Equal: (7.8325995, 48.0066757, 0.0) -- (7.8325995, 48.0066757, 0.0)
Equal: (7.8324275, 48.0067807, 0.0) -- (7.8324275, 48.0067807, 0.0)
Equal: (7.8329729, 48.0069493, 0.0) -- (7.8329729, 48.0069493, 0.0)
Equal: (7.8325995, 48.0066757, 0.0) -- (7.8325995, 48.0066757, 0.0)
Equal: (7.8327973, 48.0070572, 0.0) -- (7.8327973, 48.0070572, 0.0)
Equal: (7.8329729, 48.0069493, 0.0) -- (7.8329729, 48.0069493, 0.0)
Equal: (7.832594741461897, 48.00678856190903, 9.385126534628892e-05) -- (7.832594741461897, 48.00678856190903, 9.385126534628892e-05)
Equal: (7.8324275, 48.0067807, 0.0) -- (7.8324275, 48.0067807, 0.0)
Equal: (7.832594741461897, 48.00678856190903, 9.385126534628892e-05) -- (7.832594741461897, 48.00678856190903, 9.385126534628892e-05)
Equal: (7.8325995, 48.0066757, 0.0) -- (7.8325995, 48.0066757, 0.0)
Equal: (7.832802530957057, 48.00694236500673, 9.510177268927739e-05) -- (7.832802530957057, 48.00694236500673, 9.510177268927739e-05)
Equal: (7.8329729, 48.0069493, 0.0) -- (7.8329729, 48.0069493, 0.0)
Equal: (7.832802530957057, 48.00694236500673, 9.510177268927739e-05) -- (7.832802530957057, 48.00694236500673, 9.510177268927739e-05)
Equal: (7.8327973, 48.0070572, 0.0) -- (7.8327973, 48.0070572, 0.0)
Equal: (7.832802530957057, 48.00694236500673, 9.510177268927739e-05) -- (7.832802530957057, 48.00694236500673, 9.510177268927739e-05)
Equal: (7.832594741461897, 48.00678856190903, 9.385126534628892e-05) -- (7.832594741461897, 48.00678856190903, 9.385126534628892e-05)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants