Skip to content

Conversation

@ryan-di
Copy link
Member

@ryan-di ryan-di commented Jan 31, 2024

This PR tries to improve upon the collision methods that we have for a given element in the editor and it is in relation to the following goals:

  • reduce unnecessary dependencies so that we can better tree-shake
  • shift to vector geometry so that mere mortals like me can extend the "primitive" geometry helpers so that we can enable more powerful and more accurate interactions on different shapes
  • make the collision and (later down the line) bounds api more simplistic

Under utils/geometry, two files geometry.ts and shape.ts are introduced. shape.ts defines various pure geometric shapes, like polygon, curves, and ellipses. It also includes methods to convert an element or a Drawable into pure geometric shapes. Then in geometry.ts, pure methods for working with different pure geometric shapes are provided.

And excalidraw/element/collision.ts has been updated so that the simple apis uses the pure functions from utils/collision.ts, which depends on geometry.ts and shape.ts.

In App.tsx, we have public and private methods that depend on app state and cache to get pure geometric shapes and to carry out collision detection for different use cases.

@vercel
Copy link

vercel bot commented Jan 31, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
excalidraw ✅ Ready (Inspect) Visit Preview Apr 3, 2024 10:08pm
excalidraw-package-example ✅ Ready (Inspect) Visit Preview Apr 3, 2024 10:08pm
excalidraw-package-example-with-nextjs ✅ Ready (Inspect) Visit Preview Apr 3, 2024 10:08pm
1 Ignored Deployment
Name Status Preview Updated (UTC)
docs ⬜️ Ignored (Inspect) Visit Preview Apr 3, 2024 10:08pm

@github-actions
Copy link

github-actions bot commented Jan 31, 2024

Coverage Report

