Rounding vertex values?

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
mconsidine
Posts: 125
Joined: Wed Jan 18, 2023 10:41 pm
Location: Randolph, VT USA

Rounding vertex values?

Post by mconsidine »

Hi,
First off:

Code: Select all

OS: Linux Mint 21 (X-Cinnamon/cinnamon)
Word size of FreeCAD: 64-bit
Version: 0.21.0.33044 (Git)
Build type: Unknown
Branch: master
Hash: 3fabd940dd3322b247fe2a82f68b754c087f3b34
Python 3.10.6, Qt 5.15.3, Coin 4.0.1, Vtk 9.1.0, OCC 7.7.1
Locale: English/United States (en_US)
Installed mods: 
  * OpenSCAD_Alt_Import 1.0.0
  * ProDarkThemePreferencePack 1.0.0
  * Alternate_OpenSCAD.backup1684871460.3140821 1.0.0 (Disabled)
  * toSketch 1.0.1
  * Alternate_OpenSCAD 1.0.0
  * Render 2023.2.5
  * Manipulator 1.5.0
  * Help 1.0.3
  * POV-Ray-Rendering
  * MeshRemodel 1.8919.0
  * Assembly4 0.50.2
  * freecad.gears 1.0.0
  * CubeMenu
  * fasteners 0.4.56
  * Silk 0.1.3
  * Dracula 0.0.4
  * Curves 0.6.9
  * A2plus 0.4.60n
  * ThreadProfile 1.85.0
I am trying to figure out an efficient way to round the values of a Vertex. For example, let's say I have

Code: Select all

an_edge=Part.Edge(Part.Vertex((1.23456,2.34567,3.45678)),Part.Vertex((7.23456,8.34567,9.45678)))
What I would like to be able to do is say something like:

Code: Select all

an_edge = round(an_edge, 3) #note: this doesn't work
but what that returns is

Code: Select all

Traceback (most recent call last):
  File "<input>", line 1, in <module>
TypeError: type Part.Edge doesn't define __round__ method
It seems like its pretty inefficient to loop through this, pick off each value, round it and then reassemble the edge.

Does anyone have a pointer or suggestion on how to get vertex values rounded to a given number of decimal places?

TIA,
mconsidine
edwilliams16
Veteran
Posts: 3179
Joined: Thu Sep 24, 2020 10:31 pm
Location: Hawaii
Contact:

Re: Rounding vertex values?

Post by edwilliams16 »

mconsidine wrote: Tue May 23, 2023 9:42 pm

It seems like its pretty inefficient to loop through this, pick off each value, round it and then reassemble the edge.
I don't see how you can avoid reconstructing the edge. In python, something like

Code: Select all

def roundVertexes(vxlist, num):
    loclist = [v.Point for v in vxlist]
    return [Part.Vertex(App.Vector(round(l.x, num), round(l.y, num), round(l.z, num))) for l in loclist]

def roundEdge(edge, num):
    return Part.Edge(*roundVertexes(edge.Vertexes, num))
Post Reply