jbuckmccready / cavalier_contours

2D polyline/shape library for offsetting, combining, etc.
Apache License 2.0
144 stars 12 forks source link

Boolean operation failed #42

Open timoria21 opened 1 month ago

timoria21 commented 1 month ago

Hi,

I managed to find these two polyline where the difference operation seems to not work, however I didn't manage to found the root cause; I tested the case with the interactive demo, in the attached file there are the two polylines and the code that the COPY TEST CODE button created.

// Polyline A
{
  "isClosed": true, 
  "vertexes": [
    [-188.500000000023, -166.831646988729, 0],
[-188.5, -195.881478300073, 0],
[-189, -196.91384910249, 0.553407781718062],
[-170.999999999999, -225.631646989572, -0.553407781718061],
[-153, -196.91384910249, -0.553407781718095],
[-153.5, -195.881478300072, 0],
[-153.5, -166.831646988778, 0],
[-153.5, -166.820646988779, 0],
[-188.500000000023, -166.820646988729, 0]
  ]
}
// Polyline B
{
  "isClosed": true, 
  "vertexes": [
    [412, -246.331646989572, 0],
[412, -156.831646989572, 0],
[319, -156.831646989571, 0],
[319, -193.831646989571, 0],
[317, -193.831646989571, 0],
[317, -156.831646989572, 0],
[-153.5, -156.831646989572, 0],
[-153.5, -195.881478300072, 0],
[-153, -196.91384910249, -0.553407781718061],
[-171, -225.631646989571, -0.553407781718061],
[-189, -196.91384910249, 0],
[-188.5, -195.881478300073, 0],
[-188.5, -156.831646989571, 0],
[-498, -156.831646989571, 0],
[-498, -193.831646989572, 0],
[-448, -193.831646989572, 0],
[-448, -228.831646989571, 0],
[-538, -228.831646989571, 0],
[-538, -193.831646989572, 0],
[-500, -193.831646989572, 0],
[-500, -156.831646989572, 0],
[-618, -156.831646989572, 0],
[-618, -246.331646989572, 0]
  ]
}
// Copy test code result
(
    pline_closed![(-188.500000000023, -166.831646988729, 0.0),
(-188.5, -195.881478300073, 0.0),
(-189.0, -196.91384910249, 0.553407781718062),
(-170.999999999999, -225.631646989572, -0.553407781718061),
(-153.0, -196.91384910249, -0.553407781718095),
(-153.5, -195.881478300072, 0.0),
(-153.5, -166.831646988778, 0.0),
(-153.5, -166.820646988779, 0.0),
(-188.500000000023, -166.820646988729, 0.0)],
    pline_closed![(412.0, -246.331646989572, 0.0),
(412.0, -156.831646989572, 0.0),
(319.0, -156.831646989571, 0.0),
(319.0, -193.831646989571, 0.0),
(317.0, -193.831646989571, 0.0),
(317.0, -156.831646989572, 0.0),
(-153.5, -156.831646989572, 0.0),
(-153.5, -195.881478300072, 0.0),
(-153.0, -196.91384910249, -0.553407781718061),
(-171.0, -225.631646989571, -0.553407781718061),
(-189.0, -196.91384910249, 0.0),
(-188.5, -195.881478300073, 0.0),
(-188.5, -156.831646989571, 0.0),
(-498.0, -156.831646989571, 0.0),
(-498.0, -193.831646989572, 0.0),
(-448.0, -193.831646989572, 0.0),
(-448.0, -228.831646989571, 0.0),
(-538.0, -228.831646989571, 0.0),
(-538.0, -193.831646989572, 0.0),
(-500.0, -193.831646989572, 0.0),
(-500.0, -156.831646989572, 0.0),
(-618.0, -156.831646989572, 0.0),
(-618.0, -246.331646989572, 0.0)]
)
=>
[
    (BooleanOp::Or, &[PlineProperties::new(2, 0.0, 58.12166262258597, -153.5, -195.881478300072, -153.5, -166.820646988779)], &[PlineProperties::new(2, -0.25699795696345973, 2.515629079078068, -153.60334994589547, -196.91384910249, -153.0, -195.881478300072)]),
    (BooleanOp::And, &[PlineProperties::new(2, 0.0, 58.12166262258597, -153.5, -195.881478300072, -153.5, -166.820646988779), PlineProperties::new(6, 0.0, 141.28874550503852, -191.0, -225.631646989571, -171.0, -166.820646988729)], &[]),
    (BooleanOp::Not, &[PlineProperties::new(2, 0.00000000000275690581, 80.87292554364576, -173.0, -225.631646989571, -153.0, -196.91384910249)], &[]),
    (BooleanOp::Xor, &[PlineProperties::new(2, 0.00000000000275690581, 80.87292554364576, -173.0, -225.631646989571, -153.0, -196.91384910249), PlineProperties::new(23, 86517.95712324319, 2759.2667455033516, -618.0, -246.331646989572, 412.0, -156.831646989571)], &[])
]