From 0a54d54ebec2ac487e1a5275f209ed88b892267c Mon Sep 17 00:00:00 2001 From: rdb Date: Sat, 13 Jul 2019 21:38:05 +0200 Subject: [PATCH 1/4] Update BACKERS.md --- BACKERS.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/BACKERS.md b/BACKERS.md index 8c6cd2e965..d3dcf17084 100644 --- a/BACKERS.md +++ b/BACKERS.md @@ -24,6 +24,12 @@ This is a list of all the people who are contributing financially to Panda3D. I * Sam Edwards * Max Voss +## Enthusiasts + +![Benefactors](https://opencollective.com/panda3d/tiers/enthusiast.svg?avatarHeight=48&width=600) + +* Eric Thomson + ## Backers ![Backers](https://opencollective.com/panda3d/tiers/backer.svg?avatarHeight=48&width=600) From ce6d02b8d7f6e8b30ed9bc542c56272a6c196f76 Mon Sep 17 00:00:00 2001 From: rdb Date: Mon, 15 Jul 2019 14:54:55 +0200 Subject: [PATCH 2/4] egg: remove unused matrix_2d variable --- panda/src/egg/parser.cxx.prebuilt | 4 ---- panda/src/egg/parser.yxx | 4 ---- 2 files changed, 8 deletions(-) diff --git a/panda/src/egg/parser.cxx.prebuilt b/panda/src/egg/parser.cxx.prebuilt index f39d54d456..576f851740 100644 --- a/panda/src/egg/parser.cxx.prebuilt +++ b/panda/src/egg/parser.cxx.prebuilt @@ -168,10 +168,6 @@ static Groups groups; // temporarily. static int vertex_index; -// We need to hold a matrix for a little bit while parsing the -// entries. -static LMatrix3d matrix_2d; - //////////////////////////////////////////////////////////////////// // Defining the interface to the parser. diff --git a/panda/src/egg/parser.yxx b/panda/src/egg/parser.yxx index 6125ead479..a41b08ba57 100644 --- a/panda/src/egg/parser.yxx +++ b/panda/src/egg/parser.yxx @@ -98,10 +98,6 @@ static Groups groups; // temporarily. static int vertex_index; -// We need to hold a matrix for a little bit while parsing the -// entries. -static LMatrix3d matrix_2d; - //////////////////////////////////////////////////////////////////// // Defining the interface to the parser. From 46a3a72029163643e9e95f0c12102755c8af43c7 Mon Sep 17 00:00:00 2001 From: pythonengineer Date: Wed, 10 Jul 2019 21:09:41 -0400 Subject: [PATCH 3/4] PythonUtil: weightedChoice should throw IndexError on empty list Also includes a unit test. Closes #682 --- direct/src/showbase/PythonUtil.py | 5 +++ tests/showbase/test_PythonUtil.py | 62 +++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) diff --git a/direct/src/showbase/PythonUtil.py b/direct/src/showbase/PythonUtil.py index 2370742957..fbef9ecc70 100644 --- a/direct/src/showbase/PythonUtil.py +++ b/direct/src/showbase/PythonUtil.py @@ -1130,6 +1130,10 @@ def weightedChoice(choiceList, rng=random.random, sum=None): """given a list of (weight, item) pairs, chooses an item based on the weights. rng must return 0..1. if you happen to have the sum of the weights, pass it in 'sum'.""" + # Throw an IndexError if we got an empty list. + if not choiceList: + raise IndexError('Cannot choose from an empty sequence') + # TODO: add support for dicts if sum is None: sum = 0. @@ -1138,6 +1142,7 @@ def weightedChoice(choiceList, rng=random.random, sum=None): rand = rng() accum = rand * sum + item = None for weight, item in choiceList: accum -= weight if accum <= 0.: diff --git a/tests/showbase/test_PythonUtil.py b/tests/showbase/test_PythonUtil.py index faf5da269f..c4c1b8076a 100644 --- a/tests/showbase/test_PythonUtil.py +++ b/tests/showbase/test_PythonUtil.py @@ -1,4 +1,5 @@ from direct.showbase import PythonUtil +import pytest def test_queue(): @@ -103,3 +104,64 @@ def test_priority_callbacks(): pc.clear() pc() assert len(l) == 0 + +def test_weighted_choice(): + # Test PythonUtil.weightedChoice() with no valid list. + with pytest.raises(IndexError): + PythonUtil.weightedChoice([]) + + # Create a sample choice list. + # This contains a few tuples containing only a weight + # and an arbitrary item. + choicelist = [(3, 'item1'), (1, 'item2'), (7, 'item3')] + + # These are the items that we expect. + items = ['item1', 'item2', 'item3'] + + # Test PythonUtil.weightedChoice() with our choice list. + item = PythonUtil.weightedChoice(choicelist) + + # Assert that what we got was at least an available item. + assert item in items + + # Create yet another sample choice list, but with a couple more items. + choicelist = [(2, 'item1'), (25, 'item2'), (14, 'item3'), (5, 'item4'), + (7, 'item5'), (3, 'item6'), (6, 'item7'), (50, 'item8')] + + # Set the items that we expect again. + items = ['item1', 'item2', 'item3', 'item4', 'item5', 'item6', 'item7', 'item8'] + + # The sum of all of the weights is 112. + weightsum = 2 + 25 + 14 + 5 + 7 + 3 + 6 + 50 + + # Test PythonUtil.weightedChoice() with the sum. + item = PythonUtil.weightedChoice(choicelist, sum=weightsum) + + # Assert that we got a valid item (most of the time this should be 'item8'). + assert item in items + + # Test PythonUtil.weightedChoice(), but with an invalid sum. + item = PythonUtil.weightedChoice(choicelist, sum=1) + + # Assert that we got 'item1'. + assert item == items[0] + + # Test PythonUtil.weightedChoice() with an invalid sum. + # This time, we're using 2000 so that regardless of the random + # number, we will still reach the very last item. + item = PythonUtil.weightedChoice(choicelist, sum=100000) + + # Assert that we got 'item8', since we would get the last item. + assert item == items[-1] + + # Create a bogus random function. + rnd = lambda: 0.5 + + # Test PythonUtil.weightedChoice() with the bogus function. + item = PythonUtil.weightedChoice(choicelist, rng=rnd, sum=weightsum) + + # Assert that we got 'item6'. + # We expect 'item6' because 0.5 multiplied by 112 is 56.0. + # When subtracting that number by each weight, it will reach 0 + # by the time it hits 'item6' in the iteration. + assert item == items[5] From 23232a5b20b39a0209805d8e4b7bdfdbdcd795b7 Mon Sep 17 00:00:00 2001 From: rdb Date: Mon, 15 Jul 2019 19:41:07 +0200 Subject: [PATCH 4/4] pgraphnodes: fix assert when analyzing geoms with strip cut index --- panda/src/pgraphnodes/sceneGraphAnalyzer.cxx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/panda/src/pgraphnodes/sceneGraphAnalyzer.cxx b/panda/src/pgraphnodes/sceneGraphAnalyzer.cxx index 915845af86..9a71530919 100644 --- a/panda/src/pgraphnodes/sceneGraphAnalyzer.cxx +++ b/panda/src/pgraphnodes/sceneGraphAnalyzer.cxx @@ -425,8 +425,12 @@ collect_statistics(const Geom *geom) { CPT(GeomPrimitive) prim = geom->get_primitive(i); int num_vertices = prim->get_num_vertices(); + int strip_cut_index = prim->get_strip_cut_index(); for (int vi = 0; vi < num_vertices; ++vi) { - tracker._referenced_vertices.set_bit(prim->get_vertex(vi)); + int index = prim->get_vertex(vi); + if (index != strip_cut_index) { + tracker._referenced_vertices.set_bit(index); + } } if (prim->is_indexed()) {