Skip to content

Rename Shape.func to field and extend Phase - #144

Open
chemiskyy wants to merge 5 commits into
mainfrom
chore/tier2-api
Open

chemiskyy wants to merge 5 commits into
mainfrom
chore/tier2-api

Conversation

@chemiskyy

Copy link
Copy Markdown
Member

Replace the Shape internal implicit field attribute from _func/func to _field/field across the codebase and update all callers (require_func → require_field, evaluate, mesh paths, implicit ops, primitives). Rename immutable transform APIs on Shape (translate/rotate/scale → translated/rotated/scaled) and update tests accordingly. Enhance Phase with new constructors and features: Phase.from_implicit, Phase.from_grid (grid caching and nearest-neighbour wrapper), a cached grid shortcut, and an immutable rotated() transform (CAD- and field-backed handling) plus an internal _with_cad helper. Minor fix in meshbridge error check to use the new field property. Tests updated and a new test file added to cover Phase constructors and rotations. These changes standardize naming and add Tier-2 Phase functionality while updating tests to match the new API.

chemiskyy added 5 commits June 1, 2026 16:30
Replace the Shape internal implicit field attribute from `_func`/func to `_field`/field across the codebase and update all callers (require_func → require_field, evaluate, mesh paths, implicit ops, primitives). Rename immutable transform APIs on Shape (translate/rotate/scale → translated/rotated/scaled) and update tests accordingly. Enhance Phase with new constructors and features: Phase.from_implicit, Phase.from_grid (grid caching and nearest-neighbour wrapper), a cached grid shortcut, and an immutable rotated() transform (CAD- and field-backed handling) plus an internal _with_cad helper. Minor fix in meshbridge error check to use the new field property. Tests updated and a new test file added to cover Phase constructors and rotations. These changes standardize naming and add Tier-2 Phase functionality while updating tests to match the new API.
Move scipy.spatial.transform.Rotation import to module scope in microgen/phase.py (removing the local import inside Phase) and update tests to import pytest, Tpms, and surface_functions at the top. Also remove several in-test imports and minor whitespace cleanups. These are refactors to satisfy style/static checks and keep imports consistent; behavior is unchanged.
Rename immutable transform APIs to PyVista-style verbs and add optional inplace behavior. translated/scaled/rotated/tiled -> translate/scale/rotate/tile across Phase and Shape; transforms now accept inplace=False (default) to return a new Phase/Shape or inplace=True to mutate. Implement Phase.copy(), _invalidate_derived() and internal _apply_* workers to keep field, CAD, mesh and cached grid coherent. Rotation now accepts scipy.spatial.transform.Rotation (or a 3x3 matrix) and supports a pivot point; scaling uses a computed pivot (center_of_mass/mesh center). Tests and example updated to use the new names and Rotation imports. Notes: tile remains a producer (always returns new), rotations invalidate axis-aligned periodicity, and cached grids are cleared when necessary. Breaking change: public transform method names and signatures changed.
Add a shared affine helper module and wire affine transform support through shapes and phases.

- New microgen/shape/_affine.py: utilities for rotations, signed-permutation snapping, scale factors, transforming points/bounds/fields and period handling.
- Phase: introduce _grid_frame, _inside_nodes and unify transforms via _apply_affine; translate/rotate/scale now follow PyVista convention (inplace=False by default), keep/adjust iso and period correctly, transform CAD/surface/cached grids with homogeneous matrices, and fix cached-grid implicit array handling.
- Shape: document world-frame implicit field, add copy/_rebuild_field hooks, native-parameter scaling support, local-axis handling and composed transforms; many docstring clarifications.
- Shapes updated (Box, Capsule, Cylinder, Ellipsoid): use _field naming, add _native_params/_scale_params implementations so transforms can update native parameters when possible.
- CAD: optimize transform_geometry to use BRepBuilderAPI_Transform for similarity transforms to preserve analytic surfaces; fall back to GTransform for general linear maps.
- Docs/examples/tests: update tutorials.rst to document transforms, tweak example wording, and add tests for phase transforms.

These changes make translate/rotate/scale coherent across field/CAD/mesh/grid representations and enable accurate period/iso handling and native-parameter updates where applicable.
Centralize and rationalize affine transform logic across Shape and Phase. Introduces an AffineMap dataclass and new helpers in microgen.shape._affine (translation/rotation_about/scaling, rotation_matrix, orthogonality checks, and transform_field/pathways) so transforms are expressed and applied uniformly. Phase now uses a _transform/_apply_affine flow that applies AffineMap to field, bounds, iso, period, CAD, mesh and cached grids (including clipping of fields for non-permutation rotations). Grid handling and piece extraction were improved (_grid_frame, _bounds_from, find_objects), inertia is computed about the center of mass, and shallow-copy semantics were added (_shallow_copy). Shape transformation hooks were changed: subclasses now implement _scaled_params (returning parameter updates) and _apply_params, _rebuild_field became a callable attribute when present, and various shape classes were adapted to return parameter dicts instead of mutating in-place. Docstrings, example text, tests, and CI were updated (added tests/test_phase_transforms.py to the workflow) to match the new behavior and APIs.
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.

1 participant