How to use vector - 10 common examples

To help you get started, we’ve selected a few vector examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github snake-biscuits / QtPyHammer / src / main / python / buffer_studies.py View on Github external
print(f'{len(vertices) // 33:,} TRIANGLES')
    print(f'{len(vertices) * 4 // 1024:,}KB')
    print('import took {:.2f} seconds'.format(time.time() - start_import))

    # STATIC BUFFER (UTILITIES)
    # Skybox, 3D grid, Origin Point
    # Editor Props (playerspawn, lights, sprite, path_track)

    CAMERA = camera.freecam((160, -160, 160), None, 128)
    render_solids = [s for s in solids if (s.center - CAMERA.position).sqrmagnitude() < 1024]
    rendered_ray = []

    SDL_SetRelativeMouseMode(SDL_TRUE)
    SDL_CaptureMouse(SDL_TRUE)

    mousepos = vector.vec2(-180, 120) # overrides start angle
    keys = []
            
    tickrate = 1 / 0.015
    old_time = time.time()
    event = SDL_Event()
    while True:
        while SDL_PollEvent(ctypes.byref(event)) != 0:
            if event.type == SDL_QUIT or event.key.keysym.sym == SDLK_ESCAPE and event.type == SDL_KEYDOWN:
                SDL_GL_DeleteContext(glContext)
                SDL_DestroyWindow(window)
                SDL_Quit()
                return False
            if event.type == SDL_KEYDOWN:
                if event.key.keysym.sym not in keys:
                    keys.append(event.key.keysym.sym)
            if event.type == SDL_KEYUP:
github snake-biscuits / QtPyHammer / hammer.py View on Github external
SDL_DestroyWindow(window)
                SDL_Quit()
                return False
            if event.type == SDL_KEYDOWN:
                if event.key.keysym.sym not in keys:
                    keys.append(event.key.keysym.sym)
            if event.type == SDL_KEYUP:
                while event.key.keysym.sym in keys:
                    keys.remove(event.key.keysym.sym)
            if event.type == SDL_MOUSEBUTTONDOWN:
                keys.append(event.button.button)
            if event.type == SDL_MOUSEBUTTONUP:
                while event.button.button in keys:
                    keys.remove(event.button.button)
            if event.type == SDL_MOUSEMOTION:
                mousepos += vector.vec2(event.motion.xrel, event.motion.yrel)
                SDL_WarpMouseInWindow(window, width // 2, height // 2)
            if event.type == SDL_MOUSEWHEEL:
                if CAMERA.speed + event.wheel.y * 32 > 0: # speed limits
                    CAMERA.speed += event.wheel.y * 32
            if event.type == SDL_DROPFILE:
                # load event.drop.file
                # .vmf -> new tab
                # .lin / .prt -> match to vmf
                pass

        dt = time.time() - old_time
        while dt >= 1 / tickrate:
            # use KEYTIME to delay input repeat
            # KEYTIME
            CAMERA.update(mousepos, keys, 1 / tickrate)
            render_solids = [s for s in solids if (s.center - CAMERA.position).magnitude() < 2048]
github snake-biscuits / QtPyHammer / src / main / python / buffer_studies.py View on Github external
SDL_DestroyWindow(window)
                SDL_Quit()
                return False
            if event.type == SDL_KEYDOWN:
                if event.key.keysym.sym not in keys:
                    keys.append(event.key.keysym.sym)
            if event.type == SDL_KEYUP:
                while event.key.keysym.sym in keys:
                    keys.remove(event.key.keysym.sym)
            if event.type == SDL_MOUSEBUTTONDOWN:
                keys.append(event.button.button)
            if event.type == SDL_MOUSEBUTTONUP:
                while event.button.button in keys:
                    keys.remove(event.button.button)
            if event.type == SDL_MOUSEMOTION:
                mousepos += vector.vec2(event.motion.xrel, event.motion.yrel)
                SDL_WarpMouseInWindow(window, width // 2, height // 2)
            if event.type == SDL_MOUSEWHEEL:
                if CAMERA.speed + event.wheel.y * 32 > 0: # speed limits
                    CAMERA.speed += event.wheel.y * 32
            if event.type == SDL_DROPFILE:
                # load event.drop.file
                # .vmf -> new tab
                # .lin / .prt -> match to vmf
                pass

        dt = time.time() - old_time
        while dt >= 1 / tickrate:
            # use KEYTIME to delay input repeat
            # KEYTIME
            # KEYTIME_COOLDOWN (time since key pressed with a limit of X seconds)
            CAMERA.update(mousepos, keys, 1 / tickrate)
github inasafe / inasafe / safe / storage / test_io.py View on Github external
P = numpy.array([[106.7922547, -6.2297884],
                         [106.7924589, -6.2298087],
                         [106.7924538, -6.2299127],
                         [106.7922547, -6.2298899],
                         [106.7922547, -6.2297884]])

        C = calculate_polygon_centroid(P)

        # Check against reference centroid from qgis
        reference_centroid = [106.79235602697445, -6.229849764722536]
        msg = 'Got %s but expected %s' % (str(C), str(reference_centroid))
        assert numpy.allclose(C, reference_centroid, rtol=1.0e-8), msg

        # Store centroid to file (to e.g. check with qgis)
        out_filename = unique_filename(prefix='test_centroid', suffix='.shp')
        V = Vector(data=None,
                   projection=DEFAULT_PROJECTION,
                   geometry=[C],
                   name='Test centroid')
        V.write_to_file(out_filename)
github thomas-haslwanter / scikit-kinematics / tests / test_vector.py View on Github external
def test_normalize(self):
        result = vector.normalize([3, 0, 0])
        correct = array([[ 1.,  0.,  0.]])
        error = norm(result-correct)
        self.assertAlmostEqual(error, 0)
github thomas-haslwanter / scikit-kinematics / tests / test_markers.py View on Github external
def test_analyze3dmarkers(self):
        t = np.arange(0,10,0.1)
        translation = (np.c_[[1,1,0]]*t).T
    
        M = np.empty((3,3))
        M[0] = np.r_[0,0,0]
        M[1]= np.r_[1,0,0]
        M[2] = np.r_[1,1,0]
        M -= np.mean(M, axis=0) 
    
        q = np.vstack((np.zeros_like(t), np.zeros_like(t),quat.deg2quat(100*t))).T
    
        M0 = vector.rotate_vector(M[0], q) + translation
        M1 = vector.rotate_vector(M[1], q) + translation
        M2 = vector.rotate_vector(M[2], q) + translation
    
        data = np.hstack((M0,M1,M2))
    
        (pos, ori) = markers.analyze3Dmarkers(data, data[0])
        
        self.assertAlmostEqual(np.max(np.abs(pos-translation)), 0)
        self.assertAlmostEqual(np.max(np.abs(ori-q)), 0)
github thomas-haslwanter / scikit-kinematics / tests / test_vector.py View on Github external
def test_rotate_vector(self):
        x = [[1,0,0], [0, 1, 0], [0,0,1]]
        result = vector.rotate_vector(x, [0, 0, sin(0.1)])
        correct = array([[ 0.98006658,  0.19866933,  0.        ],
              [-0.19866933,  0.98006658,  0.        ],
              [ 0.        ,  0.        ,  1.        ]])
        error = norm(result - correct)
        self.assertTrue(error < self.delta)
github MonsieurV / py-findpeaks / tests / octave_findpeaks.py View on Github external
np.array(vector),
    indexes,
    algorithm='Octave-Forge findpeaks'
)

print('Detect peaks with minimum height and distance filters.')
(pks, indexes) = octave.findpeaks(
    np.array(vector),
    'DoubleSided', 'MinPeakHeight', 6, 'MinPeakDistance', 2, 'MinPeakWidth', 0
)
# The results are in a 2D array and in floats: get back to 1D array and convert
# peak indexes to integer. Also this is MatLab-style indexation (one-based),
# so we must substract one to get back to Python indexation (zero-based).
indexes = indexes[0].astype(int) - 1
print('Peaks are: %s' % (indexes))
plot_peaks(
    np.array(vector),
    indexes,
    mph=6, mpd=2, algorithm='Octave-Forge findpeaks'
)
github MonsieurV / py-findpeaks / tests / peakutils_indexes.py View on Github external
print('Detect peaks without any filters.')
indexes = peakutils.peak.indexes(np.array(vector), thres=0, min_dist=0)
print('Peaks are: %s' % (indexes))
plot_peaks(
    np.array(vector),
    indexes,
    algorithm='peakutils.peak.indexes'
)

print('Detect peaks with minimum height and distance filters.')
indexes = peakutils.peak.indexes(
    np.array(vector),
    thres=7.0/max(vector), min_dist=2
)
print('Peaks are: %s' % (indexes))
plot_peaks(
    np.array(vector),
    indexes,
    mph=7, mpd=2, algorithm='peakutils.peak.indexes'
)
github MonsieurV / py-findpeaks / tests / scipy_signal_find_peaks.py View on Github external
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import numpy as np
from vector import vector, plot_peaks
import scipy.signal

print('Detect peaks without any filters.')
indexes, _ = scipy.signal.find_peaks(np.array(vector))
print('Peaks are: {}'.format(indexes))
plot_peaks(
    np.array(vector),
    indexes,
    algorithm='scipy.signal.find_peaks'
)

print('Detect peaks with minimum height and distance filters.')
indexes, _ = scipy.signal.find_peaks(
    np.array(vector),
    height=7, distance=2.1
)
print('Peaks are: {}'.format(indexes))
plot_peaks(
    np.array(vector),
    indexes,
    mph=7, mpd=2.1, algorithm='scipy.signal.find_peaks'
)