How to use depth method in hypothesis

Best Python code snippet using hypothesis

GlobeDepth.js

Source:GlobeDepth.js Github

copy

Full Screen

1import BoundingRectangle from "../Core/BoundingRectangle.js";2import Color from "../Core/Color.js";3import defined from "../Core/defined.js";4import destroyObject from "../Core/destroyObject.js";5import PixelFormat from "../Core/PixelFormat.js";6import ClearCommand from "../Renderer/ClearCommand.js";7import Framebuffer from "../Renderer/Framebuffer.js";8import PixelDatatype from "../Renderer/PixelDatatype.js";9import RenderState from "../Renderer/RenderState.js";10import Sampler from "../Renderer/Sampler.js";11import ShaderSource from "../Renderer/ShaderSource.js";12import Texture from "../Renderer/Texture.js";13import PassThrough from "../Shaders/PostProcessStages/PassThrough.js";14import PassThroughDepth from "../Shaders/PostProcessStages/PassThroughDepth.js";15import BlendingState from "./BlendingState.js";16import StencilConstants from "./StencilConstants.js";17import StencilFunction from "./StencilFunction.js";18import StencilOperation from "./StencilOperation.js";19/**20 * @private21 */22function GlobeDepth() {23 this._globeColorTexture = undefined;24 this._primitiveColorTexture = undefined;25 this._depthStencilTexture = undefined;26 this._globeDepthTexture = undefined;27 this._tempGlobeDepthTexture = undefined;28 this._tempCopyDepthTexture = undefined;29 this._globeColorFramebuffer = undefined;30 this._primitiveColorFramebuffer = undefined;31 this._copyDepthFramebuffer = undefined;32 this._tempCopyDepthFramebuffer = undefined;33 this._updateDepthFramebuffer = undefined;34 this._clearGlobeColorCommand = undefined;35 this._clearPrimitiveColorCommand = undefined;36 this._copyColorCommand = undefined;37 this._copyDepthCommand = undefined;38 this._tempCopyDepthCommand = undefined;39 this._updateDepthCommand = undefined;40 this._mergeColorCommand = undefined;41 this._viewport = new BoundingRectangle();42 this._rs = undefined;43 this._rsBlend = undefined;44 this._rsUpdate = undefined;45 this._useScissorTest = false;46 this._scissorRectangle = undefined;47 this._useLogDepth = undefined;48 this._useHdr = undefined;49 this._clearGlobeDepth = undefined;50 this._debugGlobeDepthViewportCommand = undefined;51}52Object.defineProperties(GlobeDepth.prototype, {53 framebuffer: {54 get: function () {55 return this._globeColorFramebuffer;56 },57 },58 primitiveFramebuffer: {59 get: function () {60 return this._primitiveColorFramebuffer;61 },62 },63});64function executeDebugGlobeDepth(globeDepth, context, passState, useLogDepth) {65 if (66 !defined(globeDepth._debugGlobeDepthViewportCommand) ||67 useLogDepth !== globeDepth._useLogDepth68 ) {69 var fsSource =70 "uniform highp sampler2D u_depthTexture;\n" +71 "varying vec2 v_textureCoordinates;\n" +72 "void main()\n" +73 "{\n" +74 " float z_window = czm_unpackDepth(texture2D(u_depthTexture, v_textureCoordinates));\n" +75 " z_window = czm_reverseLogDepth(z_window); \n" +76 " float n_range = czm_depthRange.near;\n" +77 " float f_range = czm_depthRange.far;\n" +78 " float z_ndc = (2.0 * z_window - n_range - f_range) / (f_range - n_range);\n" +79 " float scale = pow(z_ndc * 0.5 + 0.5, 8.0);\n" +80 " gl_FragColor = vec4(mix(vec3(0.0), vec3(1.0), scale), 1.0);\n" +81 "}\n";82 var fs = new ShaderSource({83 defines: [useLogDepth ? "LOG_DEPTH" : ""],84 sources: [fsSource],85 });86 globeDepth._debugGlobeDepthViewportCommand = context.createViewportQuadCommand(87 fs,88 {89 uniformMap: {90 u_depthTexture: function () {91 return globeDepth._globeDepthTexture;92 },93 },94 owner: globeDepth,95 }96 );97 globeDepth._useLogDepth = useLogDepth;98 }99 globeDepth._debugGlobeDepthViewportCommand.execute(context, passState);100}101function destroyTextures(globeDepth) {102 globeDepth._globeColorTexture =103 globeDepth._globeColorTexture &&104 !globeDepth._globeColorTexture.isDestroyed() &&105 globeDepth._globeColorTexture.destroy();106 globeDepth._depthStencilTexture =107 globeDepth._depthStencilTexture &&108 !globeDepth._depthStencilTexture.isDestroyed() &&109 globeDepth._depthStencilTexture.destroy();110 globeDepth._globeDepthTexture =111 globeDepth._globeDepthTexture &&112 !globeDepth._globeDepthTexture.isDestroyed() &&113 globeDepth._globeDepthTexture.destroy();114}115function destroyFramebuffers(globeDepth) {116 globeDepth._globeColorFramebuffer =117 globeDepth._globeColorFramebuffer &&118 !globeDepth._globeColorFramebuffer.isDestroyed() &&119 globeDepth._globeColorFramebuffer.destroy();120 globeDepth._copyDepthFramebuffer =121 globeDepth._copyDepthFramebuffer &&122 !globeDepth._copyDepthFramebuffer.isDestroyed() &&123 globeDepth._copyDepthFramebuffer.destroy();124}125function destroyUpdateDepthResources(globeDepth) {126 globeDepth._tempCopyDepthFramebuffer =127 globeDepth._tempCopyDepthFramebuffer &&128 !globeDepth._tempCopyDepthFramebuffer.isDestroyed() &&129 globeDepth._tempCopyDepthFramebuffer.destroy();130 globeDepth._updateDepthFramebuffer =131 globeDepth._updateDepthFramebuffer &&132 !globeDepth._updateDepthFramebuffer.isDestroyed() &&133 globeDepth._updateDepthFramebuffer.destroy();134 globeDepth._tempGlobeDepthTexture =135 globeDepth._tempGlobeDepthTexture &&136 !globeDepth._tempGlobeDepthTexture.isDestroyed() &&137 globeDepth._tempGlobeDepthTexture.destroy();138}139function createUpdateDepthResources(140 globeDepth,141 context,142 width,143 height,144 passState145) {146 globeDepth._tempGlobeDepthTexture = new Texture({147 context: context,148 width: width,149 height: height,150 pixelFormat: PixelFormat.RGBA,151 pixelDatatype: PixelDatatype.UNSIGNED_BYTE,152 sampler: Sampler.NEAREST,153 });154 globeDepth._tempCopyDepthFramebuffer = new Framebuffer({155 context: context,156 colorTextures: [globeDepth._tempGlobeDepthTexture],157 destroyAttachments: false,158 });159 globeDepth._updateDepthFramebuffer = new Framebuffer({160 context: context,161 colorTextures: [globeDepth._globeDepthTexture],162 depthStencilTexture: passState.framebuffer.depthStencilTexture,163 destroyAttachments: false,164 });165}166function createTextures(globeDepth, context, width, height, hdr) {167 var pixelDatatype = hdr168 ? context.halfFloatingPointTexture169 ? PixelDatatype.HALF_FLOAT170 : PixelDatatype.FLOAT171 : PixelDatatype.UNSIGNED_BYTE;172 globeDepth._globeColorTexture = new Texture({173 context: context,174 width: width,175 height: height,176 pixelFormat: PixelFormat.RGBA,177 pixelDatatype: pixelDatatype,178 sampler: Sampler.NEAREST,179 });180 globeDepth._depthStencilTexture = new Texture({181 context: context,182 width: width,183 height: height,184 pixelFormat: PixelFormat.DEPTH_STENCIL,185 pixelDatatype: PixelDatatype.UNSIGNED_INT_24_8,186 });187 globeDepth._globeDepthTexture = new Texture({188 context: context,189 width: width,190 height: height,191 pixelFormat: PixelFormat.RGBA,192 pixelDatatype: PixelDatatype.UNSIGNED_BYTE,193 sampler: Sampler.NEAREST,194 });195}196function createFramebuffers(globeDepth, context) {197 globeDepth._globeColorFramebuffer = new Framebuffer({198 context: context,199 colorTextures: [globeDepth._globeColorTexture],200 depthStencilTexture: globeDepth._depthStencilTexture,201 destroyAttachments: false,202 });203 globeDepth._copyDepthFramebuffer = new Framebuffer({204 context: context,205 colorTextures: [globeDepth._globeDepthTexture],206 destroyAttachments: false,207 });208}209function createPrimitiveFramebuffer(globeDepth, context, width, height, hdr) {210 var pixelDatatype = hdr211 ? context.halfFloatingPointTexture212 ? PixelDatatype.HALF_FLOAT213 : PixelDatatype.FLOAT214 : PixelDatatype.UNSIGNED_BYTE;215 globeDepth._primitiveColorTexture = new Texture({216 context: context,217 width: width,218 height: height,219 pixelFormat: PixelFormat.RGBA,220 pixelDatatype: pixelDatatype,221 sampler: Sampler.NEAREST,222 });223 globeDepth._primitiveColorFramebuffer = new Framebuffer({224 context: context,225 colorTextures: [globeDepth._primitiveColorTexture],226 depthStencilTexture: globeDepth._depthStencilTexture,227 destroyAttachments: false,228 });229}230function destroyPrimitiveFramebuffer(globeDepth) {231 globeDepth._primitiveColorTexture =232 globeDepth._primitiveColorTexture &&233 !globeDepth._primitiveColorTexture.isDestroyed() &&234 globeDepth._primitiveColorTexture.destroy();235 globeDepth._primitiveColorFramebuffer =236 globeDepth._primitiveColorFramebuffer &&237 !globeDepth._primitiveColorFramebuffer.isDestroyed() &&238 globeDepth._primitiveColorFramebuffer.destroy();239}240function updateFramebuffers(241 globeDepth,242 context,243 width,244 height,245 hdr,246 clearGlobeDepth247) {248 var colorTexture = globeDepth._globeColorTexture;249 var textureChanged =250 !defined(colorTexture) ||251 colorTexture.width !== width ||252 colorTexture.height !== height ||253 hdr !== globeDepth._useHdr;254 if (textureChanged) {255 destroyTextures(globeDepth);256 destroyFramebuffers(globeDepth);257 createTextures(globeDepth, context, width, height, hdr, clearGlobeDepth);258 createFramebuffers(globeDepth, context, clearGlobeDepth);259 }260 if (textureChanged || clearGlobeDepth !== globeDepth._clearGlobeDepth) {261 destroyPrimitiveFramebuffer(globeDepth);262 if (clearGlobeDepth) {263 createPrimitiveFramebuffer(globeDepth, context, width, height, hdr);264 }265 }266}267function updateCopyCommands(globeDepth, context, width, height, passState) {268 globeDepth._viewport.width = width;269 globeDepth._viewport.height = height;270 var useScissorTest = !BoundingRectangle.equals(271 globeDepth._viewport,272 passState.viewport273 );274 var updateScissor = useScissorTest !== globeDepth._useScissorTest;275 globeDepth._useScissorTest = useScissorTest;276 if (277 !BoundingRectangle.equals(globeDepth._scissorRectangle, passState.viewport)278 ) {279 globeDepth._scissorRectangle = BoundingRectangle.clone(280 passState.viewport,281 globeDepth._scissorRectangle282 );283 updateScissor = true;284 }285 if (286 !defined(globeDepth._rs) ||287 !BoundingRectangle.equals(globeDepth._viewport, globeDepth._rs.viewport) ||288 updateScissor289 ) {290 globeDepth._rs = RenderState.fromCache({291 viewport: globeDepth._viewport,292 scissorTest: {293 enabled: globeDepth._useScissorTest,294 rectangle: globeDepth._scissorRectangle,295 },296 });297 globeDepth._rsBlend = RenderState.fromCache({298 viewport: globeDepth._viewport,299 scissorTest: {300 enabled: globeDepth._useScissorTest,301 rectangle: globeDepth._scissorRectangle,302 },303 blending: BlendingState.ALPHA_BLEND,304 });305 // Copy packed depth only if the 3D Tiles bit is set306 globeDepth._rsUpdate = RenderState.fromCache({307 viewport: globeDepth._viewport,308 scissorTest: {309 enabled: globeDepth._useScissorTest,310 rectangle: globeDepth._scissorRectangle,311 },312 stencilTest: {313 enabled: true,314 frontFunction: StencilFunction.EQUAL,315 frontOperation: {316 fail: StencilOperation.KEEP,317 zFail: StencilOperation.KEEP,318 zPass: StencilOperation.KEEP,319 },320 backFunction: StencilFunction.NEVER,321 reference: StencilConstants.CESIUM_3D_TILE_MASK,322 mask: StencilConstants.CESIUM_3D_TILE_MASK,323 },324 });325 }326 if (!defined(globeDepth._copyDepthCommand)) {327 globeDepth._copyDepthCommand = context.createViewportQuadCommand(328 PassThroughDepth,329 {330 uniformMap: {331 u_depthTexture: function () {332 return globeDepth._depthStencilTexture;333 },334 },335 owner: globeDepth,336 }337 );338 }339 globeDepth._copyDepthCommand.framebuffer = globeDepth._copyDepthFramebuffer;340 globeDepth._copyDepthCommand.renderState = globeDepth._rs;341 if (!defined(globeDepth._copyColorCommand)) {342 globeDepth._copyColorCommand = context.createViewportQuadCommand(343 PassThrough,344 {345 uniformMap: {346 colorTexture: function () {347 return globeDepth._globeColorTexture;348 },349 },350 owner: globeDepth,351 }352 );353 }354 globeDepth._copyColorCommand.renderState = globeDepth._rs;355 if (!defined(globeDepth._tempCopyDepthCommand)) {356 globeDepth._tempCopyDepthCommand = context.createViewportQuadCommand(357 PassThroughDepth,358 {359 uniformMap: {360 u_depthTexture: function () {361 return globeDepth._tempCopyDepthTexture;362 },363 },364 owner: globeDepth,365 }366 );367 }368 globeDepth._tempCopyDepthCommand.framebuffer =369 globeDepth._tempCopyDepthFramebuffer;370 globeDepth._tempCopyDepthCommand.renderState = globeDepth._rs;371 if (!defined(globeDepth._updateDepthCommand)) {372 globeDepth._updateDepthCommand = context.createViewportQuadCommand(373 PassThrough,374 {375 uniformMap: {376 colorTexture: function () {377 return globeDepth._tempGlobeDepthTexture;378 },379 },380 owner: globeDepth,381 }382 );383 }384 globeDepth._updateDepthCommand.framebuffer =385 globeDepth._updateDepthFramebuffer;386 globeDepth._updateDepthCommand.renderState = globeDepth._rsUpdate;387 if (!defined(globeDepth._clearGlobeColorCommand)) {388 globeDepth._clearGlobeColorCommand = new ClearCommand({389 color: new Color(0.0, 0.0, 0.0, 0.0),390 stencil: 0.0,391 owner: globeDepth,392 });393 }394 globeDepth._clearGlobeColorCommand.framebuffer =395 globeDepth._globeColorFramebuffer;396 if (!defined(globeDepth._clearPrimitiveColorCommand)) {397 globeDepth._clearPrimitiveColorCommand = new ClearCommand({398 color: new Color(0.0, 0.0, 0.0, 0.0),399 stencil: 0.0,400 owner: globeDepth,401 });402 }403 globeDepth._clearPrimitiveColorCommand.framebuffer =404 globeDepth._primitiveColorFramebuffer;405 if (!defined(globeDepth._mergeColorCommand)) {406 globeDepth._mergeColorCommand = context.createViewportQuadCommand(407 PassThrough,408 {409 uniformMap: {410 colorTexture: function () {411 return globeDepth._primitiveColorTexture;412 },413 },414 owner: globeDepth,415 }416 );417 }418 globeDepth._mergeColorCommand.framebuffer = globeDepth._globeColorFramebuffer;419 globeDepth._mergeColorCommand.renderState = globeDepth._rsBlend;420}421GlobeDepth.prototype.executeDebugGlobeDepth = function (422 context,423 passState,424 useLogDepth425) {426 executeDebugGlobeDepth(this, context, passState, useLogDepth);427};428GlobeDepth.prototype.update = function (429 context,430 passState,431 viewport,432 hdr,433 clearGlobeDepth434) {435 var width = viewport.width;436 var height = viewport.height;437 updateFramebuffers(this, context, width, height, hdr, clearGlobeDepth);438 updateCopyCommands(this, context, width, height, passState);439 context.uniformState.globeDepthTexture = undefined;440 this._useHdr = hdr;441 this._clearGlobeDepth = clearGlobeDepth;442};443GlobeDepth.prototype.executeCopyDepth = function (context, passState) {444 if (defined(this._copyDepthCommand)) {445 this._copyDepthCommand.execute(context, passState);446 context.uniformState.globeDepthTexture = this._globeDepthTexture;447 }448};449GlobeDepth.prototype.executeUpdateDepth = function (450 context,451 passState,452 clearGlobeDepth453) {454 var depthTextureToCopy = passState.framebuffer.depthStencilTexture;455 if (clearGlobeDepth || depthTextureToCopy !== this._depthStencilTexture) {456 // First copy the depth to a temporary globe depth texture, then update the457 // main globe depth texture where the stencil bit for 3D Tiles is set.458 // This preserves the original globe depth except where 3D Tiles is rendered.459 // The additional texture and framebuffer resources are created on demand.460 if (defined(this._updateDepthCommand)) {461 if (462 !defined(this._updateDepthFramebuffer) ||463 this._updateDepthFramebuffer.depthStencilTexture !==464 depthTextureToCopy ||465 this._updateDepthFramebuffer.getColorTexture(0) !==466 this._globeDepthTexture467 ) {468 var width = this._globeDepthTexture.width;469 var height = this._globeDepthTexture.height;470 destroyUpdateDepthResources(this);471 createUpdateDepthResources(this, context, width, height, passState);472 updateCopyCommands(this, context, width, height, passState);473 }474 this._tempCopyDepthTexture = depthTextureToCopy;475 this._tempCopyDepthCommand.execute(context, passState);476 this._updateDepthCommand.execute(context, passState);477 }478 return;479 }480 // Fast path - the depth texture can be copied normally.481 if (defined(this._copyDepthCommand)) {482 this._copyDepthCommand.execute(context, passState);483 }484};485GlobeDepth.prototype.executeCopyColor = function (context, passState) {486 if (defined(this._copyColorCommand)) {487 this._copyColorCommand.execute(context, passState);488 }489};490GlobeDepth.prototype.executeMergeColor = function (context, passState) {491 if (defined(this._mergeColorCommand)) {492 this._mergeColorCommand.execute(context, passState);493 }494};495GlobeDepth.prototype.clear = function (context, passState, clearColor) {496 var clear = this._clearGlobeColorCommand;497 if (defined(clear)) {498 Color.clone(clearColor, clear.color);499 clear.execute(context, passState);500 }501 clear = this._clearPrimitiveColorCommand;502 if (defined(clear) && defined(this._primitiveColorFramebuffer)) {503 clear.execute(context, passState);504 }505};506GlobeDepth.prototype.isDestroyed = function () {507 return false;508};509GlobeDepth.prototype.destroy = function () {510 destroyTextures(this);511 destroyFramebuffers(this);512 destroyPrimitiveFramebuffer(this);513 destroyUpdateDepthResources(this);514 if (defined(this._copyColorCommand)) {515 this._copyColorCommand.shaderProgram = this._copyColorCommand.shaderProgram.destroy();516 }517 if (defined(this._copyDepthCommand)) {518 this._copyDepthCommand.shaderProgram = this._copyDepthCommand.shaderProgram.destroy();519 }520 if (defined(this._tempCopyDepthCommand)) {521 this._tempCopyDepthCommand.shaderProgram = this._tempCopyDepthCommand.shaderProgram.destroy();522 }523 if (defined(this._updateDepthCommand)) {524 this._updateDepthCommand.shaderProgram = this._updateDepthCommand.shaderProgram.destroy();525 }526 if (defined(this._mergeColorCommand)) {527 this._mergeColorCommand.shaderProgram = this._mergeColorCommand.shaderProgram.destroy();528 }529 if (defined(this._debugGlobeDepthViewportCommand)) {530 this._debugGlobeDepthViewportCommand.shaderProgram = this._debugGlobeDepthViewportCommand.shaderProgram.destroy();531 }532 return destroyObject(this);533};...

Full Screen

Full Screen

shanten.py

Source:shanten.py Github

copy

Full Screen

1import math2from typing import List3from mahjong.constants import HONOR_INDICES, TERMINAL_INDICES4class Shanten:5 AGARI_STATE = -16 tiles = []7 number_melds = 08 number_tatsu = 09 number_pairs = 010 number_jidahai = 011 number_characters = 012 number_isolated_tiles = 013 min_shanten = 014 def calculate_shanten(self, tiles_34: List[int], use_chiitoitsu: bool = True, use_kokushi: bool = True) -> int:15 """16 Return the minimum shanten for provided hand,17 it will consider chiitoitsu and kokushi options if possible.18 """19 shanten_results = [self.calculate_shanten_for_regular_hand(tiles_34)]20 if use_chiitoitsu:21 shanten_results.append(self.calculate_shanten_for_chiitoitsu_hand(tiles_34))22 if use_kokushi:23 shanten_results.append(self.calculate_shanten_for_kokushi_hand(tiles_34))24 return min(shanten_results)25 def calculate_shanten_for_chiitoitsu_hand(self, tiles_34: List[int]) -> int:26 """27 Calculate the number of shanten for chiitoitsu hand28 """29 pairs = len([x for x in tiles_34 if x >= 2])30 if pairs == 7:31 return Shanten.AGARI_STATE32 return 6 - pairs33 def calculate_shanten_for_kokushi_hand(self, tiles_34: List[int]) -> int:34 """35 Calculate the number of shanten for kokushi musou hand36 """37 indices = TERMINAL_INDICES + HONOR_INDICES38 completed_terminals = 039 for i in indices:40 completed_terminals += tiles_34[i] >= 241 terminals = 042 for i in indices:43 terminals += tiles_34[i] != 044 return 13 - terminals - (completed_terminals and 1 or 0)45 def calculate_shanten_for_regular_hand(self, tiles_34: List[int]) -> int:46 """47 Calculate the number of shanten for regular hand48 """49 # we will modify tiles array later, so we need to use a copy50 tiles_34 = tiles_34[:]51 self._init(tiles_34)52 count_of_tiles = sum(tiles_34)53 assert count_of_tiles <= 14, f"Too many tiles = {count_of_tiles}"54 self._remove_character_tiles(count_of_tiles)55 init_mentsu = math.floor((14 - count_of_tiles) / 3)56 self._scan(init_mentsu)57 return self.min_shanten58 def _init(self, tiles):59 self.tiles = tiles60 self.number_melds = 061 self.number_tatsu = 062 self.number_pairs = 063 self.number_jidahai = 064 self.number_characters = 065 self.number_isolated_tiles = 066 self.min_shanten = 867 def _scan(self, init_mentsu):68 self.number_characters = 069 for i in range(0, 27):70 self.number_characters |= (self.tiles[i] == 4) << i71 self.number_melds += init_mentsu72 self._run(0)73 def _run(self, depth):74 if self.min_shanten == Shanten.AGARI_STATE:75 return76 while not self.tiles[depth]:77 depth += 178 if depth >= 27:79 break80 if depth >= 27:81 return self._update_result()82 i = depth83 if i > 8:84 i -= 985 if i > 8:86 i -= 987 if self.tiles[depth] == 4:88 self._increase_set(depth)89 if i < 7 and self.tiles[depth + 2]:90 if self.tiles[depth + 1]:91 self._increase_syuntsu(depth)92 self._run(depth + 1)93 self._decrease_syuntsu(depth)94 self._increase_tatsu_second(depth)95 self._run(depth + 1)96 self._decrease_tatsu_second(depth)97 if i < 8 and self.tiles[depth + 1]:98 self._increase_tatsu_first(depth)99 self._run(depth + 1)100 self._decrease_tatsu_first(depth)101 self._increase_isolated_tile(depth)102 self._run(depth + 1)103 self._decrease_isolated_tile(depth)104 self._decrease_set(depth)105 self._increase_pair(depth)106 if i < 7 and self.tiles[depth + 2]:107 if self.tiles[depth + 1]:108 self._increase_syuntsu(depth)109 self._run(depth)110 self._decrease_syuntsu(depth)111 self._increase_tatsu_second(depth)112 self._run(depth + 1)113 self._decrease_tatsu_second(depth)114 if i < 8 and self.tiles[depth + 1]:115 self._increase_tatsu_first(depth)116 self._run(depth + 1)117 self._decrease_tatsu_first(depth)118 self._decrease_pair(depth)119 if self.tiles[depth] == 3:120 self._increase_set(depth)121 self._run(depth + 1)122 self._decrease_set(depth)123 self._increase_pair(depth)124 if i < 7 and self.tiles[depth + 1] and self.tiles[depth + 2]:125 self._increase_syuntsu(depth)126 self._run(depth + 1)127 self._decrease_syuntsu(depth)128 else:129 if i < 7 and self.tiles[depth + 2]:130 self._increase_tatsu_second(depth)131 self._run(depth + 1)132 self._decrease_tatsu_second(depth)133 if i < 8 and self.tiles[depth + 1]:134 self._increase_tatsu_first(depth)135 self._run(depth + 1)136 self._decrease_tatsu_first(depth)137 self._decrease_pair(depth)138 if i < 7 and self.tiles[depth + 2] >= 2 and self.tiles[depth + 1] >= 2:139 self._increase_syuntsu(depth)140 self._increase_syuntsu(depth)141 self._run(depth)142 self._decrease_syuntsu(depth)143 self._decrease_syuntsu(depth)144 if self.tiles[depth] == 2:145 self._increase_pair(depth)146 self._run(depth + 1)147 self._decrease_pair(depth)148 if i < 7 and self.tiles[depth + 2] and self.tiles[depth + 1]:149 self._increase_syuntsu(depth)150 self._run(depth)151 self._decrease_syuntsu(depth)152 if self.tiles[depth] == 1:153 if i < 6 and self.tiles[depth + 1] == 1 and self.tiles[depth + 2] and self.tiles[depth + 3] != 4:154 self._increase_syuntsu(depth)155 self._run(depth + 2)156 self._decrease_syuntsu(depth)157 else:158 self._increase_isolated_tile(depth)159 self._run(depth + 1)160 self._decrease_isolated_tile(depth)161 if i < 7 and self.tiles[depth + 2]:162 if self.tiles[depth + 1]:163 self._increase_syuntsu(depth)164 self._run(depth + 1)165 self._decrease_syuntsu(depth)166 self._increase_tatsu_second(depth)167 self._run(depth + 1)168 self._decrease_tatsu_second(depth)169 if i < 8 and self.tiles[depth + 1]:170 self._increase_tatsu_first(depth)171 self._run(depth + 1)172 self._decrease_tatsu_first(depth)173 def _update_result(self):174 ret_shanten = 8 - self.number_melds * 2 - self.number_tatsu - self.number_pairs175 n_mentsu_kouho = self.number_melds + self.number_tatsu176 if self.number_pairs:177 n_mentsu_kouho += self.number_pairs - 1178 elif self.number_characters and self.number_isolated_tiles:179 if (self.number_characters | self.number_isolated_tiles) == self.number_characters:180 ret_shanten += 1181 if n_mentsu_kouho > 4:182 ret_shanten += n_mentsu_kouho - 4183 if ret_shanten != Shanten.AGARI_STATE and ret_shanten < self.number_jidahai:184 ret_shanten = self.number_jidahai185 if ret_shanten < self.min_shanten:186 self.min_shanten = ret_shanten187 def _increase_set(self, k):188 self.tiles[k] -= 3189 self.number_melds += 1190 def _decrease_set(self, k):191 self.tiles[k] += 3192 self.number_melds -= 1193 def _increase_pair(self, k):194 self.tiles[k] -= 2195 self.number_pairs += 1196 def _decrease_pair(self, k):197 self.tiles[k] += 2198 self.number_pairs -= 1199 def _increase_syuntsu(self, k):200 self.tiles[k] -= 1201 self.tiles[k + 1] -= 1202 self.tiles[k + 2] -= 1203 self.number_melds += 1204 def _decrease_syuntsu(self, k):205 self.tiles[k] += 1206 self.tiles[k + 1] += 1207 self.tiles[k + 2] += 1208 self.number_melds -= 1209 def _increase_tatsu_first(self, k):210 self.tiles[k] -= 1211 self.tiles[k + 1] -= 1212 self.number_tatsu += 1213 def _decrease_tatsu_first(self, k):214 self.tiles[k] += 1215 self.tiles[k + 1] += 1216 self.number_tatsu -= 1217 def _increase_tatsu_second(self, k):218 self.tiles[k] -= 1219 self.tiles[k + 2] -= 1220 self.number_tatsu += 1221 def _decrease_tatsu_second(self, k):222 self.tiles[k] += 1223 self.tiles[k + 2] += 1224 self.number_tatsu -= 1225 def _increase_isolated_tile(self, k):226 self.tiles[k] -= 1227 self.number_isolated_tiles |= 1 << k228 def _decrease_isolated_tile(self, k):229 self.tiles[k] += 1230 self.number_isolated_tiles |= 1 << k231 def _scan_chiitoitsu_and_kokushi(self, chiitoitsu, kokushi):232 shanten = self.min_shanten233 indices = [0, 8, 9, 17, 18, 26, 27, 28, 29, 30, 31, 32, 33]234 completed_terminals = 0235 for i in indices:236 completed_terminals += self.tiles[i] >= 2237 terminals = 0238 for i in indices:239 terminals += self.tiles[i] != 0240 indices = [1, 2, 3, 4, 5, 6, 7, 10, 11, 12, 13, 14, 15, 16, 19, 20, 21, 22, 23, 24, 25]241 completed_pairs = completed_terminals242 for i in indices:243 completed_pairs += self.tiles[i] >= 2244 pairs = terminals245 for i in indices:246 pairs += self.tiles[i] != 0247 if chiitoitsu:248 ret_shanten = 6 - completed_pairs + (pairs < 7 and 7 - pairs or 0)249 if ret_shanten < shanten:250 shanten = ret_shanten251 if kokushi:252 ret_shanten = 13 - terminals - (completed_terminals and 1 or 0)253 if ret_shanten < shanten:254 shanten = ret_shanten255 return shanten256 def _remove_character_tiles(self, nc):257 number = 0258 isolated = 0259 for i in range(27, 34):260 if self.tiles[i] == 4:261 self.number_melds += 1262 self.number_jidahai += 1263 number |= 1 << (i - 27)264 isolated |= 1 << (i - 27)265 if self.tiles[i] == 3:266 self.number_melds += 1267 if self.tiles[i] == 2:268 self.number_pairs += 1269 if self.tiles[i] == 1:270 isolated |= 1 << (i - 27)271 if self.number_jidahai and (nc % 3) == 2:272 self.number_jidahai -= 1273 if isolated:274 self.number_isolated_tiles |= 1 << 27275 if (number | isolated) == number:...

Full Screen

Full Screen

esnext.array.d.ts

Source:esnext.array.d.ts Github

copy

Full Screen

1interface ReadonlyArray<T> {23 /**4 * Calls a defined callback function on each element of an array. Then, flattens the result into5 * a new array.6 * This is identical to a map followed by flat with depth 1.7 *8 * @param callback A function that accepts up to three arguments. The flatMap method calls the9 * callback function one time for each element in the array.10 * @param thisArg An object to which the this keyword can refer in the callback function. If11 * thisArg is omitted, undefined is used as the this value.12 */13 flatMap<U, This = undefined> (14 callback: (this: This, value: T, index: number, array: T[]) => U|ReadonlyArray<U>,15 thisArg?: This16 ): U[]171819 /**20 * Returns a new array with all sub-array elements concatenated into it recursively up to the21 * specified depth.22 *23 * @param depth The maximum recursion depth24 */25 flat<U>(this:26 ReadonlyArray<U[][][][]> |2728 ReadonlyArray<ReadonlyArray<U[][][]>> |29 ReadonlyArray<ReadonlyArray<U[][]>[]> |30 ReadonlyArray<ReadonlyArray<U[]>[][]> |31 ReadonlyArray<ReadonlyArray<U>[][][]> |3233 ReadonlyArray<ReadonlyArray<ReadonlyArray<U[][]>>> |34 ReadonlyArray<ReadonlyArray<ReadonlyArray<U>[][]>> |35 ReadonlyArray<ReadonlyArray<ReadonlyArray<U>>[][]> |36 ReadonlyArray<ReadonlyArray<ReadonlyArray<U>[]>[]> |37 ReadonlyArray<ReadonlyArray<ReadonlyArray<U[]>>[]> |38 ReadonlyArray<ReadonlyArray<ReadonlyArray<U[]>[]>> |3940 ReadonlyArray<ReadonlyArray<ReadonlyArray<ReadonlyArray<U[]>>>> |41 ReadonlyArray<ReadonlyArray<ReadonlyArray<ReadonlyArray<U>[]>>> |42 ReadonlyArray<ReadonlyArray<ReadonlyArray<ReadonlyArray<U>>[]>> |43 ReadonlyArray<ReadonlyArray<ReadonlyArray<ReadonlyArray<U>>>[]> |4445 ReadonlyArray<ReadonlyArray<ReadonlyArray<ReadonlyArray<ReadonlyArray<U>>>>>,46 depth: 4): U[];4748 /**49 * Returns a new array with all sub-array elements concatenated into it recursively up to the50 * specified depth.51 *52 * @param depth The maximum recursion depth53 */54 flat<U>(this:55 ReadonlyArray<U[][][]> |5657 ReadonlyArray<ReadonlyArray<U>[][]> |58 ReadonlyArray<ReadonlyArray<U[]>[]> |59 ReadonlyArray<ReadonlyArray<U[][]>> |6061 ReadonlyArray<ReadonlyArray<ReadonlyArray<U[]>>> |62 ReadonlyArray<ReadonlyArray<ReadonlyArray<U>[]>> |63 ReadonlyArray<ReadonlyArray<ReadonlyArray<U>>[]> |6465 ReadonlyArray<ReadonlyArray<ReadonlyArray<ReadonlyArray<U>>>>,66 depth: 3): U[];6768 /**69 * Returns a new array with all sub-array elements concatenated into it recursively up to the70 * specified depth.71 *72 * @param depth The maximum recursion depth73 */74 flat<U>(this:75 ReadonlyArray<U[][]> |7677 ReadonlyArray<ReadonlyArray<U[]>> |78 ReadonlyArray<ReadonlyArray<U>[]> |7980 ReadonlyArray<ReadonlyArray<ReadonlyArray<U>>>,81 depth: 2): U[];8283 /**84 * Returns a new array with all sub-array elements concatenated into it recursively up to the85 * specified depth.86 *87 * @param depth The maximum recursion depth88 */89 flat<U>(this:90 ReadonlyArray<U[]> |91 ReadonlyArray<ReadonlyArray<U>>,92 depth?: 193 ): U[];9495 /**96 * Returns a new array with all sub-array elements concatenated into it recursively up to the97 * specified depth.98 *99 * @param depth The maximum recursion depth100 */101 flat<U>(this:102 ReadonlyArray<U>,103 depth: 0104 ): U[];105106 /**107 * Returns a new array with all sub-array elements concatenated into it recursively up to the108 * specified depth. If no depth is provided, flat method defaults to the depth of 1.109 *110 * @param depth The maximum recursion depth111 */112 flat<U>(depth?: number): any[];113 }114115interface Array<T> {116117 /**118 * Calls a defined callback function on each element of an array. Then, flattens the result into119 * a new array.120 * This is identical to a map followed by flat with depth 1.121 *122 * @param callback A function that accepts up to three arguments. The flatMap method calls the123 * callback function one time for each element in the array.124 * @param thisArg An object to which the this keyword can refer in the callback function. If125 * thisArg is omitted, undefined is used as the this value.126 */127 flatMap<U, This = undefined> (128 callback: (this: This, value: T, index: number, array: T[]) => U|ReadonlyArray<U>,129 thisArg?: This130 ): U[]131132 /**133 * Returns a new array with all sub-array elements concatenated into it recursively up to the134 * specified depth.135 *136 * @param depth The maximum recursion depth137 */138 flat<U>(this: U[][][][][][][][], depth: 7): U[];139140 /**141 * Returns a new array with all sub-array elements concatenated into it recursively up to the142 * specified depth.143 *144 * @param depth The maximum recursion depth145 */146 flat<U>(this: U[][][][][][][], depth: 6): U[];147148 /**149 * Returns a new array with all sub-array elements concatenated into it recursively up to the150 * specified depth.151 *152 * @param depth The maximum recursion depth153 */154 flat<U>(this: U[][][][][][], depth: 5): U[];155156 /**157 * Returns a new array with all sub-array elements concatenated into it recursively up to the158 * specified depth.159 *160 * @param depth The maximum recursion depth161 */162 flat<U>(this: U[][][][][], depth: 4): U[];163164 /**165 * Returns a new array with all sub-array elements concatenated into it recursively up to the166 * specified depth.167 *168 * @param depth The maximum recursion depth169 */170 flat<U>(this: U[][][][], depth: 3): U[];171172 /**173 * Returns a new array with all sub-array elements concatenated into it recursively up to the174 * specified depth.175 *176 * @param depth The maximum recursion depth177 */178 flat<U>(this: U[][][], depth: 2): U[];179180 /**181 * Returns a new array with all sub-array elements concatenated into it recursively up to the182 * specified depth.183 *184 * @param depth The maximum recursion depth185 */186 flat<U>(this: U[][], depth?: 1): U[];187188 /**189 * Returns a new array with all sub-array elements concatenated into it recursively up to the190 * specified depth.191 *192 * @param depth The maximum recursion depth193 */194 flat<U>(this: U[], depth: 0): U[];195196 /**197 * Returns a new array with all sub-array elements concatenated into it recursively up to the198 * specified depth. If no depth is provided, flat method defaults to the depth of 1.199 *200 * @param depth The maximum recursion depth201 */202 flat<U>(depth?: number): any[]; ...

Full Screen

Full Screen

PickDepth.js

Source:PickDepth.js Github

copy

Full Screen

1import Cartesian4 from "../Core/Cartesian4.js";2import defined from "../Core/defined.js";3import destroyObject from "../Core/destroyObject.js";4import PixelFormat from "../Core/PixelFormat.js";5import Framebuffer from "../Renderer/Framebuffer.js";6import PixelDatatype from "../Renderer/PixelDatatype.js";7import RenderState from "../Renderer/RenderState.js";8import ShaderSource from "../Renderer/ShaderSource.js";9import Texture from "../Renderer/Texture.js";10/**11 * @private12 */13function PickDepth() {14 this._framebuffer = undefined;15 this._depthTexture = undefined;16 this._textureToCopy = undefined;17 this._copyDepthCommand = undefined;18 this._useLogDepth = undefined;19 this._debugPickDepthViewportCommand = undefined;20}21function executeDebugPickDepth(pickDepth, context, passState, useLogDepth) {22 if (23 !defined(pickDepth._debugPickDepthViewportCommand) ||24 useLogDepth !== pickDepth._useLogDepth25 ) {26 var fsSource =27 "uniform highp sampler2D u_texture;\n" +28 "varying vec2 v_textureCoordinates;\n" +29 "void main()\n" +30 "{\n" +31 " float z_window = czm_unpackDepth(texture2D(u_texture, v_textureCoordinates));\n" +32 " z_window = czm_reverseLogDepth(z_window); \n" +33 " float n_range = czm_depthRange.near;\n" +34 " float f_range = czm_depthRange.far;\n" +35 " float z_ndc = (2.0 * z_window - n_range - f_range) / (f_range - n_range);\n" +36 " float scale = pow(z_ndc * 0.5 + 0.5, 8.0);\n" +37 " gl_FragColor = vec4(mix(vec3(0.0), vec3(1.0), scale), 1.0);\n" +38 "}\n";39 var fs = new ShaderSource({40 defines: [useLogDepth ? "LOG_DEPTH" : ""],41 sources: [fsSource],42 });43 pickDepth._debugPickDepthViewportCommand = context.createViewportQuadCommand(44 fs,45 {46 uniformMap: {47 u_texture: function () {48 return pickDepth._depthTexture;49 },50 },51 owner: pickDepth,52 }53 );54 pickDepth._useLogDepth = useLogDepth;55 }56 pickDepth._debugPickDepthViewportCommand.execute(context, passState);57}58function destroyTextures(pickDepth) {59 pickDepth._depthTexture =60 pickDepth._depthTexture &&61 !pickDepth._depthTexture.isDestroyed() &&62 pickDepth._depthTexture.destroy();63}64function destroyFramebuffers(pickDepth) {65 pickDepth._framebuffer =66 pickDepth._framebuffer &&67 !pickDepth._framebuffer.isDestroyed() &&68 pickDepth._framebuffer.destroy();69}70function createTextures(pickDepth, context, width, height) {71 pickDepth._depthTexture = new Texture({72 context: context,73 width: width,74 height: height,75 pixelFormat: PixelFormat.RGBA,76 pixelDatatype: PixelDatatype.UNSIGNED_BYTE,77 });78}79function createFramebuffers(pickDepth, context, width, height) {80 destroyTextures(pickDepth);81 destroyFramebuffers(pickDepth);82 createTextures(pickDepth, context, width, height);83 pickDepth._framebuffer = new Framebuffer({84 context: context,85 colorTextures: [pickDepth._depthTexture],86 destroyAttachments: false,87 });88}89function updateFramebuffers(pickDepth, context, depthTexture) {90 var width = depthTexture.width;91 var height = depthTexture.height;92 var texture = pickDepth._depthTexture;93 var textureChanged =94 !defined(texture) || texture.width !== width || texture.height !== height;95 if (!defined(pickDepth._framebuffer) || textureChanged) {96 createFramebuffers(pickDepth, context, width, height);97 }98}99function updateCopyCommands(pickDepth, context, depthTexture) {100 if (!defined(pickDepth._copyDepthCommand)) {101 var fs =102 "uniform highp sampler2D u_texture;\n" +103 "varying vec2 v_textureCoordinates;\n" +104 "void main()\n" +105 "{\n" +106 " gl_FragColor = czm_packDepth(texture2D(u_texture, v_textureCoordinates).r);\n" +107 "}\n";108 pickDepth._copyDepthCommand = context.createViewportQuadCommand(fs, {109 renderState: RenderState.fromCache(),110 uniformMap: {111 u_texture: function () {112 return pickDepth._textureToCopy;113 },114 },115 owner: pickDepth,116 });117 }118 pickDepth._textureToCopy = depthTexture;119 pickDepth._copyDepthCommand.framebuffer = pickDepth._framebuffer;120}121PickDepth.prototype.executeDebugPickDepth = function (122 context,123 passState,124 useLogDepth125) {126 executeDebugPickDepth(this, context, passState, useLogDepth);127};128PickDepth.prototype.update = function (context, depthTexture) {129 updateFramebuffers(this, context, depthTexture);130 updateCopyCommands(this, context, depthTexture);131};132var scratchPackedDepth = new Cartesian4();133var packedDepthScale = new Cartesian4(134 1.0,135 1.0 / 255.0,136 1.0 / 65025.0,137 1.0 / 16581375.0138);139PickDepth.prototype.getDepth = function (context, x, y) {140 // If this function is called before the framebuffer is created, the depth is undefined.141 if (!defined(this._framebuffer)) {142 return undefined;143 }144 var pixels = context.readPixels({145 x: x,146 y: y,147 width: 1,148 height: 1,149 framebuffer: this._framebuffer,150 });151 var packedDepth = Cartesian4.unpack(pixels, 0, scratchPackedDepth);152 Cartesian4.divideByScalar(packedDepth, 255.0, packedDepth);153 return Cartesian4.dot(packedDepth, packedDepthScale);154};155PickDepth.prototype.executeCopyDepth = function (context, passState) {156 this._copyDepthCommand.execute(context, passState);157};158PickDepth.prototype.isDestroyed = function () {159 return false;160};161PickDepth.prototype.destroy = function () {162 destroyTextures(this);163 destroyFramebuffers(this);164 if (defined(this._copyDepthCommand)) {165 this._copyDepthCommand.shaderProgram =166 defined(this._copyDepthCommand.shaderProgram) &&167 this._copyDepthCommand.shaderProgram.destroy();168 }169 return destroyObject(this);170};...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run hypothesis automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful