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

new functions for compas geometry #569

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

nikeftekhar
Copy link
Contributor

@nikeftekhar nikeftekhar commented Jun 24, 2020

new functions regarding the following topics:
line divide by count
polyline shorten
polyline rebuild
polyline divide by count
polyline tween
transformations extend line
transformations extend polyline
intersection_mesh_line
intersection_mesh_plane
split polyline_plane
split mesh_plane

What type of change is this?

  • Bug fix in a backwards-compatible manner.
  • New feature in a backwards-compatible manner.
  • Breaking change: bug fix or new feature that involve incompatible API changes.
  • Other (e.g. doc update, configuration, etc)

Checklist

Put an x in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code.

  • I added a line to the CHANGELOG.md file in the Unreleased section under the most fitting heading (e.g. Added, Changed, Removed).
  • I ran all tests on my computer and it's all green (i.e. invoke test).
  • I ran lint on my computer and there are no errors (i.e. invoke lint).
  • I added new functions/classes and made them available on a second-level import, e.g. compas.datastructures.Mesh.
  • I have added tests that prove my fix is effective or that my feature works.
  • I have added necessary documentation (if appropriate)

line divide by count
polyline shorten
polyline rebuild
polyline divide by count
polyline tween
transformations extend line
transformations extend polyline
intersection_mesh_line
intersection_mesh_plane
split polyline_plane
split mesh_plane
Copy link
Member

@gonzalocasas gonzalocasas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked mostly for code style. I guess @brgcode would check for correctness in terms of geometry processing.
I added a bunch of comments, plus I think it would really be of use to add a few unit tests to this (and it should not be overly complex to do so).

src/compas/geometry/_intersections/mesh_intersections.py Outdated Show resolved Hide resolved
src/compas/geometry/_intersections/mesh_intersections.py Outdated Show resolved Hide resolved
src/compas/geometry/_intersections/mesh_intersections.py Outdated Show resolved Hide resolved
src/compas/geometry/_intersections/mesh_intersections.py Outdated Show resolved Hide resolved
src/compas/geometry/_primitives/line.py Outdated Show resolved Hide resolved
src/compas/geometry/splits/splits.py Outdated Show resolved Hide resolved
src/compas/geometry/splits/splits.py Outdated Show resolved Hide resolved
src/compas/geometry/splits/splits.py Outdated Show resolved Hide resolved
src/compas/geometry/splits/splits.py Outdated Show resolved Hide resolved
src/compas/geometry/splits/splits.py Outdated Show resolved Hide resolved
nikeftekhar and others added 10 commits June 25, 2020 09:50
Co-authored-by: Gonzalo Casas <gonzalocasas@gmail.com>
Co-authored-by: Gonzalo Casas <gonzalocasas@gmail.com>
Co-authored-by: Gonzalo Casas <gonzalocasas@gmail.com>
Co-authored-by: Gonzalo Casas <gonzalocasas@gmail.com>
Co-authored-by: Gonzalo Casas <gonzalocasas@gmail.com>
Co-authored-by: Gonzalo Casas <gonzalocasas@gmail.com>
Co-authored-by: Gonzalo Casas <gonzalocasas@gmail.com>
Co-authored-by: Gonzalo Casas <gonzalocasas@gmail.com>
Co-authored-by: Gonzalo Casas <gonzalocasas@gmail.com>
corrected errors
invoke lint passed
invoke test passed
intersection_2 = intersection_line_triangle(line, triangle_2)
if intersection_2:
return Point(intersection_2[0], intersection_2[1], intersection_2[2])
else:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indent

Copy link
Member

@beverlylytle beverlylytle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey Nik, nice PR! There's a lot going in this, so I've made a lot of comments, sorry if it is overwhelming. Really, there are three general themes to the comments.

  • The first category is about making the docstrings consistent and exact:

There should be consistency in using the same tense, capitalization, and punctuation (eg "Return blahblahblah. " vs "returns blahblahblah").

Types of function parameters and return objects should be double checked. Reference-able types should be included in the format required by Sphinx, eg

 :class:`compas.geometry.Point`