Status Category Percentage Covered / Total
🔴 Lines 64.16% (🎯 70%) 47854 / 74582
🔴 Statements 64.16% (🎯 70%) 47854 / 74582
🔴 Functions 64.88% (🎯 68%) 1441 / 2221
🟢 Branches 79.98% (🎯 70%) 5743 / 7180
File Coverage
File Stmts % Branch % Funcs % Lines Uncovered Lines
Changed Files
packages/excalidraw/types.ts 100% 100% 100% 100%
packages/excalidraw/actions/actionFinalize.tsx 73.68% 88.37% 66.66% 73.68% 29-55, 61, 64-65, 108-117, 144-149, 199-207
packages/excalidraw/actions/actionFlip.ts 99.23% 81.25% 100% 99.23% 127
packages/excalidraw/components/App.tsx 68.96% 75.68% 67.87% 68.96% 471-472, 578-587, 682-683, 701-702, 722-782, 785-791, 794-797, 800-876, 879-898, 901-906, 914-924, 926-927, 932-933, 937-939, 953, 960-1219, 1279-1280, 1291-1292, 1320-1322, 1332-1377, 1403, 1413, 1420-1423, 1432-1436, 1467-1468, 1552-1562, 1567-1582, 1586-1633, 1704-1709, 1738-1743, 1746-1776, 1784-1809, 1812-1821, 1824-1936, 1939-1947, 1956-1969, 1972-1998, 2001-2072, 2075-2115, 2161-2162, 2176-2177, 2214-2215, 2219-2220, 2236-2243, 2248-2261, 2267-2268, 2273-2281, 2283-2291, 2303, 2343-2344, 2366-2367, 2374, 2435-2437, 2440-2445, 2450-2451, 2488-2496, 2501-2510, 2548-2549, 2632-2633, 2637, 2640-2641, 2649-2652, 2661-2674, 2680-2683, 2686, 2688-2689, 2696-2697, 2703-2704, 2707-2708, 2716-2717, 2720-2721, 2724-2727, 2738-2746, 2751-2752, 2801-2802, 2816-2822, 2828-2836, 2840-2848, 2852-2853, 2856-2889, 2892-2904, 2915-2916, 2927-2928, 2945-2949, 2953-2956, 2963-2965, 2983-2990, 2993, 2995-3000, 3004-3006, 3027-3028, 3035-3037, 3039-3062, 3088, 3094, 3150-3151, 3168-3170, 3192-3193, 3199-3202, 3208-3289, 3361-3362, 3367-3370, 3433, 3443-3461, 3464-3470, 3473-3474, 3480-3493, 3579-3580, 3582-3583, 3588-3590, 3598-3599, 3622-3636, 3641-3660, 3683-3684, 3756, 3765-3766, 3768-3775, 3790-3794, 3805-3806, 3809-3813, 3815-3816, 3818-3821, 3846-3847, 3856-3858, 3860, 3938-3941, 3963-3965, 3975-3976, 3978-3998, 4001-4007, 4024-4027, 4033-4036, 4046-4053, 4057-4058, 4064, 4092-4096, 4100, 4105-4106, 4111-4115, 4143-4144, 4147-4148, 4151-4152, 4160-4164, 4169-4170, 4176-4186, 4191-4218, 4223-4234, 4301, 4327-4328, 4393-4398, 4498, 4524-4526, 4593-4594, 4609-4610, 4780-4781, 4784-4785, 4793, 4841-4845, 4896-4903, 4909-4979, 5023, 5072, 5099, 5106-5107, 5116-5119, 5150, 5198-5201, 5204-5210, 5212-5215, 5230-5239, 5242-5243, 5325-5326, 5329, 5331-5336, 5342-5344, 5346, 5355, 5377-5382, 5384-5387, 5391-5392, 5402-5502, 5506-5507, 5522-5523, 5556-5557, 5584-5585, 5618-5644, 5651-5652, 5674-5675, 5694, 5696-5739, 5744-5745, 5747-5748, 5764-5765, 5771-5772, 5776-5779, 5782-5783, 5798-5825, 5833-5834, 5838-5841, 5843-5847, 5865-5869, 5915-5920, 5922-5924, 5940, 5942-5955, 5980-5983, 6027, 6044-6045, 6047-6070, 6085-6086, 6197-6225, 6294-6298, 6322-6323, 6343-6344, 6438, 6444-6445, 6468-6487, 6502, 6630, 6652-6693, 6697-6750, 6765, 6774, 6808-6814, 6829-6831, 6973-6976, 7000-7034, 7047, 7049-7057, 7071, 7073-7081, 7088-7091, 7099-7104, 7131-7132, 7137-7139, 7142-7143, 7168-7169, 7200-7201, 7284-7285, 7334-7347, 7408-7411, 7437-7438, 7469-7470, 7483, 7501-7507, 7514-7517, 7540-7546, 7618, 7624, 7639-7646, 7649-7656, 7712, 7789-7790, 7811-7813, 7816, 7830-7854, 7957-7981, 7991-8030, 8043-8044, 8053-8060, 8074-8087, 8100-8105, 8159-8185, 8187-8188, 8262-8263, 8270, 8272-8308, 8337, 8398, 8423-8425, 8450-8455, 8457-8458, 8463-8465, 8468-8488, 8502-8503, 8509-8518, 8523, 8527-8531, 8540-8544, 8547-8552, 8556-8563, 8593, 8595-8599, 8601-8611, 8627-8629, 8640-8648, 8652-8696, 8699-8770, 8778, 8796-8803, 8805-8821, 8836-8858, 8877-8879, 8924-8925, 8955-8956, 8975, 9052-9056, 9058-9074, 9076-9080, 9092-9093, 9103-9119, 9137-9156, 9158-9159, 9180-9181, 9185-9186, 9196, 9198-9201, 9203-9204, 9244, 9265-9266, 9292, 9295, 9336, 9350-9358, 9375-9376, 9408-9411, 9500-9507, 9533-9534, 9575-9629, 9677-9678, 9687-9690, 9695-9696, 9717-9719, 9721-9725, 9763
packages/excalidraw/components/hyperlink/Hyperlink.tsx 16.84% 33.33% 28.57% 16.84% 54-316, 319-331, 339-341, 343, 350-361, 364-404, 407-408, 410-412, 416-457
packages/excalidraw/components/hyperlink/helpers.ts 20.93% 100% 0% 20.93% 15-45, 48-66, 69-86
packages/excalidraw/element/binding.ts 92.26% 89.49% 96.15% 92.26% 137-141, 191-196, 292-293, 390-391, 396-397, 432-433, 471-473, 492, 502-504, 641-642, 697-698, 703-718, 727-734, 746-749, 758-770, 790-791, 793-794, 801-806, 829-830, 833-840, 1180-1182, 1220-1225, 1271-1272, 1294-1295, 1347-1349
packages/excalidraw/element/bounds.ts 83.75% 82.57% 90% 83.75% 166, 210-237, 253-259, 262-272, 292-300, 323-324, 456-459, 503, 505, 513, 517, 529-530, 582, 587, 606-608, 617-647, 663-664, 691-703, 765-775, 808-811, 855-856, 905-917
packages/excalidraw/element/collision.ts 100% 92% 100% 100%
packages/excalidraw/element/index.ts 86.88% 84.61% 70% 86.88% 69-76, 83-85, 108, 113-114, 121-122
packages/excalidraw/element/linearElementEditor.ts 76.92% 81.86% 89.18% 76.92% 134, 138-190, 206-207, 211-212, 222-223, 225-245, 271-274, 297-306, 345-346, 364-373, 386, 404-412, 500-501, 625-626, 639, 663-664, 670-671, 688-723, 818-819, 823-824, 831-832, 838-840, 842-879, 930, 1029-1094, 1108-1115, 1130-1139, 1205-1206, 1247-1248, 1312-1338, 1350-1351, 1454-1486
packages/excalidraw/element/textElement.ts 94.95% 95.23% 94.87% 94.95% 174-175, 215, 358-359, 571-578, 590-611, 625-626, 641-642, 681-688
packages/excalidraw/renderer/interactiveScene.ts 86.35% 84.82% 85% 86.35% 76-77, 81-82, 128-129, 142-160, 237-248, 263-288, 361, 432-434, 455-456, 496-503, 555-566, 582-583, 629-630, 736-745, 762, 879-902
packages/utils/collision.ts 87.87% 62.5% 66.66% 87.87% 28, 32, 36, 46, 48, 59, 65-66
packages/utils/geometry/geometry.ts 46.96% 93.33% 49.15% 46.96% 49-51, 86-91, 111-114, 118-121, 125-129, 141-142, 145-150, 155-157, 160-203, 206-207, 210-225, 228-265, 268-315, 318-330, 337-342, 345-375, 378-397, 400-419, 422-442, 445-465, 468-486, 489-507, 510-515, 522-535, 538-541, 544-569, 666-667, 674-675, 694-711, 714-748, 836-856, 859-886
packages/utils/geometry/shape.ts 82.37% 88.23% 88.88% 82.37% 158-159, 225-228, 236-278
Generated in workflow #2198

# Conflicts:
#	packages/excalidraw/components/App.tsx
#	packages/excalidraw/element/textElement.ts
#	packages/excalidraw/renderer/interactiveScene.ts
@dwelle
Copy link
Member

dwelle commented Apr 3, 2024

Thanks for the PR @ryan-di! 🚀

@ryan-di ryan-di merged commit bbdcd30 into master Apr 4, 2024
@ryan-di ryan-di deleted the vector-geometry branch April 4, 2024 08:31
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.

3 participants