gumyr / cq_warehouse

A cadquery parametric part collection
Apache License 2.0
107 stars 23 forks source link

Problem with external thread with parameter end_finishes=("chamfer","square") #86

Open yguel opened 5 months ago

yguel commented 5 months ago

When modifying the code from the thread_example.py and change the finishes for external threads from ("fade","square") to : either ("square", "chamfer") or ("chamfer","square") the thread is not produced. Maybe I do not understand correctly those parameters. From the doc I expect one of the two to be for the bottom of the cylinder and the other for the top of the cylinder.

If I understand correctly, I expect that bug to be a problem with the occ_kernel. Do you have ideas how to solve it ?

Furthermore when I use the ("square","square") parameter I expect the result to be clamped at the beginning and end of the iso_external_core cylinder, but on the bottom it extends.

Below is the code I used:

import timeit

from cq_warehouse.thread import (
    IsoThread
)

MM = 1

def external_example():
    """IsoThread External Example"""
    starttime = timeit.default_timer()
    iso_external_thread = IsoThread(
        major_diameter=6 * MM,
        pitch=1 * MM,
        length=10 * MM,
        external=True,
        #end_finishes=("fade", "square"),
        end_finishes=("square", "chamfer"),
        #end_finishes=("chamfer","square"),
        #end_finishes=("chamfer","chamfer"),
        #end_finishes=("square", "square"),
        #end_finishes=("fade", "fade"),
        #end_finishes=("fade","chamfer"),
        hand="right"
        #hand="left"
    )
    elapsed_time = timeit.default_timer() - starttime

    iso_external_core = (
        cq.Workplane("XY")
        .circle(iso_external_thread.min_radius)
        .extrude(iso_external_thread.length)
    )
    iso_external = iso_external_thread.cq_object.fuse(iso_external_core.val())
    print(f"{iso_external.isValid()=}")

    show_object(iso_external_thread.cq_object, name="iso_external_thread")
    show_object(iso_external_core, name="iso_external_core")
    show_object(iso_external, name="iso_external")

external_example()

I think I might be able to secure some processing time to perform unit tests with all the possible configurations. I am just not sure how to test automatically that the result is correct, at least it could be possible to detect when the result is empty for the thread or just a cylinder for the union of the thread and the core. I would like to have the thoughts of others about the feasibility and the soundness of such kind of tests.

I would like to finish by express my thanks to the developers of cq_warehouse it was really features lacking in cadQuery and it makes cq much, much more complete for CAD.