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

Minor additions #1327

Merged
merged 6 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

* Added `compas.colors.Color.contrast`.
* Added `compas.geometry.Brep.from_plane`.
* Added `compas.tolerance.Tolerance.angulardeflection`.

### Changed

* Changed and updated the `compas_view2` examples into `compas_viewer`.
Expand Down
6 changes: 6 additions & 0 deletions src/compas/colors/color.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ class Color(Data):
The perceived freedom of whiteness.
is_light : bool
If True, the color is considered light.
contrast : :class:`compas.colors.Color`
The contrasting color to the current color.

Examples
--------
Expand Down Expand Up @@ -311,6 +313,10 @@ def saturation(self):
minval = min(self.r, self.g, self.b)
return (maxval - minval) / maxval

@property
def contrast(self):
return self.darkened(25) if self.is_light else self.lightened(50)

# --------------------------------------------------------------------------
# Constructors
# --------------------------------------------------------------------------
Expand Down
5 changes: 5 additions & 0 deletions src/compas/geometry/brep/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ def from_pipe(*args, **kwargs):
raise PluginNotInstalledError


@pluggable(category="factories")
def from_plane(*args, **kwargs):
raise PluginNotInstalledError

Comment on lines +75 to +78
Copy link
Member

Choose a reason for hiding this comment

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

Is there a rhino implementation that we could add right away as well? Or will this be only OCC?

Copy link
Member Author

Choose a reason for hiding this comment

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

dunno. will check

Copy link
Member Author

Choose a reason for hiding this comment

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

no, Rhino doesn't have a CreateFromPlane or similar...


@pluggable(category="factories")
def from_planes(*args, **kwargs):
raise PluginNotInstalledError
Expand Down
28 changes: 23 additions & 5 deletions src/compas/geometry/brep/brep.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,14 @@
from . import from_boolean_union
from . import from_curves
from . import from_pipe
from . import from_plane
from . import from_planes
from . import from_polygons
from . import from_step
from . import from_sweep
from . import from_native


LINEAR_DEFLECTION = 1e-3


class BrepType(object):
"""Possible types of a Brep

Expand Down Expand Up @@ -489,6 +487,26 @@ def from_pipe(cls, curve, radius, thickness=None):
"""
return from_pipe(curve, radius, thickness=thickness)

@classmethod
def from_plane(cls, plane, domain_u=(-1, +1), domain_v=(-1, +1)):
"""Construct a Brep from one plane and its u and v domains.

Parameters
----------
plane : :class:`~compas.geometry.Plane`
A plane.
domain_u : tuple[float, float], optional
The surface domain in the u direction.
domain_v : tuple[float, float], optional
The surface domain in the v direction.

Returns
-------
:class:`compas.geometry.Brep`

"""
return from_plane(plane, domain_u=domain_u, domain_v=domain_v)

@classmethod
def from_planes(cls, planes):
"""Construct a Brep from a set of planes.
Expand Down Expand Up @@ -768,7 +786,7 @@ def to_stl(self, filepath):
"""
raise NotImplementedError

def to_tesselation(self, linear_deflection=LINEAR_DEFLECTION):
def to_tesselation(self, linear_deflection=None):
"""Create a tesselation of the shape for visualisation.

Parameters
Expand Down Expand Up @@ -1093,7 +1111,7 @@ def split(self, cutter):
"""
raise NotImplementedError

def overlap(self, other, deflection=LINEAR_DEFLECTION, tolerance=0.0):
def overlap(self, other, deflection=None, tolerance=0.0):
"""Compute the overlap between this BRep and another.

Parameters
Expand Down
29 changes: 27 additions & 2 deletions src/compas/tolerance.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,14 @@ class Tolerance(Data):
"""

LINEARDEFLECTION = 1e-3
"""float: The maximum distance between a curve or surface and its polygonal approximation.
"""float: The maximum "distance" deviation between a curve or surface and its polygonal approximation.

This is used by the viewer to determine the mesh and polyline resolution of curves and surfaces for visualisation.

"""

ANGULARDEFLECTION = 1e-1
"""float: The maximum "curvature" deviation between a curve or surface and its polygonal approximation.

This is used by the viewer to determine the mesh and polyline resolution of curves and surfaces for visualisation.

Expand All @@ -115,6 +122,7 @@ def __data__(self):
"approximation": self.approximation,
"precision": self.precision,
"lineardeflection": self.lineardeflection,
"angulardeflection": self.angulardeflection,
}

@classmethod
Expand All @@ -127,6 +135,7 @@ def __from_data__(cls, data):
tol.approximation = data["approximation"]
tol.precision = data["precision"]
tol.lineardeflection = data["lineardeflection"]
tol.angulardeflection = data["angulardeflection"]
return tol

def __init__(
Expand All @@ -138,6 +147,7 @@ def __init__(
approximation=None,
precision=None,
lineardflection=None,
angulardflection=None,
name=None,
):
super(Tolerance, self).__init__(name=name)
Expand All @@ -148,25 +158,29 @@ def __init__(
self._approximation = None
self._precision = None
self._lineardeflection = None
self._angulardeflection = None
self.unit = unit
self.absolute = absolute
self.relative = relative
self.angular = angular
self.approximation = approximation
self.precision = precision
self.lineardeflection = lineardflection
self.angulardeflection = angulardflection

# this can be autogenerated if we use slots
# __repr__: return f"{__class__.__name__}({', '.join(f'{k}={v!r}' for k, v in self.__dict__.items())})}"

def __repr__(self):
return "Tolerance(unit='{}', absolute={}, relative={}, angular={}, approximation={}, precision={}, lineardeflection={})".format(
return "Tolerance(unit='{}', absolute={}, relative={}, angular={}, approximation={}, precision={}, lineardeflection={}, angulardeflection={})".format(
self.unit,
self.absolute,
self.relative,
self.angular,
self.approximation,
self.precision,
self.lineardeflection,
self.angulardeflection,
)

def reset(self):
Expand All @@ -177,6 +191,7 @@ def reset(self):
self._approximation = None
self._precision = None
self._lineardeflection = None
self._angulardeflection = None

@property
def units(self):
Expand Down Expand Up @@ -250,6 +265,16 @@ def lineardeflection(self):
def lineardeflection(self, value):
self._lineardeflection = value

@property
def angulardeflection(self):
if not self._angulardeflection:
return self.ANGULARDEFLECTION
return self._angulardeflection

@angulardeflection.setter
def angulardeflection(self, value):
self._angulardeflection = value

def tolerance(self, truevalue, rtol, atol):
"""Compute the tolerance for a comparison.

Expand Down
Loading