mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-29 01:34:29 +01:00
Where overlapping faces of a solid are put in the order of their depths (local_order, also Revolve's surface_order) and some lie in front of one another in a ring, no order draws them all correctly. When the sort could draw no face next, it drew the first face left by depth, whether or not that face was part of a ring. A face that is only in front of a ring's face, and comes before the ring by depth, was then drawn under it: dashed strokes on bars that overlap in a ring, extruded as a 3D group, had whole wall panels drawn over their dashes. The sort now follows the faces that go before the first face left back, among the faces that come before the next face drawn last, to a ring that waits for no other of them (Tarjan's algorithm on the pairs reversed, stopped at the first component completed). That ring gives up its own face that comes first in the order of their depths, and the faces left are looked at afresh, since they may be a smaller ring or none. Only pairs of a ring, and pairs with a face drawn last, are then drawn the wrong way round. A face drawn last (a cap) still follows every face before it. Cost and memory: - Comparing pairs and looking for rings share MAX_LOCAL_CHECKS steps: every face and pair looked at takes a step, and a face's list of the faces before it is charged before it is read. Past the limit the first face left by depth goes next, as before. - A first face left that waits only for the next face drawn last, or faces after it, goes next with no search and no step: each face keeps a count of the faces not drawn before it that come before the face drawn last. - The search goes on from where it stopped, less the group that gave up a face, so rings apart or one behind the other take a few steps a face. A ring that is still a ring after it gives up a face is walked again, so a large ring can cost about the square of its faces. - The pairs are held as two u32 (8 bytes), dropped once each face's list of the faces after it is made; both kinds of list are one array of 4 bytes a pair. The lists of the faces before each face take a step a pair to make, not taken from the limit, and are made only when the room left is at least a quarter of the pairs, so making them costs no more than four times the room left. A solid whose comparing leaves less breaks its rings at the first face left by depth. draw_order, cut_stroke_faces and in_one_order are unchanged. Tests (solids::tests): - a_face_in_front_of_a_cycle_waits_for_it: [0, 2, 3, 1] where the first face by depth gave [3, 0, 2, 1]; with a cap, it stays last. - the_faces_left_are_looked_at_afresh_after_each_face_released, the_ring_released_waits_for_no_face_outside_it, a_ring_is_looked_for_before_the_next_face_drawn_last. - breaking_a_ring_draws_no_more_pairs_wrong_than_the_first_face_by_depth: 6,000 random sets (up to 30 faces, pairs shuffled and repeated, up to four faces drawn last), each held to the order worked out plainly. - breaking_rings_stops_at_its_room, breaking_rings_takes_a_few_steps_a_face_but_for_a_ring_of_many_pairs: the steps are counted, not timed, and bounded from above. - a_face_that_waits_only_for_the_face_drawn_last_costs_no_search: 1,000 such faces before a ring take no search. - the_lists_for_rings_are_made_only_with_room_for_a_quarter_of_the_pairs. - a_list_longer_than_the_room_left_is_not_read: the entries read are counted where they are read, and stay within the room. - a_depth_cycle_keeps_the_cap_last is unchanged and passes. With no ring looked for, the ring tests fail; without the skip or the room for the lists, their tests fail. Docs: docs/three-d.md, docs/revolve.md, docs/effects-parity.md, docs/target-app-parity.md. Part of #7023.