Docstrings should by default include examples that can be run as tests. I didn't explicitly ask for examples in my comments, but those should be added when possible.

  • The next category of comments is about tightening up the code. Using one line instead of two, or naming conventions. These are mostly about readability, and maybe are just my personal preference, but a couple of them are about optimization.

  • The last category of comments is about code correctness. I think in one or two places some edge cases were missed, and these need to be addressed.

Do let me know if anything is unclear.


Parameters
----------
mesh : compas.datastructures.Mesh
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To make the documentation reference-able, this should read

mesh : :class:`compas.datastructures.Mesh`

and similarly for all references in this PR.

-------
Point : compas.geometry.Point
"""
for fkey in list(mesh.faces()):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I understand it mesh.faces() returns a generator, so there's no need to instantiate a list (could be very taxing on memory), so it would be more efficient to have:

for fkey in mesh.faces():

Comment on lines +32 to +36
if not vertex_keys:
continue
vertices = [mesh.vertex_attributes(vkey, 'xyz') for vkey in vertex_keys]
if len(vertex_keys) not in (3, 4):
continue
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this be simplified to

if not (vertex_keys and len(vertex_keys) in (3,4)):
    continue
vertices = [mesh.vertex_atrributes(vkey, 'xyz') for vkey in vertex_keys]

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well or a condition that fails early (the and will require both conditions to be checked at all times)

if not vertex_keys or len(vertex_keys) not in (3, 4):
    continue

intersections: list of points as keys from mesh
"""
intersections = []
for u, v in list(mesh.edges()):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, for efficiency for u, v in mesh.edges():


Returns
-------
Point : compas.geometry.Point
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:class:`compas.geometry.Point`

Parameters
----------
mesh : compas.datastructures.Mesh
plane : compas.geometry.Plane
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a description of 'open'.



def intersection_mesh_line(mesh, line):
"""Compute intersection between mesh faces and line. After one single intersection, stops searching for more.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are very clear in the docstrings about the behavior of intersection_mesh_line and intersection_mesh_plane, but I don't like that the one fails early (returning the first point of intersection with a line) and the other gives all points of intersection. I think the difference should be reflected in the names.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename both to intersections_mesh_xxx? with returned intersections sorted based on distance in the case of line?

triangle = [vertices[0], vertices[1], vertices[2]]
intersection = intersection_line_triangle(line, triangle)
if intersection:
return Point(intersection[0], intersection[1], intersection[2])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would this work?

return Point(*intersection)

return intersections


def mesh_vertices_to_points(mesh, v_keys):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function doesn't have much functionality, and I don't see much point of adding it to the library.


Returns
-------
list of :class: 'compas.geometry.Point'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

list of :class:`compas.geometry.Point`

@nperraud
Copy link

nperraud commented Oct 1, 2020

Hi everyone,

First, thank you for the great package. Would it be possible to know when this will be merged. I need the function intersection_mesh_line for one of my experiment.

All the best

@tomvanmele
Copy link
Member

hi, it seems there are still quite a bit of unaddressed comments. if you resolve those, i am more than happy to merge immediately. if in the meantime you need mesh/line intersections urgently you could use intersection_mesh_ray of compas_libigl...

@tomvanmele
Copy link
Member

also, in the case of intersection_mesh_plane you could use the slicing functionality of compas_cgal, if you need it urgently...

Base automatically changed from master to main February 5, 2021 09:49
@jf---
Copy link
Contributor

jf--- commented Apr 16, 2024

@tomvanmele this is meaningful work, but this has been sitting here for a long time...
Since the author hasn't responded to the excellent code review, I think its fair to close it.

@nikeftekhar
Copy link
Contributor Author

nikeftekhar commented Apr 16, 2024 via email

@gonzalocasas
Copy link
Member

we could set a meeting, may be you could guide me through on how to set the working environment and everything properly

@nikeftekhar yep, let's do that, feel free to poke me directly in person, or send me a calendar invite to do this

@nikeftekhar
Copy link
Contributor Author

nikeftekhar commented Apr 16, 2024 via email

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

Successfully merging this pull request may close these issues.

6 participants