@woosh/meep-engine 2.164.0 → 2.165.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/bundle-worker-terrain.js +1 -1
- package/package.json +1 -1
- package/src/core/binary/BitImage2.d.ts +91 -0
- package/src/core/binary/BitImage2.d.ts.map +1 -0
- package/src/core/binary/BitImage2.js +242 -0
- package/src/core/geom/2d/oriented-box/min_area_rect_2d.d.ts +22 -0
- package/src/core/geom/2d/oriented-box/min_area_rect_2d.d.ts.map +1 -0
- package/src/core/geom/2d/oriented-box/min_area_rect_2d.js +69 -0
- package/src/core/geom/2d/packing/skyline.d.ts +116 -0
- package/src/core/geom/2d/packing/skyline.d.ts.map +1 -0
- package/src/core/geom/2d/packing/skyline.js +258 -0
- package/src/core/geom/2d/triangle/tri2_rasterize_conservative.d.ts +18 -0
- package/src/core/geom/2d/triangle/tri2_rasterize_conservative.d.ts.map +1 -0
- package/src/core/geom/2d/triangle/tri2_rasterize_conservative.js +86 -0
- package/src/core/geom/3d/atlas/ATLAS_PORT_PLAN.md +486 -0
- package/src/core/geom/3d/atlas/BFF_PLAN.md +174 -0
- package/src/core/geom/3d/atlas/Chart.d.ts +58 -0
- package/src/core/geom/3d/atlas/Chart.d.ts.map +1 -0
- package/src/core/geom/3d/atlas/Chart.js +77 -0
- package/src/core/geom/3d/atlas/REVIEW_02.md +392 -0
- package/src/core/geom/3d/atlas/atlas_bench_lib.d.ts +73 -0
- package/src/core/geom/3d/atlas/atlas_bench_lib.d.ts.map +1 -0
- package/src/core/geom/3d/atlas/atlas_bench_lib.js +315 -0
- package/src/core/geom/3d/atlas/atlas_chart_type.d.ts +17 -0
- package/src/core/geom/3d/atlas/atlas_chart_type.d.ts.map +1 -0
- package/src/core/geom/3d/atlas/atlas_chart_type.js +16 -0
- package/src/core/geom/3d/atlas/atlas_compute_charts.d.ts +25 -0
- package/src/core/geom/3d/atlas/atlas_compute_charts.d.ts.map +1 -0
- package/src/core/geom/3d/atlas/atlas_compute_charts.js +188 -0
- package/src/core/geom/3d/atlas/atlas_extract_chart.d.ts +17 -0
- package/src/core/geom/3d/atlas/atlas_extract_chart.d.ts.map +1 -0
- package/src/core/geom/3d/atlas/atlas_extract_chart.js +107 -0
- package/src/core/geom/3d/atlas/atlas_generate.d.ts +39 -0
- package/src/core/geom/3d/atlas/atlas_generate.d.ts.map +1 -0
- package/src/core/geom/3d/atlas/atlas_generate.js +43 -0
- package/src/core/geom/3d/atlas/atlas_test_fixtures.d.ts +84 -0
- package/src/core/geom/3d/atlas/atlas_test_fixtures.d.ts.map +1 -0
- package/src/core/geom/3d/atlas/atlas_test_fixtures.js +266 -0
- package/src/core/geom/3d/atlas/atlas_write_chart_uvs.d.ts +25 -0
- package/src/core/geom/3d/atlas/atlas_write_chart_uvs.d.ts.map +1 -0
- package/src/core/geom/3d/atlas/atlas_write_chart_uvs.js +36 -0
- package/src/core/geom/3d/atlas/data/atlas_build_edge_dihedrals.d.ts +22 -0
- package/src/core/geom/3d/atlas/data/atlas_build_edge_dihedrals.d.ts.map +1 -0
- package/src/core/geom/3d/atlas/data/atlas_build_edge_dihedrals.js +62 -0
- package/src/core/geom/3d/atlas/data/atlas_build_edge_lengths.d.ts +9 -0
- package/src/core/geom/3d/atlas/data/atlas_build_edge_lengths.d.ts.map +1 -0
- package/src/core/geom/3d/atlas/data/atlas_build_edge_lengths.js +33 -0
- package/src/core/geom/3d/atlas/data/atlas_build_face_areas.d.ts +9 -0
- package/src/core/geom/3d/atlas/data/atlas_build_face_areas.d.ts.map +1 -0
- package/src/core/geom/3d/atlas/data/atlas_build_face_areas.js +50 -0
- package/src/core/geom/3d/atlas/io/atlas_mesh_weld_colocals.d.ts +27 -0
- package/src/core/geom/3d/atlas/io/atlas_mesh_weld_colocals.d.ts.map +1 -0
- package/src/core/geom/3d/atlas/io/atlas_mesh_weld_colocals.js +39 -0
- package/src/core/geom/3d/atlas/io/bt_loop_uv.d.ts +22 -0
- package/src/core/geom/3d/atlas/io/bt_loop_uv.d.ts.map +1 -0
- package/src/core/geom/3d/atlas/io/bt_loop_uv.js +57 -0
- package/src/core/geom/3d/atlas/pack/ChartPlacement.d.ts +36 -0
- package/src/core/geom/3d/atlas/pack/ChartPlacement.d.ts.map +1 -0
- package/src/core/geom/3d/atlas/pack/ChartPlacement.js +46 -0
- package/src/core/geom/3d/atlas/pack/atlas_pack_charts.d.ts +62 -0
- package/src/core/geom/3d/atlas/pack/atlas_pack_charts.d.ts.map +1 -0
- package/src/core/geom/3d/atlas/pack/atlas_pack_charts.js +551 -0
- package/src/core/geom/3d/atlas/param/atlas_chart_param_validity.d.ts +22 -0
- package/src/core/geom/3d/atlas/param/atlas_chart_param_validity.d.ts.map +1 -0
- package/src/core/geom/3d/atlas/param/atlas_chart_param_validity.js +73 -0
- package/src/core/geom/3d/atlas/param/atlas_chart_parameterize_bff.d.ts +37 -0
- package/src/core/geom/3d/atlas/param/atlas_chart_parameterize_bff.d.ts.map +1 -0
- package/src/core/geom/3d/atlas/param/atlas_chart_parameterize_bff.js +270 -0
- package/src/core/geom/3d/atlas/param/atlas_chart_parameterize_lscm.d.ts +23 -0
- package/src/core/geom/3d/atlas/param/atlas_chart_parameterize_lscm.d.ts.map +1 -0
- package/src/core/geom/3d/atlas/param/atlas_chart_parameterize_lscm.js +224 -0
- package/src/core/geom/3d/atlas/param/atlas_chart_parameterize_ortho.d.ts +14 -0
- package/src/core/geom/3d/atlas/param/atlas_chart_parameterize_ortho.d.ts.map +1 -0
- package/src/core/geom/3d/atlas/param/atlas_chart_parameterize_ortho.js +38 -0
- package/src/core/geom/3d/atlas/param/atlas_chart_stretch_metric.d.ts +22 -0
- package/src/core/geom/3d/atlas/param/atlas_chart_stretch_metric.d.ts.map +1 -0
- package/src/core/geom/3d/atlas/param/atlas_chart_stretch_metric.js +86 -0
- package/src/core/geom/3d/atlas/param/atlas_piecewise_resegment.d.ts +20 -0
- package/src/core/geom/3d/atlas/param/atlas_piecewise_resegment.d.ts.map +1 -0
- package/src/core/geom/3d/atlas/param/atlas_piecewise_resegment.js +183 -0
- package/src/core/geom/3d/atlas/param/fit_plane_basis.d.ts +27 -0
- package/src/core/geom/3d/atlas/param/fit_plane_basis.d.ts.map +1 -0
- package/src/core/geom/3d/atlas/param/fit_plane_basis.js +66 -0
- package/src/core/geom/3d/atlas/segment/RegionGraph.d.ts +31 -0
- package/src/core/geom/3d/atlas/segment/RegionGraph.d.ts.map +1 -0
- package/src/core/geom/3d/atlas/segment/RegionGraph.js +40 -0
- package/src/core/geom/3d/atlas/segment/atlas_build_region_graph.d.ts +23 -0
- package/src/core/geom/3d/atlas/segment/atlas_build_region_graph.d.ts.map +1 -0
- package/src/core/geom/3d/atlas/segment/atlas_build_region_graph.js +136 -0
- package/src/core/geom/3d/atlas/segment/atlas_compute_planar_regions.d.ts +24 -0
- package/src/core/geom/3d/atlas/segment/atlas_compute_planar_regions.d.ts.map +1 -0
- package/src/core/geom/3d/atlas/segment/atlas_compute_planar_regions.js +77 -0
- package/src/core/geom/3d/atlas/segment/atlas_merge_charts.d.ts +27 -0
- package/src/core/geom/3d/atlas/segment/atlas_merge_charts.d.ts.map +1 -0
- package/src/core/geom/3d/atlas/segment/atlas_merge_charts.js +113 -0
- package/src/core/geom/3d/atlas/segment/atlas_segment_charts.d.ts +44 -0
- package/src/core/geom/3d/atlas/segment/atlas_segment_charts.d.ts.map +1 -0
- package/src/core/geom/3d/atlas/segment/atlas_segment_charts.js +275 -0
- package/src/core/geom/3d/atlas/segment/atlas_segment_charts_atomic.d.ts +22 -0
- package/src/core/geom/3d/atlas/segment/atlas_segment_charts_atomic.d.ts.map +1 -0
- package/src/core/geom/3d/atlas/segment/atlas_segment_charts_atomic.js +199 -0
- package/src/core/geom/3d/line/line3_compute_point_segment_point_distance_unfolded.d.ts +32 -0
- package/src/core/geom/3d/line/line3_compute_point_segment_point_distance_unfolded.d.ts.map +1 -0
- package/src/core/geom/3d/line/line3_compute_point_segment_point_distance_unfolded.js +64 -0
- package/src/core/geom/3d/mat4/m4_from_rotation_translation_scale.d.ts +20 -0
- package/src/core/geom/3d/mat4/m4_from_rotation_translation_scale.d.ts.map +1 -0
- package/src/core/geom/3d/mat4/m4_from_rotation_translation_scale.js +66 -0
- package/src/core/geom/3d/sphere/harmonics/sh3_dering_optimize_positive.d.ts.map +1 -1
- package/src/core/geom/3d/sphere/harmonics/sh3_dering_optimize_positive.js +13 -11
- package/src/core/geom/3d/sphere/sphere_compute_bounding_of_2_spheres.d.ts.map +1 -1
- package/src/core/geom/3d/sphere/sphere_compute_bounding_of_2_spheres.js +4 -3
- package/src/core/geom/3d/topology/simplify/decimate_edge_collapse_snap.d.ts.map +1 -1
- package/src/core/geom/3d/topology/simplify/decimate_edge_collapse_snap.js +4 -3
- package/src/core/geom/3d/topology/simplify/quadratic/Quadric3.d.ts.map +1 -1
- package/src/core/geom/3d/topology/simplify/quadratic/Quadric3.js +4 -3
- package/src/core/geom/3d/topology/simplify/quadratic/apply_border_penalty_to_vertex_quadrics.d.ts.map +1 -1
- package/src/core/geom/3d/topology/simplify/quadratic/apply_border_penalty_to_vertex_quadrics.js +10 -6
- package/src/core/geom/3d/topology/struct/TopoMesh.js +2 -2
- package/src/core/geom/3d/topology/struct/TopoTriangle.d.ts +0 -2
- package/src/core/geom/3d/topology/struct/TopoTriangle.d.ts.map +1 -1
- package/src/core/geom/3d/topology/struct/TopoTriangle.js +2 -2
- package/src/core/geom/3d/topology/struct/binary/query/bt_mesh_face_find_path_polyanya.d.ts.map +1 -1
- package/src/core/geom/3d/topology/struct/binary/query/bt_mesh_face_find_path_polyanya.js +8 -27
- package/src/core/geom/vec3/v3_cotangent.d.ts +20 -0
- package/src/core/geom/vec3/v3_cotangent.d.ts.map +1 -0
- package/src/core/geom/vec3/v3_cotangent.js +29 -0
- package/src/core/geom/vec3/v3_matrix3_multiply.d.ts +19 -0
- package/src/core/geom/vec3/v3_matrix3_multiply.d.ts.map +1 -0
- package/src/core/geom/vec3/v3_matrix3_multiply.js +30 -0
- package/src/core/geom/vec3/v3_multiply.d.ts +16 -0
- package/src/core/geom/vec3/v3_multiply.d.ts.map +1 -0
- package/src/core/geom/vec3/v3_multiply.js +19 -0
- package/src/core/math/linalg/cg/cg_solve.d.ts +24 -0
- package/src/core/math/linalg/cg/cg_solve.d.ts.map +1 -0
- package/src/core/math/linalg/cg/cg_solve.js +106 -0
- package/src/core/math/linalg/cg/cg_solve_normal_equations.d.ts +21 -0
- package/src/core/math/linalg/cg/cg_solve_normal_equations.d.ts.map +1 -0
- package/src/core/math/linalg/cg/cg_solve_normal_equations.js +59 -0
- package/src/core/math/linalg/eigen/matrix_symmetric_3x3_eigen.d.ts +19 -0
- package/src/core/math/linalg/eigen/matrix_symmetric_3x3_eigen.d.ts.map +1 -0
- package/src/core/math/linalg/eigen/matrix_symmetric_3x3_eigen.js +117 -0
- package/src/core/math/linalg/sparse/SparseMatrixCSR.d.ts +50 -0
- package/src/core/math/linalg/sparse/SparseMatrixCSR.d.ts.map +1 -0
- package/src/core/math/linalg/sparse/SparseMatrixCSR.js +88 -0
- package/src/core/math/linalg/sparse/spm_matvec.d.ts +9 -0
- package/src/core/math/linalg/sparse/spm_matvec.d.ts.map +1 -0
- package/src/core/math/linalg/sparse/spm_matvec.js +22 -0
- package/src/core/math/linalg/sparse/spm_matvec_transpose.d.ts +12 -0
- package/src/core/math/linalg/sparse/spm_matvec_transpose.d.ts.map +1 -0
- package/src/core/math/linalg/sparse/spm_matvec_transpose.js +29 -0
- package/src/core/math/physics/mie/MIE_PARTICLES_STANDARD_PRECOMPUTED.d.ts +39 -0
- package/src/core/math/physics/mie/MIE_PARTICLES_STANDARD_PRECOMPUTED.js +22 -1
- package/src/core/math/physics/mie/compute_mie_particle_properties_rgb.d.ts.map +1 -1
- package/src/core/math/physics/mie/compute_mie_particle_properties_rgb.js +32 -9
- package/src/core/math/physics/mie/compute_mie_phase.d.ts +2 -3
- package/src/core/math/physics/mie/compute_mie_phase.d.ts.map +1 -1
- package/src/core/math/physics/mie/compute_mie_phase.js +1 -3
- package/src/core/math/physics/mie/lorenz_mie_coefs.d.ts +0 -1
- package/src/core/math/physics/mie/lorenz_mie_coefs.d.ts.map +1 -1
- package/src/core/math/physics/mie/lorenz_mie_coefs.js +0 -7
- package/src/engine/ecs/attachment/TransformAttachmentBinding.js +3 -3
- package/src/engine/ecs/gui/hud/HeadsUpDisplaySystem.js +2 -2
- package/src/engine/ecs/terrain/ecs/Terrain.d.ts.map +1 -1
- package/src/engine/ecs/terrain/ecs/Terrain.js +4 -3
- package/src/engine/ecs/terrain/tiles/TerrainTile.js +2 -2
- package/src/engine/ecs/terrain/tiles/TerrainTileManager.d.ts.map +1 -1
- package/src/engine/ecs/terrain/tiles/TerrainTileManager.js +9 -8
- package/src/engine/graphics/GraphicsEngine.d.ts.map +1 -1
- package/src/engine/graphics/GraphicsEngine.js +2 -1
- package/src/engine/graphics/ecs/decal/v2/FPDecalSystem.js +2 -2
- package/src/engine/graphics/ecs/decal/v2/prototypeDecalSystem.js +2 -2
- package/src/engine/graphics/ecs/mesh-v2/ShadedGeometry.js +2 -2
- package/src/engine/graphics/ecs/mesh-v2/ShadedGeometrySystem.d.ts.map +1 -1
- package/src/engine/graphics/ecs/mesh-v2/ShadedGeometrySystem.js +0 -1
- package/src/engine/graphics/ecs/path/tube/build/computeFrenetFrames.d.ts.map +1 -1
- package/src/engine/graphics/ecs/path/tube/build/computeFrenetFrames.js +8 -7
- package/src/engine/graphics/geometry/MikkT/AvgTSpace.d.ts.map +1 -1
- package/src/engine/graphics/geometry/MikkT/AvgTSpace.js +11 -6
- package/src/engine/graphics/geometry/MikkT/BuildNeighborsFast.d.ts.map +1 -1
- package/src/engine/graphics/geometry/MikkT/BuildNeighborsFast.js +2 -3
- package/src/engine/graphics/geometry/MikkT/CalcTexArea.d.ts.map +1 -1
- package/src/engine/graphics/geometry/MikkT/CalcTexArea.js +3 -4
- package/src/engine/graphics/geometry/MikkT/DegenEpilogue.js +4 -4
- package/src/engine/graphics/geometry/MikkT/EvalTspace.d.ts.map +1 -1
- package/src/engine/graphics/geometry/MikkT/EvalTspace.js +11 -8
- package/src/engine/graphics/geometry/MikkT/GenerateSharedVerticesIndexList.d.ts.map +1 -1
- package/src/engine/graphics/geometry/MikkT/GenerateSharedVerticesIndexList.js +7 -8
- package/src/engine/graphics/geometry/MikkT/GenerateTSpaces.js +8 -8
- package/src/engine/graphics/geometry/MikkT/InitTriInfo.d.ts.map +1 -1
- package/src/engine/graphics/geometry/MikkT/InitTriInfo.js +30 -25
- package/src/engine/graphics/geometry/MikkT/MikkTSpace.js +7 -7
- package/src/engine/graphics/geometry/MikkT/NormalizeSafe.d.ts +0 -1
- package/src/engine/graphics/geometry/MikkT/NormalizeSafe.d.ts.map +1 -1
- package/src/engine/graphics/geometry/MikkT/NormalizeSafe.js +6 -4
- package/src/engine/graphics/geometry/MikkT/STSpace.d.ts +0 -2
- package/src/engine/graphics/geometry/MikkT/STSpace.d.ts.map +1 -1
- package/src/engine/graphics/geometry/MikkT/STSpace.js +3 -3
- package/src/engine/graphics/geometry/MikkT/v3_scale_dot_sub_normalize.d.ts +0 -2
- package/src/engine/graphics/geometry/MikkT/v3_scale_dot_sub_normalize.d.ts.map +1 -1
- package/src/engine/graphics/geometry/MikkT/v3_scale_dot_sub_normalize.js +0 -1
- package/src/engine/graphics/impostors/octahedral/ImpostorBaker.d.ts +0 -2
- package/src/engine/graphics/impostors/octahedral/ImpostorBaker.d.ts.map +1 -1
- package/src/engine/graphics/impostors/octahedral/ImpostorBaker.js +4 -3
- package/src/engine/graphics/impostors/octahedral/grid/HemiOctahedralUvEncoder.js +2 -2
- package/src/engine/graphics/impostors/octahedral/grid/UvEncoder.d.ts +17 -7
- package/src/engine/graphics/impostors/voxel/VoxelImpostorBaker.js +2 -2
- package/src/engine/graphics/particles/particular/engine/utils/volume/ParticleVolume.js +3 -3
- package/src/engine/graphics/particles/particular/engine/utils/volume/prototypeParticleVolume.js +4 -3
- package/src/engine/graphics/render/forward_plus/LightManager.js +2 -2
- package/src/engine/graphics/render/forward_plus/model/Decal.d.ts +0 -2
- package/src/engine/graphics/render/forward_plus/model/Decal.d.ts.map +1 -1
- package/src/engine/graphics/render/forward_plus/model/Decal.js +3 -3
- package/src/engine/graphics/render/forward_plus/prototype/prototypeLightManager.js +4 -3
- package/src/engine/graphics/render/visibility/hiz/prototypeHiZ.js +6 -4
- package/src/engine/graphics/sh3/lightmap/ARTIFACTS_PLAN.md +146 -0
- package/src/engine/graphics/sh3/lightmap/CODE_REVIEW.md +121 -0
- package/src/engine/graphics/sh3/lightmap/LIGHTMAPPER_REVIEW.md +183 -0
- package/src/engine/graphics/sh3/lightmap/bake_lightmap_for_scene.d.ts +90 -0
- package/src/engine/graphics/sh3/lightmap/bake_lightmap_for_scene.d.ts.map +1 -0
- package/src/engine/graphics/sh3/lightmap/bake_lightmap_for_scene.js +678 -0
- package/src/engine/graphics/sh3/lightmap/lightmap_build_geometry.d.ts +32 -0
- package/src/engine/graphics/sh3/lightmap/lightmap_build_geometry.d.ts.map +1 -0
- package/src/engine/graphics/sh3/lightmap/lightmap_build_geometry.js +155 -0
- package/src/engine/graphics/sh3/lightmap/lightmap_denoise.d.ts +49 -0
- package/src/engine/graphics/sh3/lightmap/lightmap_denoise.d.ts.map +1 -0
- package/src/engine/graphics/sh3/lightmap/lightmap_denoise.js +136 -0
- package/src/engine/graphics/sh3/lightmap/lightmap_dilate.d.ts +19 -0
- package/src/engine/graphics/sh3/lightmap/lightmap_dilate.d.ts.map +1 -0
- package/src/engine/graphics/sh3/lightmap/lightmap_dilate.js +89 -0
- package/src/engine/graphics/sh3/lightmap/lightmap_gather.d.ts +54 -0
- package/src/engine/graphics/sh3/lightmap/lightmap_gather.d.ts.map +1 -0
- package/src/engine/graphics/sh3/lightmap/lightmap_gather.js +168 -0
- package/src/engine/graphics/sh3/lightmap/lightmap_rasterize_triangle.d.ts +30 -0
- package/src/engine/graphics/sh3/lightmap/lightmap_rasterize_triangle.d.ts.map +1 -0
- package/src/engine/graphics/sh3/lightmap/lightmap_rasterize_triangle.js +145 -0
- package/src/engine/graphics/sh3/lightmap/lightmap_seam_fix.d.ts +38 -0
- package/src/engine/graphics/sh3/lightmap/lightmap_seam_fix.d.ts.map +1 -0
- package/src/engine/graphics/sh3/lightmap/lightmap_seam_fix.js +152 -0
- package/src/engine/graphics/sh3/lightmap/prototypeLightmapBaker.d.ts +2 -0
- package/src/engine/graphics/sh3/lightmap/prototypeLightmapBaker.d.ts.map +1 -0
- package/src/engine/graphics/sh3/lightmap/prototypeLightmapBaker.js +186 -0
- package/src/engine/graphics/sh3/path_tracer/PathTracedMesh.d.ts.map +1 -1
- package/src/engine/graphics/sh3/path_tracer/PathTracedMesh.js +2 -2
- package/src/engine/graphics/sh3/path_tracer/PathTracer.js +2 -2
- package/src/engine/graphics/sh3/path_tracer/prepare_scene_gltf.d.ts.map +1 -1
- package/src/engine/graphics/sh3/path_tracer/prepare_scene_gltf.js +6 -4
- package/src/engine/graphics/sh3/path_tracer/prototypePathTracer.js +3 -3
- package/src/engine/graphics/sh3/path_tracer/texture/sample_material.d.ts.map +1 -1
- package/src/engine/graphics/sh3/path_tracer/texture/sample_material.js +5 -4
- package/src/engine/graphics/sh3/sky/hosek/prototype_hosek.js +2 -2
- package/src/engine/input/devices/KeyboardDevice.d.ts +61 -14
- package/src/engine/input/devices/KeyboardDevice.d.ts.map +1 -1
- package/src/engine/input/devices/KeyboardDevice.js +41 -15
- package/src/engine/input/devices/isHTMLElementFocusable.d.ts.map +1 -1
- package/src/engine/input/devices/isHTMLElementFocusable.js +2 -9
- package/src/engine/sound/simulation/prototypeAcousticSolver.js +261 -143
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
import { Uint32Heap4 } from "../../../../../../collection/heap/Uint32Heap4.js";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
line2_segment_intersection_fraction_2d
|
|
4
|
+
} from "../../../../../2d/line/line2_segment_intersection_fraction_2d.js";
|
|
3
5
|
import { tri2_signed_area } from "../../../../../2d/triangle/tri2_signed_area.js";
|
|
4
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
line3_compute_point_segment_point_distance_unfolded
|
|
8
|
+
} from "../../../../../3d/line/line3_compute_point_segment_point_distance_unfolded.js";
|
|
5
9
|
import { v2_distance } from "../../../../../vec2/v2_distance.js";
|
|
10
|
+
import { NULL_POINTER } from "../BinaryTopology.js";
|
|
6
11
|
|
|
7
12
|
/*
|
|
8
13
|
* Polyanya: exact any-angle shortest path on a triangle navmesh.
|
|
@@ -79,30 +84,6 @@ function touch_distance(rx, ry, i0x, i0y, i1x, i1y, gx, gy) {
|
|
|
79
84
|
);
|
|
80
85
|
}
|
|
81
86
|
|
|
82
|
-
/**
|
|
83
|
-
* Shortest root->interval->goal measured with straight 3D chords (admissible heuristic: it is the
|
|
84
|
-
* 3D-space unfolding of the two segments across the interval's line, always <= the on-surface geodesic).
|
|
85
|
-
*/
|
|
86
|
-
function touch_distance_3d(rx, ry, rz, i0x, i0y, i0z, i1x, i1y, i1z, gx, gy, gz) {
|
|
87
|
-
const dx = i1x - i0x, dy = i1y - i0y, dz = i1z - i0z;
|
|
88
|
-
const dlen2 = dx * dx + dy * dy + dz * dz;
|
|
89
|
-
const viaI0 = Math.hypot(rx - i0x, ry - i0y, rz - i0z) + Math.hypot(gx - i0x, gy - i0y, gz - i0z);
|
|
90
|
-
if (dlen2 < 1e-18) return viaI0;
|
|
91
|
-
|
|
92
|
-
const dlen = Math.sqrt(dlen2), ux = dx / dlen, uy = dy / dlen, uz = dz / dlen;
|
|
93
|
-
const rt = (rx - i0x) * ux + (ry - i0y) * uy + (rz - i0z) * uz;
|
|
94
|
-
const rperp = Math.hypot(rx - i0x - rt * ux, ry - i0y - rt * uy, rz - i0z - rt * uz);
|
|
95
|
-
const gt = (gx - i0x) * ux + (gy - i0y) * uy + (gz - i0z) * uz;
|
|
96
|
-
const gperp = Math.hypot(gx - i0x - gt * ux, gy - i0y - gt * uy, gz - i0z - gt * uz);
|
|
97
|
-
|
|
98
|
-
const denom = rperp + gperp;
|
|
99
|
-
const xs = denom < 1e-12 ? rt : rt + (gt - rt) * rperp / denom; // edge crossing of the unfolded line
|
|
100
|
-
if (xs >= 0 && xs <= dlen) return Math.hypot(gt - rt, denom);
|
|
101
|
-
|
|
102
|
-
const viaI1 = Math.hypot(rx - i1x, ry - i1y, rz - i1z) + Math.hypot(gx - i1x, gy - i1y, gz - i1z);
|
|
103
|
-
return Math.min(viaI0, viaI1);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
87
|
// ---- mesh helpers ----------------------------------------------------------------------------------
|
|
107
88
|
|
|
108
89
|
const _va = new Float64Array(3), _vb = new Float64Array(3), _vc = new Float64Array(3);
|
|
@@ -660,7 +641,7 @@ function emit_node(topology, neighbour, Pv, Qv, Px, Py, Qx, Qy, rx, ry, rootVid,
|
|
|
660
641
|
else { topology.vertex_read_coordinate(_qa, 0, rootVid); r3x = _qa[0]; r3y = _qa[1]; r3z = _qa[2]; }
|
|
661
642
|
topology.vertex_read_coordinate(_va, 0, Pv);
|
|
662
643
|
topology.vertex_read_coordinate(_vb, 0, Qv);
|
|
663
|
-
const h =
|
|
644
|
+
const h = line3_compute_point_segment_point_distance_unfolded(
|
|
664
645
|
r3x, r3y, r3z,
|
|
665
646
|
_va[0] + t0 * (_vb[0] - _va[0]), _va[1] + t0 * (_vb[1] - _va[1]), _va[2] + t0 * (_vb[2] - _va[2]),
|
|
666
647
|
_va[0] + t1 * (_vb[0] - _va[0]), _va[1] + t1 * (_vb[1] - _va[1]), _va[2] + t1 * (_vb[2] - _va[2]),
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cotangent of the angle between two 3D vectors `a` and `b`.
|
|
3
|
+
*
|
|
4
|
+
* cot(θ) = cos(θ) / sin(θ) = (a · b) / |a × b|
|
|
5
|
+
*
|
|
6
|
+
* This is the building block of the cotangent-weight Laplacian and the
|
|
7
|
+
* discrete conformal energy: to weight the mesh edge opposite a triangle
|
|
8
|
+
* corner, pass the two edge vectors emanating from that corner.
|
|
9
|
+
*
|
|
10
|
+
* Precondition: `a` and `b` are non-degenerate and non-parallel (a real
|
|
11
|
+
* triangle corner). On a degenerate corner `|a × b|` is 0 and the result is
|
|
12
|
+
* non-finite — callers exclude degenerate faces upstream rather than guarding
|
|
13
|
+
* here.
|
|
14
|
+
*
|
|
15
|
+
* @param {number} ax @param {number} ay @param {number} az
|
|
16
|
+
* @param {number} bx @param {number} by @param {number} bz
|
|
17
|
+
* @returns {number}
|
|
18
|
+
*/
|
|
19
|
+
export function v3_cotangent(ax: number, ay: number, az: number, bx: number, by: number, bz: number): number;
|
|
20
|
+
//# sourceMappingURL=v3_cotangent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"v3_cotangent.d.ts","sourceRoot":"","sources":["../../../../../src/core/geom/vec3/v3_cotangent.js"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;GAiBG;AACH,iCAJW,MAAM,MAAa,MAAM,MAAa,MAAM,MAC5C,MAAM,MAAa,MAAM,MAAa,MAAM,GAC1C,MAAM,CAUlB"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { v3_dot } from "./v3_dot.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Cotangent of the angle between two 3D vectors `a` and `b`.
|
|
5
|
+
*
|
|
6
|
+
* cot(θ) = cos(θ) / sin(θ) = (a · b) / |a × b|
|
|
7
|
+
*
|
|
8
|
+
* This is the building block of the cotangent-weight Laplacian and the
|
|
9
|
+
* discrete conformal energy: to weight the mesh edge opposite a triangle
|
|
10
|
+
* corner, pass the two edge vectors emanating from that corner.
|
|
11
|
+
*
|
|
12
|
+
* Precondition: `a` and `b` are non-degenerate and non-parallel (a real
|
|
13
|
+
* triangle corner). On a degenerate corner `|a × b|` is 0 and the result is
|
|
14
|
+
* non-finite — callers exclude degenerate faces upstream rather than guarding
|
|
15
|
+
* here.
|
|
16
|
+
*
|
|
17
|
+
* @param {number} ax @param {number} ay @param {number} az
|
|
18
|
+
* @param {number} bx @param {number} by @param {number} bz
|
|
19
|
+
* @returns {number}
|
|
20
|
+
*/
|
|
21
|
+
export function v3_cotangent(ax, ay, az, bx, by, bz) {
|
|
22
|
+
const cx = ay * bz - az * by;
|
|
23
|
+
const cy = az * bx - ax * bz;
|
|
24
|
+
const cz = ax * by - ay * bx;
|
|
25
|
+
|
|
26
|
+
const sin_length = Math.sqrt(cx * cx + cy * cy + cz * cz);
|
|
27
|
+
|
|
28
|
+
return v3_dot(ax, ay, az, bx, by, bz) / sin_length;
|
|
29
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Transform a 3d vector by a 3x3 (column-major) matrix. `output = mat3 * input`.
|
|
3
|
+
*
|
|
4
|
+
* Unlike {@link v3_matrix3_rotate} this does NOT renormalize the result, so it is
|
|
5
|
+
* suitable for transforming positions / arbitrary vectors (not just directions).
|
|
6
|
+
* Companion to {@link v3_matrix4_multiply}. Reads the input components up front, so
|
|
7
|
+
* `output` may alias `input`. Allocation-free.
|
|
8
|
+
*
|
|
9
|
+
* @param {number[]|Float32Array|Float64Array} output
|
|
10
|
+
* @param {number} output_offset
|
|
11
|
+
* @param {number[]|Float32Array|Float64Array} input
|
|
12
|
+
* @param {number} input_offset
|
|
13
|
+
* @param {number[]|Float32Array|Float64Array} mat3 column-major 3x3 matrix
|
|
14
|
+
*
|
|
15
|
+
* @author Alex Goldring
|
|
16
|
+
* @copyright Company Named Limited (c) 2026
|
|
17
|
+
*/
|
|
18
|
+
export function v3_matrix3_multiply(output: number[] | Float32Array | Float64Array, output_offset: number, input: number[] | Float32Array | Float64Array, input_offset: number, mat3: number[] | Float32Array | Float64Array): void;
|
|
19
|
+
//# sourceMappingURL=v3_matrix3_multiply.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"v3_matrix3_multiply.d.ts","sourceRoot":"","sources":["../../../../../src/core/geom/vec3/v3_matrix3_multiply.js"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,4CATW,MAAM,EAAE,GAAC,YAAY,GAAC,YAAY,iBAClC,MAAM,SACN,MAAM,EAAE,GAAC,YAAY,GAAC,YAAY,gBAClC,MAAM,QACN,MAAM,EAAE,GAAC,YAAY,GAAC,YAAY,QAiB5C"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Transform a 3d vector by a 3x3 (column-major) matrix. `output = mat3 * input`.
|
|
3
|
+
*
|
|
4
|
+
* Unlike {@link v3_matrix3_rotate} this does NOT renormalize the result, so it is
|
|
5
|
+
* suitable for transforming positions / arbitrary vectors (not just directions).
|
|
6
|
+
* Companion to {@link v3_matrix4_multiply}. Reads the input components up front, so
|
|
7
|
+
* `output` may alias `input`. Allocation-free.
|
|
8
|
+
*
|
|
9
|
+
* @param {number[]|Float32Array|Float64Array} output
|
|
10
|
+
* @param {number} output_offset
|
|
11
|
+
* @param {number[]|Float32Array|Float64Array} input
|
|
12
|
+
* @param {number} input_offset
|
|
13
|
+
* @param {number[]|Float32Array|Float64Array} mat3 column-major 3x3 matrix
|
|
14
|
+
*
|
|
15
|
+
* @author Alex Goldring
|
|
16
|
+
* @copyright Company Named Limited (c) 2026
|
|
17
|
+
*/
|
|
18
|
+
export function v3_matrix3_multiply(
|
|
19
|
+
output, output_offset,
|
|
20
|
+
input, input_offset,
|
|
21
|
+
mat3
|
|
22
|
+
) {
|
|
23
|
+
const x = input[input_offset];
|
|
24
|
+
const y = input[input_offset + 1];
|
|
25
|
+
const z = input[input_offset + 2];
|
|
26
|
+
|
|
27
|
+
output[output_offset] = mat3[0] * x + mat3[3] * y + mat3[6] * z;
|
|
28
|
+
output[output_offset + 1] = mat3[1] * x + mat3[4] * y + mat3[7] * z;
|
|
29
|
+
output[output_offset + 2] = mat3[2] * x + mat3[5] * y + mat3[8] * z;
|
|
30
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Component-wise vector product `a * b`, written to `result[result_offset .. result_offset+2]`.
|
|
3
|
+
*
|
|
4
|
+
* Scalar-argument, out-parameter form: lets callers multiply two vectors straight
|
|
5
|
+
* into a scratch buffer (or in place) without allocating a temporary. Allocation-free.
|
|
6
|
+
*
|
|
7
|
+
* @param {number[]|Float32Array|Float64Array} result destination
|
|
8
|
+
* @param {number} result_offset offset into `result`
|
|
9
|
+
* @param {number} ax @param {number} ay @param {number} az first factor
|
|
10
|
+
* @param {number} bx @param {number} by @param {number} bz second factor
|
|
11
|
+
*
|
|
12
|
+
* @author Alex Goldring
|
|
13
|
+
* @copyright Company Named Limited (c) 2026
|
|
14
|
+
*/
|
|
15
|
+
export function v3_multiply(result: number[] | Float32Array | Float64Array, result_offset: number, ax: number, ay: number, az: number, bx: number, by: number, bz: number): void;
|
|
16
|
+
//# sourceMappingURL=v3_multiply.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"v3_multiply.d.ts","sourceRoot":"","sources":["../../../../../src/core/geom/vec3/v3_multiply.js"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,oCARW,MAAM,EAAE,GAAC,YAAY,GAAC,YAAY,iBAClC,MAAM,MACN,MAAM,MAAa,MAAM,MAAa,MAAM,MAC5C,MAAM,MAAa,MAAM,MAAa,MAAM,QAStD"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Component-wise vector product `a * b`, written to `result[result_offset .. result_offset+2]`.
|
|
3
|
+
*
|
|
4
|
+
* Scalar-argument, out-parameter form: lets callers multiply two vectors straight
|
|
5
|
+
* into a scratch buffer (or in place) without allocating a temporary. Allocation-free.
|
|
6
|
+
*
|
|
7
|
+
* @param {number[]|Float32Array|Float64Array} result destination
|
|
8
|
+
* @param {number} result_offset offset into `result`
|
|
9
|
+
* @param {number} ax @param {number} ay @param {number} az first factor
|
|
10
|
+
* @param {number} bx @param {number} by @param {number} bz second factor
|
|
11
|
+
*
|
|
12
|
+
* @author Alex Goldring
|
|
13
|
+
* @copyright Company Named Limited (c) 2026
|
|
14
|
+
*/
|
|
15
|
+
export function v3_multiply(result, result_offset, ax, ay, az, bx, by, bz) {
|
|
16
|
+
result[result_offset] = ax * bx;
|
|
17
|
+
result[result_offset + 1] = ay * by;
|
|
18
|
+
result[result_offset + 2] = az * bz;
|
|
19
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Conjugate Gradient solve of `A x = b` for a symmetric positive-definite
|
|
3
|
+
* operator `A`, supplied as a matrix-free callback. This is the generic core
|
|
4
|
+
* shared by the cotangent-Laplacian harmonic solve and the LSCM normal
|
|
5
|
+
* equations (via {@link cg_solve_normal_equations}).
|
|
6
|
+
*
|
|
7
|
+
* `x` is both the initial guess and the output (warm-start it with a prior
|
|
8
|
+
* solution to cut iterations; zero-fill for a cold start). Convergence is the
|
|
9
|
+
* relative residual: the solve stops when `‖r‖ <= tolerance · ‖r0‖`.
|
|
10
|
+
*
|
|
11
|
+
* Determinism: reductions run in fixed index order with no wall-clock exit, so
|
|
12
|
+
* the result is bit-reproducible for a given `apply_A`.
|
|
13
|
+
*
|
|
14
|
+
* @param {Float64Array} x length n; initial guess in, solution out
|
|
15
|
+
* @param {(out: Float64Array, vec: Float64Array) => void} apply_A computes out = A·vec
|
|
16
|
+
* over the first n entries
|
|
17
|
+
* @param {Float64Array} b right-hand side, length n
|
|
18
|
+
* @param {number} n system size
|
|
19
|
+
* @param {number} max_iterations hard cap on iterations
|
|
20
|
+
* @param {number} tolerance relative residual target in [0, 1]; 0 runs to max_iterations
|
|
21
|
+
* @returns {number} iterations performed
|
|
22
|
+
*/
|
|
23
|
+
export function cg_solve(x: Float64Array, apply_A: (out: Float64Array, vec: Float64Array) => void, b: Float64Array, n: number, max_iterations: number, tolerance: number): number;
|
|
24
|
+
//# sourceMappingURL=cg_solve.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cg_solve.d.ts","sourceRoot":"","sources":["../../../../../../src/core/math/linalg/cg/cg_solve.js"],"names":[],"mappings":"AAwBA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,4BATW,YAAY,iBACN,YAAY,OAAO,YAAY,KAAK,IAAI,KAE9C,YAAY,KACZ,MAAM,kBACN,MAAM,aACN,MAAM,GACJ,MAAM,CA6DlB"}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Module-static scratch vectors, grown on demand and reused across calls.
|
|
3
|
+
* The solver is therefore NOT re-entrant: `apply_A` must not itself call
|
|
4
|
+
* `cg_solve` (it may call lower-level matvecs freely).
|
|
5
|
+
*/
|
|
6
|
+
let _r = new Float64Array(0);
|
|
7
|
+
let _p = new Float64Array(0);
|
|
8
|
+
let _Ap = new Float64Array(0);
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Grow the module-static scratch vectors (`_r`, `_p`, `_Ap`) so each holds at
|
|
12
|
+
* least `n` entries. A no-op once they are large enough; existing contents are
|
|
13
|
+
* not preserved, since each `cg_solve` re-initializes them.
|
|
14
|
+
*
|
|
15
|
+
* @param {number} n required minimum length
|
|
16
|
+
*/
|
|
17
|
+
function ensure_scratch(n) {
|
|
18
|
+
if (_r.length < n) {
|
|
19
|
+
_r = new Float64Array(n);
|
|
20
|
+
_p = new Float64Array(n);
|
|
21
|
+
_Ap = new Float64Array(n);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Conjugate Gradient solve of `A x = b` for a symmetric positive-definite
|
|
27
|
+
* operator `A`, supplied as a matrix-free callback. This is the generic core
|
|
28
|
+
* shared by the cotangent-Laplacian harmonic solve and the LSCM normal
|
|
29
|
+
* equations (via {@link cg_solve_normal_equations}).
|
|
30
|
+
*
|
|
31
|
+
* `x` is both the initial guess and the output (warm-start it with a prior
|
|
32
|
+
* solution to cut iterations; zero-fill for a cold start). Convergence is the
|
|
33
|
+
* relative residual: the solve stops when `‖r‖ <= tolerance · ‖r0‖`.
|
|
34
|
+
*
|
|
35
|
+
* Determinism: reductions run in fixed index order with no wall-clock exit, so
|
|
36
|
+
* the result is bit-reproducible for a given `apply_A`.
|
|
37
|
+
*
|
|
38
|
+
* @param {Float64Array} x length n; initial guess in, solution out
|
|
39
|
+
* @param {(out: Float64Array, vec: Float64Array) => void} apply_A computes out = A·vec
|
|
40
|
+
* over the first n entries
|
|
41
|
+
* @param {Float64Array} b right-hand side, length n
|
|
42
|
+
* @param {number} n system size
|
|
43
|
+
* @param {number} max_iterations hard cap on iterations
|
|
44
|
+
* @param {number} tolerance relative residual target in [0, 1]; 0 runs to max_iterations
|
|
45
|
+
* @returns {number} iterations performed
|
|
46
|
+
*/
|
|
47
|
+
export function cg_solve(x, apply_A, b, n, max_iterations, tolerance) {
|
|
48
|
+
ensure_scratch(n);
|
|
49
|
+
|
|
50
|
+
const r = _r;
|
|
51
|
+
const p = _p;
|
|
52
|
+
const Ap = _Ap;
|
|
53
|
+
|
|
54
|
+
apply_A(Ap, x);
|
|
55
|
+
|
|
56
|
+
let rs = 0;
|
|
57
|
+
for (let i = 0; i < n; i++) {
|
|
58
|
+
const ri = b[i] - Ap[i];
|
|
59
|
+
r[i] = ri;
|
|
60
|
+
p[i] = ri;
|
|
61
|
+
rs += ri * ri;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (rs === 0) {
|
|
65
|
+
return 0;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const rs0 = rs;
|
|
69
|
+
const target = tolerance * tolerance * rs0;
|
|
70
|
+
|
|
71
|
+
for (let iter = 0; iter < max_iterations; iter++) {
|
|
72
|
+
apply_A(Ap, p);
|
|
73
|
+
|
|
74
|
+
let p_dot_Ap = 0;
|
|
75
|
+
for (let i = 0; i < n; i++) {
|
|
76
|
+
p_dot_Ap += p[i] * Ap[i];
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (p_dot_Ap === 0) {
|
|
80
|
+
return iter;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const alpha = rs / p_dot_Ap;
|
|
84
|
+
|
|
85
|
+
let rs_new = 0;
|
|
86
|
+
for (let i = 0; i < n; i++) {
|
|
87
|
+
x[i] += alpha * p[i];
|
|
88
|
+
const ri = r[i] - alpha * Ap[i];
|
|
89
|
+
r[i] = ri;
|
|
90
|
+
rs_new += ri * ri;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (rs_new <= target) {
|
|
94
|
+
return iter + 1;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const beta = rs_new / rs;
|
|
98
|
+
for (let i = 0; i < n; i++) {
|
|
99
|
+
p[i] = r[i] + beta * p[i];
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
rs = rs_new;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return max_iterations;
|
|
106
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Least-squares solve of the overdetermined (or square) system `A x ≈ b` via
|
|
3
|
+
* the normal equations `AᵀA x = Aᵀb`, using {@link cg_solve} on the
|
|
4
|
+
* matrix-free operator `x ↦ Aᵀ(A x)`. `AᵀA` is symmetric positive
|
|
5
|
+
* semi-definite, and positive-definite when `A` has full column rank — which is
|
|
6
|
+
* the case for the LSCM conformal system once two vertices are pinned.
|
|
7
|
+
*
|
|
8
|
+
* The normal-equations operator squares the condition number of `A`, so this is
|
|
9
|
+
* appropriate for the well-conditioned, modest-size per-chart systems of UV
|
|
10
|
+
* parameterization; it is not a general-purpose least-squares routine for
|
|
11
|
+
* ill-conditioned problems.
|
|
12
|
+
*
|
|
13
|
+
* @param {Float64Array} x length A.cols; initial guess in, solution out
|
|
14
|
+
* @param {import("../sparse/SparseMatrixCSR.js").SparseMatrixCSR} A
|
|
15
|
+
* @param {Float64Array} b right-hand side, length A.rows
|
|
16
|
+
* @param {number} max_iterations
|
|
17
|
+
* @param {number} tolerance relative residual target for the normal equations
|
|
18
|
+
* @returns {number} iterations performed
|
|
19
|
+
*/
|
|
20
|
+
export function cg_solve_normal_equations(x: Float64Array, A: import("../sparse/SparseMatrixCSR.js").SparseMatrixCSR, b: Float64Array, max_iterations: number, tolerance: number): number;
|
|
21
|
+
//# sourceMappingURL=cg_solve_normal_equations.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cg_solve_normal_equations.d.ts","sourceRoot":"","sources":["../../../../../../src/core/math/linalg/cg/cg_solve_normal_equations.js"],"names":[],"mappings":"AAWA;;;;;;;;;;;;;;;;;;GAkBG;AACH,6CAPW,YAAY,KACZ,OAAO,8BAA8B,EAAE,eAAe,KACtD,YAAY,kBACZ,MAAM,aACN,MAAM,GACJ,MAAM,CA8BlB"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { spm_matvec } from "../sparse/spm_matvec.js";
|
|
2
|
+
import { spm_matvec_transpose } from "../sparse/spm_matvec_transpose.js";
|
|
3
|
+
import { cg_solve } from "./cg_solve.js";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Module-static scratch for the intermediate `A x` (length rows) reused across
|
|
7
|
+
* calls. Like {@link cg_solve}, this is not re-entrant.
|
|
8
|
+
*/
|
|
9
|
+
let _Ax = new Float64Array(0);
|
|
10
|
+
let _Atb = new Float64Array(0);
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Least-squares solve of the overdetermined (or square) system `A x ≈ b` via
|
|
14
|
+
* the normal equations `AᵀA x = Aᵀb`, using {@link cg_solve} on the
|
|
15
|
+
* matrix-free operator `x ↦ Aᵀ(A x)`. `AᵀA` is symmetric positive
|
|
16
|
+
* semi-definite, and positive-definite when `A` has full column rank — which is
|
|
17
|
+
* the case for the LSCM conformal system once two vertices are pinned.
|
|
18
|
+
*
|
|
19
|
+
* The normal-equations operator squares the condition number of `A`, so this is
|
|
20
|
+
* appropriate for the well-conditioned, modest-size per-chart systems of UV
|
|
21
|
+
* parameterization; it is not a general-purpose least-squares routine for
|
|
22
|
+
* ill-conditioned problems.
|
|
23
|
+
*
|
|
24
|
+
* @param {Float64Array} x length A.cols; initial guess in, solution out
|
|
25
|
+
* @param {import("../sparse/SparseMatrixCSR.js").SparseMatrixCSR} A
|
|
26
|
+
* @param {Float64Array} b right-hand side, length A.rows
|
|
27
|
+
* @param {number} max_iterations
|
|
28
|
+
* @param {number} tolerance relative residual target for the normal equations
|
|
29
|
+
* @returns {number} iterations performed
|
|
30
|
+
*/
|
|
31
|
+
export function cg_solve_normal_equations(x, A, b, max_iterations, tolerance) {
|
|
32
|
+
const rows = A.rows;
|
|
33
|
+
const cols = A.cols;
|
|
34
|
+
|
|
35
|
+
if (_Ax.length < rows) {
|
|
36
|
+
_Ax = new Float64Array(rows);
|
|
37
|
+
}
|
|
38
|
+
if (_Atb.length < cols) {
|
|
39
|
+
_Atb = new Float64Array(cols);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const Ax = _Ax;
|
|
43
|
+
|
|
44
|
+
// Right-hand side of the normal equations.
|
|
45
|
+
spm_matvec_transpose(_Atb, A, b);
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Matrix-free normal-equations operator: `out = Aᵀ(A·vec)`.
|
|
49
|
+
*
|
|
50
|
+
* @param {Float64Array} out length A.cols; overwritten with AᵀA·vec
|
|
51
|
+
* @param {Float64Array} vec length A.cols
|
|
52
|
+
*/
|
|
53
|
+
const apply_normal = (out, vec) => {
|
|
54
|
+
spm_matvec(Ax, A, vec);
|
|
55
|
+
spm_matvec_transpose(out, A, Ax);
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
return cg_solve(x, apply_normal, _Atb, cols, max_iterations, tolerance);
|
|
59
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Eigendecomposition of a symmetric 3x3 matrix via cyclic Jacobi rotations.
|
|
3
|
+
*
|
|
4
|
+
* Only the upper triangle of `m` is read (the matrix is assumed symmetric);
|
|
5
|
+
* the input is not modified. Eigenpairs are emitted sorted by **ascending
|
|
6
|
+
* eigenvalue**, so index 0 is the smallest — convenient for proxy-plane fits,
|
|
7
|
+
* where the plane normal is the eigenvector of the smallest variance.
|
|
8
|
+
*
|
|
9
|
+
* Eigenvector sign is arbitrary (an eigenvector and its negation are both
|
|
10
|
+
* valid); callers that need a consistent orientation must fix the sign
|
|
11
|
+
* themselves.
|
|
12
|
+
*
|
|
13
|
+
* @param {Float64Array|Float32Array|number[]} out_values length >= 3, eigenvalues ascending
|
|
14
|
+
* @param {Float64Array|Float32Array|number[]} out_vectors length >= 9, eigenvector k
|
|
15
|
+
* in out_vectors[k*3 .. k*3 + 2] (column-major: contiguous per eigenvector)
|
|
16
|
+
* @param {Float64Array|Float32Array|number[]} m symmetric 3x3, row-major (index = row*3 + col)
|
|
17
|
+
*/
|
|
18
|
+
export function matrix_symmetric_3x3_eigen(out_values: Float64Array | Float32Array | number[], out_vectors: Float64Array | Float32Array | number[], m: Float64Array | Float32Array | number[]): void;
|
|
19
|
+
//# sourceMappingURL=matrix_symmetric_3x3_eigen.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"matrix_symmetric_3x3_eigen.d.ts","sourceRoot":"","sources":["../../../../../../src/core/math/linalg/eigen/matrix_symmetric_3x3_eigen.js"],"names":[],"mappings":"AA8DA;;;;;;;;;;;;;;;;GAgBG;AACH,uDALW,YAAY,GAAC,YAAY,GAAC,MAAM,EAAE,eAClC,YAAY,GAAC,YAAY,GAAC,MAAM,EAAE,KAElC,YAAY,GAAC,YAAY,GAAC,MAAM,EAAE,QAuC5C"}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Maximum number of cyclic Jacobi sweeps. A symmetric 3x3 reaches full double
|
|
3
|
+
* precision in ~5-6 sweeps (Jacobi converges quadratically); 50 is a generous
|
|
4
|
+
* cap that the relative-off-diagonal early-out almost always beats.
|
|
5
|
+
* @type {number}
|
|
6
|
+
*/
|
|
7
|
+
const MAX_SWEEPS = 50;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* One Jacobi rotation in the (p, q) plane that zeroes the off-diagonal entry
|
|
11
|
+
* a[p][q]. `a` and `v` are 3x3 matrices stored row-major (index = row*3 + col).
|
|
12
|
+
* `a` is the symmetric working matrix; `v` accumulates the rotations so its
|
|
13
|
+
* columns become the eigenvectors.
|
|
14
|
+
*
|
|
15
|
+
* @param {number[]} a symmetric 3x3, mutated in place
|
|
16
|
+
* @param {number[]} v 3x3 rotation accumulator, mutated in place
|
|
17
|
+
* @param {number} p
|
|
18
|
+
* @param {number} q
|
|
19
|
+
*/
|
|
20
|
+
function jacobi_rotate(a, v, p, q) {
|
|
21
|
+
const apq = a[p * 3 + q];
|
|
22
|
+
|
|
23
|
+
if (apq === 0) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const app = a[p * 3 + p];
|
|
28
|
+
const aqq = a[q * 3 + q];
|
|
29
|
+
|
|
30
|
+
// tan of the rotation angle (Numerical Recipes form, |angle| <= pi/4).
|
|
31
|
+
const theta = (aqq - app) / (2 * apq);
|
|
32
|
+
const t = (theta >= 0)
|
|
33
|
+
? 1 / (theta + Math.sqrt(theta * theta + 1))
|
|
34
|
+
: -1 / (-theta + Math.sqrt(theta * theta + 1));
|
|
35
|
+
const c = 1 / Math.sqrt(t * t + 1);
|
|
36
|
+
const s = t * c;
|
|
37
|
+
|
|
38
|
+
// The third (untouched) index.
|
|
39
|
+
const r = 3 - p - q;
|
|
40
|
+
const arp = a[r * 3 + p];
|
|
41
|
+
const arq = a[r * 3 + q];
|
|
42
|
+
|
|
43
|
+
a[p * 3 + p] = app - t * apq;
|
|
44
|
+
a[q * 3 + q] = aqq + t * apq;
|
|
45
|
+
a[p * 3 + q] = 0;
|
|
46
|
+
a[q * 3 + p] = 0;
|
|
47
|
+
|
|
48
|
+
const new_rp = c * arp - s * arq;
|
|
49
|
+
const new_rq = s * arp + c * arq;
|
|
50
|
+
a[r * 3 + p] = new_rp;
|
|
51
|
+
a[p * 3 + r] = new_rp;
|
|
52
|
+
a[r * 3 + q] = new_rq;
|
|
53
|
+
a[q * 3 + r] = new_rq;
|
|
54
|
+
|
|
55
|
+
for (let row = 0; row < 3; row++) {
|
|
56
|
+
const vrp = v[row * 3 + p];
|
|
57
|
+
const vrq = v[row * 3 + q];
|
|
58
|
+
v[row * 3 + p] = c * vrp - s * vrq;
|
|
59
|
+
v[row * 3 + q] = s * vrp + c * vrq;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Eigendecomposition of a symmetric 3x3 matrix via cyclic Jacobi rotations.
|
|
65
|
+
*
|
|
66
|
+
* Only the upper triangle of `m` is read (the matrix is assumed symmetric);
|
|
67
|
+
* the input is not modified. Eigenpairs are emitted sorted by **ascending
|
|
68
|
+
* eigenvalue**, so index 0 is the smallest — convenient for proxy-plane fits,
|
|
69
|
+
* where the plane normal is the eigenvector of the smallest variance.
|
|
70
|
+
*
|
|
71
|
+
* Eigenvector sign is arbitrary (an eigenvector and its negation are both
|
|
72
|
+
* valid); callers that need a consistent orientation must fix the sign
|
|
73
|
+
* themselves.
|
|
74
|
+
*
|
|
75
|
+
* @param {Float64Array|Float32Array|number[]} out_values length >= 3, eigenvalues ascending
|
|
76
|
+
* @param {Float64Array|Float32Array|number[]} out_vectors length >= 9, eigenvector k
|
|
77
|
+
* in out_vectors[k*3 .. k*3 + 2] (column-major: contiguous per eigenvector)
|
|
78
|
+
* @param {Float64Array|Float32Array|number[]} m symmetric 3x3, row-major (index = row*3 + col)
|
|
79
|
+
*/
|
|
80
|
+
export function matrix_symmetric_3x3_eigen(out_values, out_vectors, m) {
|
|
81
|
+
const a = [
|
|
82
|
+
m[0], m[1], m[2],
|
|
83
|
+
m[1], m[4], m[5],
|
|
84
|
+
m[2], m[5], m[8],
|
|
85
|
+
];
|
|
86
|
+
const v = [
|
|
87
|
+
1, 0, 0,
|
|
88
|
+
0, 1, 0,
|
|
89
|
+
0, 0, 1,
|
|
90
|
+
];
|
|
91
|
+
|
|
92
|
+
for (let sweep = 0; sweep < MAX_SWEEPS; sweep++) {
|
|
93
|
+
const scale = Math.abs(a[0]) + Math.abs(a[4]) + Math.abs(a[8]);
|
|
94
|
+
const off = Math.abs(a[1]) + Math.abs(a[2]) + Math.abs(a[5]);
|
|
95
|
+
|
|
96
|
+
if (off <= 1e-18 * scale) {
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
jacobi_rotate(a, v, 0, 1);
|
|
101
|
+
jacobi_rotate(a, v, 0, 2);
|
|
102
|
+
jacobi_rotate(a, v, 1, 2);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// Eigenvalues live on the diagonal; eigenvector k is column k of V.
|
|
106
|
+
const eig = [a[0], a[4], a[8]];
|
|
107
|
+
const order = [0, 1, 2];
|
|
108
|
+
order.sort((i, j) => eig[i] - eig[j]);
|
|
109
|
+
|
|
110
|
+
for (let k = 0; k < 3; k++) {
|
|
111
|
+
const col = order[k];
|
|
112
|
+
out_values[k] = eig[col];
|
|
113
|
+
out_vectors[k * 3 + 0] = v[0 * 3 + col];
|
|
114
|
+
out_vectors[k * 3 + 1] = v[1 * 3 + col];
|
|
115
|
+
out_vectors[k * 3 + 2] = v[2 * 3 + col];
|
|
116
|
+
}
|
|
117
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An `m x n` sparse matrix in Compressed Sparse Row form.
|
|
3
|
+
*
|
|
4
|
+
* The three parallel arrays follow the standard CSR convention:
|
|
5
|
+
* - `row_ptr[r]` = start of row r's entries in `col_idx`/`values`
|
|
6
|
+
* - `row_ptr[r+1]` = end (exclusive); `row_ptr[rows]` = nnz
|
|
7
|
+
* - `col_idx[k]` = column of entry k
|
|
8
|
+
* - `values[k]` = value of entry k
|
|
9
|
+
*
|
|
10
|
+
* Entries within a row are NOT required to be sorted by column, and duplicate
|
|
11
|
+
* (row, col) entries are permitted: matrix-vector products sum over a row, so
|
|
12
|
+
* duplicates simply accumulate — which is exactly what finite-element style
|
|
13
|
+
* assembly (many small per-element contributions to the same cell) wants. This
|
|
14
|
+
* is why {@link SparseMatrixCSR.from_triplets} performs no de-duplication pass.
|
|
15
|
+
*
|
|
16
|
+
* Fields are exposed directly (not via accessors) so hot matvec loops can run
|
|
17
|
+
* `for (let k = row_ptr[r]; k < row_ptr[r+1]; k++)` without closure overhead,
|
|
18
|
+
* mirroring {@link CSRGraph}.
|
|
19
|
+
*/
|
|
20
|
+
export class SparseMatrixCSR {
|
|
21
|
+
/**
|
|
22
|
+
* Build a CSR matrix from a triplet (coordinate) list. The triplet arrays
|
|
23
|
+
* are parallel; `count` entries are read. Duplicate (row, col) triplets are
|
|
24
|
+
* kept and will sum during matvec.
|
|
25
|
+
*
|
|
26
|
+
* @param {number} rows
|
|
27
|
+
* @param {number} cols
|
|
28
|
+
* @param {Uint32Array|number[]} triplet_rows
|
|
29
|
+
* @param {Uint32Array|number[]} triplet_cols
|
|
30
|
+
* @param {Float64Array|number[]} triplet_values
|
|
31
|
+
* @param {number} count number of triplets to read
|
|
32
|
+
* @returns {SparseMatrixCSR}
|
|
33
|
+
*/
|
|
34
|
+
static from_triplets(rows: number, cols: number, triplet_rows: Uint32Array | number[], triplet_cols: Uint32Array | number[], triplet_values: Float64Array | number[], count: number): SparseMatrixCSR;
|
|
35
|
+
/**
|
|
36
|
+
* @param {number} rows
|
|
37
|
+
* @param {number} cols
|
|
38
|
+
* @param {Uint32Array} row_ptr length rows + 1
|
|
39
|
+
* @param {Uint32Array} col_idx length nnz
|
|
40
|
+
* @param {Float64Array} values length nnz
|
|
41
|
+
*/
|
|
42
|
+
constructor(rows: number, cols: number, row_ptr: Uint32Array, col_idx: Uint32Array, values: Float64Array);
|
|
43
|
+
rows: number;
|
|
44
|
+
cols: number;
|
|
45
|
+
row_ptr: Uint32Array;
|
|
46
|
+
col_idx: Uint32Array;
|
|
47
|
+
values: Float64Array;
|
|
48
|
+
nnz: number;
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=SparseMatrixCSR.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SparseMatrixCSR.d.ts","sourceRoot":"","sources":["../../../../../../src/core/math/linalg/sparse/SparseMatrixCSR.js"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;GAkBG;AACH;IAiBI;;;;;;;;;;;;OAYG;IACH,2BARW,MAAM,QACN,MAAM,gBACN,WAAW,GAAC,MAAM,EAAE,gBACpB,WAAW,GAAC,MAAM,EAAE,kBACpB,YAAY,GAAC,MAAM,EAAE,SACrB,MAAM,GACJ,eAAe,CAqC3B;IAhED;;;;;;OAMG;IACH,kBANW,MAAM,QACN,MAAM,WACN,WAAW,WACX,WAAW,UACX,YAAY,EAStB;IANG,aAAgB;IAChB,aAAgB;IAChB,qBAAsB;IACtB,qBAAsB;IACtB,qBAAoB;IACpB,YAAwB;CAoD/B"}
|