text stringlengths 9 39.2M | dir stringlengths 26 295 | lang stringclasses 185
values | created_date timestamp[us] | updated_date timestamp[us] | repo_name stringlengths 1 97 | repo_full_name stringlengths 7 106 | star int64 1k 183k | len_tokens int64 1 13.8M |
|---|---|---|---|---|---|---|---|---|
```objective-c
//
// AppDelegate.m
// weak-strong-drance-demo
//
// Created by on 12/21/16.
//
#import "AppDelegate.h"
@interface AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point... | /content/code_sandbox/Tips/Heap-Stack Dance/weak-strong-drance-demo/weak-strong-drance-demo/AppDelegate.m | objective-c | 2016-04-13T15:55:28 | 2024-06-10T16:47:34 | iOSBlog | ChenYilong/iOSBlog | 1,122 | 374 |
```objective-c
//
// Foo.m
// weak-strong-drance-demo
//
// Created by on 12/21/16.
//
#import "Foo.h"
typedef void (^Completion)(Foo *foo);
@interface Foo ()
@property (nonatomic, copy) Completion completion1;
@property (nonatomic, copy) Completion completion2;
@end
@implementation Foo
- (instancetype)init ... | /content/code_sandbox/Tips/Heap-Stack Dance/weak-strong-drance-demo/weak-strong-drance-demo/Foo.m | objective-c | 2016-04-13T15:55:28 | 2024-06-10T16:47:34 | iOSBlog | ChenYilong/iOSBlog | 1,122 | 242 |
```objective-c
//
// ViewController.h
// CYLGCDRunloopDemo
//
// Created by chenyilong on 2017/6/7.
//
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
@end
``` | /content/code_sandbox/Tips/避免使用GCD-Global队列创建Runloop常驻线程/CYLGCDRunloopDemo/CYLGCDRunloopDemo/ViewController.h | objective-c | 2016-04-13T15:55:28 | 2024-06-10T16:47:34 | iOSBlog | ChenYilong/iOSBlog | 1,122 | 48 |
```objective-c
//
// AppDelegate.h
// CYLGCDRunloopDemo
//
// Created by chenyilong on 2017/6/7.
//
#import <UIKit/UIKit.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@end
``` | /content/code_sandbox/Tips/避免使用GCD-Global队列创建Runloop常驻线程/CYLGCDRunloopDemo/CYLGCDRunloopDemo/AppDelegate.h | objective-c | 2016-04-13T15:55:28 | 2024-06-10T16:47:34 | iOSBlog | ChenYilong/iOSBlog | 1,122 | 60 |
```objective-c
//
// Foo.h
// CYLGCDRunloopDemo
//
// Created by chenyilong on 2017/6/7.
//
#import <Foundation/Foundation.h>
@interface Foo : NSObject
- (id)test;
@end
``` | /content/code_sandbox/Tips/避免使用GCD-Global队列创建Runloop常驻线程/CYLGCDRunloopDemo/CYLGCDRunloopDemo/Foo.h | objective-c | 2016-04-13T15:55:28 | 2024-06-10T16:47:34 | iOSBlog | ChenYilong/iOSBlog | 1,122 | 53 |
```objective-c
//
// ViewController.m
// CYLGCDRunloopDemo
//
// Created by chenyilong on 2017/6/7.
//
#import "ViewController.h"
#import "Foo.h"
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// NSOperationQueue *asyncOperationQueue = [[NSOperationQueue alloc] init];
// ... | /content/code_sandbox/Tips/避免使用GCD-Global队列创建Runloop常驻线程/CYLGCDRunloopDemo/CYLGCDRunloopDemo/ViewController.m | objective-c | 2016-04-13T15:55:28 | 2024-06-10T16:47:34 | iOSBlog | ChenYilong/iOSBlog | 1,122 | 270 |
```objective-c
//
// AppDelegate.m
// CYLGCDRunloopDemo
//
// Created by chenyilong on 2017/6/7.
//
#import "AppDelegate.h"
#import "Foo.h"
@interface AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
... | /content/code_sandbox/Tips/避免使用GCD-Global队列创建Runloop常驻线程/CYLGCDRunloopDemo/CYLGCDRunloopDemo/AppDelegate.m | objective-c | 2016-04-13T15:55:28 | 2024-06-10T16:47:34 | iOSBlog | ChenYilong/iOSBlog | 1,122 | 691 |
```objective-c
//
// main.m
// CYLGCDRunloopDemo
//
// Created by chenyilong on 2017/6/7.
//
#import <UIKit/UIKit.h>
#import "AppDelegate.h"
int main(int argc, char * argv[]) {
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
}
``` | /content/code_sandbox/Tips/避免使用GCD-Global队列创建Runloop常驻线程/CYLGCDRunloopDemo/CYLGCDRunloopDemo/main.m | objective-c | 2016-04-13T15:55:28 | 2024-06-10T16:47:34 | iOSBlog | ChenYilong/iOSBlog | 1,122 | 78 |
```objective-c
//
// Foo.m
// CYLGCDRunloopDemo
//
// Created by chenyilong on 2017/6/7.
//
#import "Foo.h"
@interface Foo() {
NSRunLoop *_runloop;
NSTimer *_timeoutTimer;
NSTimeInterval _timeoutInterval;
dispatch_semaphore_t _sem;
}
@end
@implementation Foo
- (instancetype)init {
if (!(sel... | /content/code_sandbox/Tips/避免使用GCD-Global队列创建Runloop常驻线程/CYLGCDRunloopDemo/CYLGCDRunloopDemo/Foo.m | objective-c | 2016-04-13T15:55:28 | 2024-06-10T16:47:34 | iOSBlog | ChenYilong/iOSBlog | 1,122 | 523 |
```objective-c
//
// CYLGCDRunloopDemoUITests.m
// CYLGCDRunloopDemoUITests
//
// Created by chenyilong on 2017/6/7.
//
#import <XCTest/XCTest.h>
@interface CYLGCDRunloopDemoUITests : XCTestCase
@end
@implementation CYLGCDRunloopDemoUITests
- (void)setUp {
[super setUp];
// Put setup code here. Thi... | /content/code_sandbox/Tips/避免使用GCD-Global队列创建Runloop常驻线程/CYLGCDRunloopDemo/CYLGCDRunloopDemoUITests/CYLGCDRunloopDemoUITests.m | objective-c | 2016-04-13T15:55:28 | 2024-06-10T16:47:34 | iOSBlog | ChenYilong/iOSBlog | 1,122 | 282 |
```objective-c
//
// CYLGCDRunloopDemoTests.m
// CYLGCDRunloopDemoTests
//
// Created by chenyilong on 2017/6/7.
//
#import <XCTest/XCTest.h>
@interface CYLGCDRunloopDemoTests : XCTestCase
@end
@implementation CYLGCDRunloopDemoTests
- (void)setUp {
[super setUp];
// Put setup code here. This method is c... | /content/code_sandbox/Tips/避免使用GCD-Global队列创建Runloop常驻线程/CYLGCDRunloopDemo/CYLGCDRunloopDemoTests/CYLGCDRunloopDemoTests.m | objective-c | 2016-04-13T15:55:28 | 2024-06-10T16:47:34 | iOSBlog | ChenYilong/iOSBlog | 1,122 | 219 |
```python
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import socket
import sys
from src.JsonReader import JsonReader
from src.tools import is_alphabet
from src.tools import ie
from src.tools import get_ip
from src.tools import report_new_word
from src.tools import report_old_word
class WudaoServer:
def __init... | /content/code_sandbox/wudao-dict/WudaoServer.py | python | 2016-07-04T11:09:37 | 2024-08-15T07:16:56 | Wudao-dict | ChestnutHeng/Wudao-dict | 1,126 | 527 |
```shell
#!/bin/bash
#
if [ ! -d usr ]
then
mkdir usr
fi
chmod -R 777 usr
# wd
echo '#!/bin/bash'>./wd
echo 'save_path=$PWD'>>./wd
echo 'cd '$PWD >>./wd
echo './wdd $*'>>./wd
echo 'cd $save_path'>>./wd
sysOS=`uname -s`
if [ $sysOS == "Darwin" ];then
sudo cp ./wd /usr/local/bin/wd
sudo chmod +x /usr/loc... | /content/code_sandbox/wudao-dict/setup.sh | shell | 2016-07-04T11:09:37 | 2024-08-15T07:16:56 | Wudao-dict | ChestnutHeng/Wudao-dict | 1,126 | 272 |
```python
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'mainwindow.ui'
#
# Created by: PyQt5 UI code generator 5.7
#
# WARNING! All changes made in this file will be lost!
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
... | /content/code_sandbox/wudao-dict/mainwindow_ui.py | python | 2016-07-04T11:09:37 | 2024-08-15T07:16:56 | Wudao-dict | ChestnutHeng/Wudao-dict | 1,126 | 630 |
```python
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
import sys
import json
from mainwindow_ui import Ui_MainWindow
from src.GuiDraw import GuiDraw
from src.WudaoClient import WudaoClient
from src.tools import is_alphabet
from src.UserHistory import UserHistory
class MainWindo... | /content/code_sandbox/wudao-dict/mainwindow.py | python | 2016-07-04T11:09:37 | 2024-08-15T07:16:56 | Wudao-dict | ChestnutHeng/Wudao-dict | 1,126 | 996 |
```python
from urllib.request import urlopen
from urllib.parse import urlparse
from urllib.parse import quote
import os
import urllib.error
RED_PATTERN = '\033[31m%s\033[0m'
def ie():
try:
urlopen('path_to_url timeout=1)
return True
except urllib.error.URLError as err:
return False
d... | /content/code_sandbox/wudao-dict/WudaoUpgrade.py | python | 2016-07-04T11:09:37 | 2024-08-15T07:16:56 | Wudao-dict | ChestnutHeng/Wudao-dict | 1,126 | 224 |
```shell
#!/bin/bash
wd -k
sysOS=`uname -s`
if [ $sysOS == "Darwin" ];then
# wd
sudo rm -f /usr/local/bin/wd
#
sudo rm -f /usr/local/etc/bash_completion.d/wd
else
# wd
sudo rm -f /usr/bin/wd
#
sudo rm -f /etc/bash_completion.d/wd
fi
echo 'Uninstall Finished! '
``` | /content/code_sandbox/wudao-dict/uninstall.sh | shell | 2016-07-04T11:09:37 | 2024-08-15T07:16:56 | Wudao-dict | ChestnutHeng/Wudao-dict | 1,126 | 105 |
```python
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import json
import sys
import os
import socket
from src.CommandDraw import CommandDraw
from src.UserHistory import UserHistory
from src.WudaoClient import WudaoClient
from src.tools import is_alphabet
from src.tools import ie
class WudaoCommand:
def __ini... | /content/code_sandbox/wudao-dict/WudaoCommand.py | python | 2016-07-04T11:09:37 | 2024-08-15T07:16:56 | Wudao-dict | ChestnutHeng/Wudao-dict | 1,126 | 1,501 |
```python
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from __future__ import print_function
import re
tag_re = re.compile('^[a-z0-9]+$')
attribselect_re = re.compile(
r'^(?P<tag>\w+)?\[(?P<attribute>[\w-]+)(?P<operator>[=~\|\^\$\*]?)' +
r'=?"?(?P<value>[^\]"]*)"?\]$'
)
# /^(\w+)\[([\w-]+)([=~\|\^\$\*]?)=... | /content/code_sandbox/wudao-dict/dict/dict_pys/wd.py | python | 2016-07-04T11:09:37 | 2024-08-15T07:16:56 | Wudao-dict | ChestnutHeng/Wudao-dict | 1,126 | 3,739 |
```python
#coding=utf8
import json
import zlib
import sys
# build
f = open('en.z','r')
dic = {}
lines = f.readlines()
prev_word, prev_no = lines[0].split('|')
for v in lines[1:]:
word, no = v.split('|')
dic[prev_word] = [int(prev_no), int(no) - int(prev_no)]
prev_word, prev_no = v.split('|')
ww = di... | /content/code_sandbox/wudao-dict/dict/dict_pys/en_decompress.py | python | 2016-07-04T11:09:37 | 2024-08-15T07:16:56 | Wudao-dict | ChestnutHeng/Wudao-dict | 1,126 | 368 |
```python
#coding=utf8
import json
import zlib
import sys
# build
f = open('dict.zlib.index','r')
dic = {}
lines = f.readlines()
prev_word, prev_no = lines[0].split('|')
for v in lines[1:]:
word, no = v.split('|')
dic[prev_word] = [int(prev_no), int(no) - int(prev_no)]
prev_word, prev_no = v.split('|')
... | /content/code_sandbox/wudao-dict/dict/dict_pys/zh_decompress.py | python | 2016-07-04T11:09:37 | 2024-08-15T07:16:56 | Wudao-dict | ChestnutHeng/Wudao-dict | 1,126 | 358 |
```python
#!/usr/bin/python3
import zlib
import json
def draw_text(word, fw, fi, wid):
# Word
word_test = word['word']
# pronunciation
phonetic = ""
if word['pronunciation']:
phonetic = word['pronunciation']
# paraphrase
paraphrase = json.dumps(word['paraphrase'])
# desc
... | /content/code_sandbox/wudao-dict/dict/dict_pys/zh_compress.py | python | 2016-07-04T11:09:37 | 2024-08-15T07:16:56 | Wudao-dict | ChestnutHeng/Wudao-dict | 1,126 | 314 |
```python
#!/usr/bin/python3
import zlib
import json
def draw_text(word, fw, fi, wid):
# Word
word_test = word['word']
# pronunciation
UK_phonetic = ""
US_phonetic = ""
unkown_phonetic = ""
if word['pronunciation']:
if '' in word['pronunciation']:
UK_phonetic = word['p... | /content/code_sandbox/wudao-dict/dict/dict_pys/en_compress.py | python | 2016-07-04T11:09:37 | 2024-08-15T07:16:56 | Wudao-dict | ChestnutHeng/Wudao-dict | 1,126 | 395 |
```python
import json
import sys
RED_PATTERN = '\033[31m%s\033[0m'
GREEN_PATTERN = '\033[32m%s\033[0m'
BLUE_PATTERN = '\033[34m%s\033[0m'
PEP_PATTERN = '\033[36m%s\033[0m'
BROWN_PATTERN = '\033[33m%s\033[0m'
def draw_text(word, conf):
# Word
print(RED_PATTERN % word['word'])
# pronunciation
if word['... | /content/code_sandbox/wudao-dict/dict/dict_pys/draw_cache.py | python | 2016-07-04T11:09:37 | 2024-08-15T07:16:56 | Wudao-dict | ChestnutHeng/Wudao-dict | 1,126 | 1,007 |
```python
import os
import sys
import json
mp = []
f = open(sys.argv[1], 'r')
lis = [x.strip() for x in f.readlines()]
f.close()
###
for fname in os.listdir('../dcache/'):
if ' ' in fname:
lis.append(fname)
###
for v in lis:
if not os.path.exists('../dcache/' + v):
if not os.path.exists('../b... | /content/code_sandbox/wudao-dict/dict/dict_pys/get_index_from_cache.py | python | 2016-07-04T11:09:37 | 2024-08-15T07:16:56 | Wudao-dict | ChestnutHeng/Wudao-dict | 1,126 | 164 |
```python
# -*- coding: utf-8 -*-
import socket
import time
class WudaoClient:
def __init__(self):
self.client = None
def connect(self):
# waiting for server init
self.client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
beats = 0
while True:
try:
... | /content/code_sandbox/wudao-dict/src/WudaoClient.py | python | 2016-07-04T11:09:37 | 2024-08-15T07:16:56 | Wudao-dict | ChestnutHeng/Wudao-dict | 1,126 | 257 |
```python
# -*- coding: utf-8 -*-
import zlib
import json
class JsonReader:
def __init__(self):
self.__main_dict = {}
self.FILE_NAME = './dict/en.z'
self.INDEX_FILE_NAME = './dict/en.ind'
self.ZH_FILE_NAME = './dict/zh.z'
self.ZH_INDEX_FILE_NAME = './dict/zh.ind'
sel... | /content/code_sandbox/wudao-dict/src/JsonReader.py | python | 2016-07-04T11:09:37 | 2024-08-15T07:16:56 | Wudao-dict | ChestnutHeng/Wudao-dict | 1,126 | 792 |
```python
__all__ = ["CommandDraw", "JsonReader", "UserHistory", "WudaoClient"]
``` | /content/code_sandbox/wudao-dict/src/__init__.py | python | 2016-07-04T11:09:37 | 2024-08-15T07:16:56 | Wudao-dict | ChestnutHeng/Wudao-dict | 1,126 | 23 |
```python
# -*- coding: utf-8 -*-
from __future__ import print_function
import os
class CommandDraw:
RED_PATTERN = '\033[31m%s\033[0m'
GREEN_PATTERN = '\033[32m%s\033[0m'
BLUE_PATTERN = '\033[34m%s\033[0m'
PEP_PATTERN = '\033[36m%s\033[0m'
BROWN_PATTERN = '\033[33m%s\033[0m'
@staticmethod
... | /content/code_sandbox/wudao-dict/src/CommandDraw.py | python | 2016-07-04T11:09:37 | 2024-08-15T07:16:56 | Wudao-dict | ChestnutHeng/Wudao-dict | 1,126 | 1,132 |
```python
# -*- coding: utf-8 -*-
class GuiDraw:
P_PATTERN = '<p>%s</p>'
RED_PATTERN = '<span style=\" font-size:12pt; font-weight:400; color:#FF0c32;\" > %s </span>'
GREEN_PATTERN = '<span style=\" font-size:12pt; font-weight:400; color:#5A9755;\" > %s </span>'
BLUE_PATTERN = '<span style=\" font-size... | /content/code_sandbox/wudao-dict/src/GuiDraw.py | python | 2016-07-04T11:09:37 | 2024-08-15T07:16:56 | Wudao-dict | ChestnutHeng/Wudao-dict | 1,126 | 1,345 |
```python
"""
soupselect.py
CSS selector support for BeautifulSoup.
soup = BeautifulSoup('<html>...')
select(soup, 'div')
- returns a list of div elements
select(soup, 'div#main ul a')
- returns a list of links inside a ul inside div#main
"""
import re
tag_re = re.compile('^[a-z0-9]+$')
attribselect_re = re.comp... | /content/code_sandbox/wudao-dict/src/soupselect.py | python | 2016-07-04T11:09:37 | 2024-08-15T07:16:56 | Wudao-dict | ChestnutHeng/Wudao-dict | 1,126 | 1,008 |
```python
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import json
class Confer:
CONF_FILE = './usr/config.json'
def __init__(self):
# Create empty file
if not os.path.exists(self.CONF_FILE):
with open(self.CONF_FILE, 'w+') as f:
tmp_dict = {}
... | /content/code_sandbox/wudao-dict/src/Confer.py | python | 2016-07-04T11:09:37 | 2024-08-15T07:16:56 | Wudao-dict | ChestnutHeng/Wudao-dict | 1,126 | 97 |
```python
# global functions
from urllib.request import urlopen
from urllib.parse import urlparse
from urllib.parse import quote
import os
import urllib.error
mon_ip = '119.28.128.77'
def get_ip():
if ie():
try:
res = urlopen('path_to_url timeout=1)
xml = res.read().decode('utf-8')... | /content/code_sandbox/wudao-dict/src/tools.py | python | 2016-07-04T11:09:37 | 2024-08-15T07:16:56 | Wudao-dict | ChestnutHeng/Wudao-dict | 1,126 | 403 |
```python
# -*- coding: utf-8 -*-
import bs4
from .soupselect import select as ss
from urllib.request import urlopen
from urllib.parse import urlparse
from urllib.parse import quote
def get_html(x):
x = quote(x)
url = urlparse('path_to_url % x)
res = urlopen(url.geturl(), timeout=1)
xml = res.read().... | /content/code_sandbox/wudao-dict/src/WudaoOnline.py | python | 2016-07-04T11:09:37 | 2024-08-15T07:16:56 | Wudao-dict | ChestnutHeng/Wudao-dict | 1,126 | 1,531 |
```python
# -*- coding: utf-8 -*-
import json
import os
class UserHistory:
MAX_LATEST_LEN = 100
MAX_CACHE_LEN = 10000
MAX_COUNT_LEN = 50000
content = {}
conf = {}
latest_word = []
DICT_FILE_NAME = './usr/usr_word.json'
LATEST_FILE_NAME = './usr/latest.txt'
ONLINE_CACHE = './usr/on... | /content/code_sandbox/wudao-dict/src/UserHistory.py | python | 2016-07-04T11:09:37 | 2024-08-15T07:16:56 | Wudao-dict | ChestnutHeng/Wudao-dict | 1,126 | 923 |
```shell
pyuic5 mainwindow.ui >../wudao-dict/mainwindow_ui.py
``` | /content/code_sandbox/wudao-gui/write_ui.sh | shell | 2016-07-04T11:09:37 | 2024-08-15T07:16:56 | Wudao-dict | ChestnutHeng/Wudao-dict | 1,126 | 19 |
```python
import bs4
from soupselect import select as ss
import json
import sys
from urllib.request import urlopen
from urllib.parse import urlparse
import urllib
def get_html(x):
url = urlparse('path_to_url % x)
res = urlopen(url.geturl())
xml = res.read().decode('utf-8')
return xml
def multi_sp... | /content/code_sandbox/soup/parse_colins.py | python | 2016-07-04T11:09:37 | 2024-08-15T07:16:56 | Wudao-dict | ChestnutHeng/Wudao-dict | 1,126 | 1,120 |
```python
import bs4
from soupselect import select as ss
from urllib.request import urlopen
from urllib.parse import urlparse
import urllib
import sys
import json
def get_html(x):
url = urlparse('path_to_url % urllib.parse.quote(x))
res = urlopen(url.geturl())
xml = res.read().decode('utf-8')
return x... | /content/code_sandbox/soup/chi_parse.py | python | 2016-07-04T11:09:37 | 2024-08-15T07:16:56 | Wudao-dict | ChestnutHeng/Wudao-dict | 1,126 | 733 |
```python
import bs4
from soupselect import select as ss
import json
import sys
from urllib.request import urlopen
from urllib.parse import urlparse
import urllib
def get_html(x):
url = urlparse('path_to_url % x)
res = urlopen(url.geturl())
xml = res.read().decode('utf-8')
return xml
def multi_sp... | /content/code_sandbox/soup/parse_21c.py | python | 2016-07-04T11:09:37 | 2024-08-15T07:16:56 | Wudao-dict | ChestnutHeng/Wudao-dict | 1,126 | 1,376 |
```objective-c
#pragma once
/*
* MULTI-CHANNEL SIGNED DISTANCE FIELD GENERATOR
* ---------------------------------------------
* A utility by Viktor Chlumsky, (c) 2014 - 2024
*
* The extension module provides ways to easily load input and save output using popular formats.
*
* Third party dependencies in exten... | /content/code_sandbox/msdfgen-ext.h | objective-c | 2016-04-24T13:03:47 | 2024-08-16T15:14:00 | msdfgen | Chlumsky/msdfgen | 3,862 | 191 |
```objective-c
#pragma once
/*
* MULTI-CHANNEL SIGNED DISTANCE FIELD GENERATOR
* ---------------------------------------------
* A utility by Viktor Chlumsky, (c) 2014 - 2024
*
* The technique used to generate multi-channel distance fields in this code
* has been developed by Viktor Chlumsky in 2014 for his mas... | /content/code_sandbox/msdfgen.h | objective-c | 2016-04-24T13:03:47 | 2024-08-16T15:14:00 | msdfgen | Chlumsky/msdfgen | 3,862 | 1,241 |
```batchfile
@echo off
setlocal
pushd "%~dp0"
if "%VCVARSALL%"=="" set "VCVARSALL=C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvarsall.bat"
if "%VCTOOLSET%"=="" set "VCTOOLSET=VC143"
if not exist "%VCVARSALL%" (
echo vcvarsall.bat not found, set VCVARSALL to its path
exit /b 1
... | /content/code_sandbox/build-release.bat | batchfile | 2016-04-24T13:03:47 | 2024-08-16T15:14:00 | msdfgen | Chlumsky/msdfgen | 3,862 | 1,233 |
```c++
#include "equation-solver.h"
#define _USE_MATH_DEFINES
#include <cmath>
namespace msdfgen {
int solveQuadratic(double x[2], double a, double b, double c) {
// a == 0 -> linear equation
if (a == 0 || fabs(b) > 1e12*fabs(a)) {
// a == 0, b == 0 -> no solution
if (b == 0) {
i... | /content/code_sandbox/core/equation-solver.cpp | c++ | 2016-04-24T13:03:47 | 2024-08-16T15:14:00 | msdfgen | Chlumsky/msdfgen | 3,862 | 679 |
```objective-c
#pragma once
#include "BitmapRef.hpp"
namespace msdfgen {
/// Saves the bitmap as an uncompressed floating-point TIFF file.
bool saveTiff(const BitmapConstRef<float, 1> &bitmap, const char *filename);
bool saveTiff(const BitmapConstRef<float, 3> &bitmap, const char *filename);
bool saveTiff(const Bit... | /content/code_sandbox/core/save-tiff.h | objective-c | 2016-04-24T13:03:47 | 2024-08-16T15:14:00 | msdfgen | Chlumsky/msdfgen | 3,862 | 92 |
```objective-c
#pragma once
#include "Vector2.hpp"
#include "Shape.h"
#include "Projection.h"
#include "Scanline.h"
#include "BitmapRef.hpp"
namespace msdfgen {
/// Rasterizes the shape into a monochrome bitmap.
void rasterize(const BitmapRef<float, 1> &output, const Shape &shape, const Projection &projection, Fill... | /content/code_sandbox/core/rasterization.h | objective-c | 2016-04-24T13:03:47 | 2024-08-16T15:14:00 | msdfgen | Chlumsky/msdfgen | 3,862 | 398 |
```objective-c
#pragma once
#include "Shape.h"
namespace msdfgen {
bool saveSvgShape(const Shape &shape, const char *filename);
bool saveSvgShape(const Shape &shape, const Shape::Bounds &bounds, const char *filename);
}
``` | /content/code_sandbox/core/export-svg.h | objective-c | 2016-04-24T13:03:47 | 2024-08-16T15:14:00 | msdfgen | Chlumsky/msdfgen | 3,862 | 51 |
```c++
#define _CRT_SECURE_NO_WARNINGS
#include "shape-description.h"
#include <cstdlib>
namespace msdfgen {
int readCharF(FILE *input) {
int c = '\0';
do {
c = fgetc(input);
} while (c == ' ' || c == '\t' || c == '\r' || c == '\n');
return c;
}
int readCharS(const char **input) {
int c... | /content/code_sandbox/core/shape-description.cpp | c++ | 2016-04-24T13:03:47 | 2024-08-16T15:14:00 | msdfgen | Chlumsky/msdfgen | 3,862 | 2,372 |
```objective-c
#pragma once
#include <vector>
#include "base.h"
namespace msdfgen {
/// Fill rule dictates how intersection total is interpreted during rasterization.
enum FillRule {
FILL_NONZERO,
FILL_ODD, // "even-odd"
FILL_POSITIVE,
FILL_NEGATIVE
};
/// Resolves the number of intersection into a... | /content/code_sandbox/core/Scanline.h | objective-c | 2016-04-24T13:03:47 | 2024-08-16T15:14:00 | msdfgen | Chlumsky/msdfgen | 3,862 | 342 |
```c++
#pragma once
#include <cmath>
#include "base.h"
namespace msdfgen {
/**
* A 2-dimensional euclidean floating-point vector.
* @author Viktor Chlumsky
*/
struct Vector2 {
double x, y;
inline Vector2(double val = 0) : x(val), y(val) { }
inline Vector2(double x, double y) : x(x), y(y) { }
... | /content/code_sandbox/core/Vector2.hpp | c++ | 2016-04-24T13:03:47 | 2024-08-16T15:14:00 | msdfgen | Chlumsky/msdfgen | 3,862 | 1,101 |
```objective-c
#pragma once
#include "Projection.h"
#include "DistanceMapping.h"
namespace msdfgen {
/**
* Full signed distance field transformation specifies both spatial transformation (Projection)
* as well as distance value transformation (DistanceMapping).
*/
class SDFTransformation : public Projection {
p... | /content/code_sandbox/core/SDFTransformation.h | objective-c | 2016-04-24T13:03:47 | 2024-08-16T15:14:00 | msdfgen | Chlumsky/msdfgen | 3,862 | 102 |
```objective-c
#pragma once
#include <vector>
#include "Contour.h"
#include "Scanline.h"
namespace msdfgen {
// Threshold of the dot product of adjacent edge directions to be considered convergent.
#define MSDFGEN_CORNER_DOT_EPSILON .000001
/// Vector shape representation.
class Shape {
public:
struct Bounds ... | /content/code_sandbox/core/Shape.h | objective-c | 2016-04-24T13:03:47 | 2024-08-16T15:14:00 | msdfgen | Chlumsky/msdfgen | 3,862 | 442 |
```objective-c
#pragma once
#include "base.h"
namespace msdfgen {
/// Edge color specifies which color channels an edge belongs to.
enum EdgeColor {
BLACK = 0,
RED = 1,
GREEN = 2,
YELLOW = 3,
BLUE = 4,
MAGENTA = 5,
CYAN = 6,
WHITE = 7
};
}
``` | /content/code_sandbox/core/EdgeColor.h | objective-c | 2016-04-24T13:03:47 | 2024-08-16T15:14:00 | msdfgen | Chlumsky/msdfgen | 3,862 | 83 |
```c++
#include "Projection.h"
namespace msdfgen {
Projection::Projection() : scale(1), translate(0) { }
Projection::Projection(const Vector2 &scale, const Vector2 &translate) : scale(scale), translate(translate) { }
Point2 Projection::project(const Point2 &coord) const {
return scale*(coord+translate);
}
Poi... | /content/code_sandbox/core/Projection.cpp | c++ | 2016-04-24T13:03:47 | 2024-08-16T15:14:00 | msdfgen | Chlumsky/msdfgen | 3,862 | 224 |
```c++
#include "ShapeDistanceFinder.h"
namespace msdfgen {
template <class ContourCombiner>
ShapeDistanceFinder<ContourCombiner>::ShapeDistanceFinder(const Shape &shape) : shape(shape), contourCombiner(shape), shapeEdgeCache(shape.edgeCount()) { }
template <class ContourCombiner>
typename ShapeDistanceFinder<Conto... | /content/code_sandbox/core/ShapeDistanceFinder.hpp | c++ | 2016-04-24T13:03:47 | 2024-08-16T15:14:00 | msdfgen | Chlumsky/msdfgen | 3,862 | 666 |
```objective-c
#pragma once
#include "BitmapRef.hpp"
#ifndef MSDFGEN_PUBLIC
#define MSDFGEN_PUBLIC // for DLL import/export
#endif
namespace msdfgen {
/// The configuration of the MSDF error correction pass.
struct ErrorCorrectionConfig {
/// The default value of minDeviationRatio.
static MSDFGEN_PUBLIC co... | /content/code_sandbox/core/generator-config.h | objective-c | 2016-04-24T13:03:47 | 2024-08-16T15:14:00 | msdfgen | Chlumsky/msdfgen | 3,862 | 633 |
```objective-c
#pragma once
#include "Vector2.hpp"
namespace msdfgen {
/// A transformation from shape coordinates to pixel coordinates.
class Projection {
public:
Projection();
Projection(const Vector2 &scale, const Vector2 &translate);
/// Converts the shape coordinate to pixel coordinate.
Point2... | /content/code_sandbox/core/Projection.h | objective-c | 2016-04-24T13:03:47 | 2024-08-16T15:14:00 | msdfgen | Chlumsky/msdfgen | 3,862 | 244 |
```objective-c
#pragma once
#include "Vector2.hpp"
#include "Range.hpp"
#include "BitmapRef.hpp"
namespace msdfgen {
/// Reconstructs the shape's appearance into output from the distance field sdf.
void renderSDF(const BitmapRef<float, 1> &output, const BitmapConstRef<float, 1> &sdf, Range sdfPxRange = 0, float sdT... | /content/code_sandbox/core/render-sdf.h | objective-c | 2016-04-24T13:03:47 | 2024-08-16T15:14:00 | msdfgen | Chlumsky/msdfgen | 3,862 | 381 |
```c++
#include "Shape.h"
#include <cstdlib>
#include "arithmetics.hpp"
#define DECONVERGE_OVERSHOOT 1.11111111111111111 // moves control points slightly more than necessary to account for floating-point errors
namespace msdfgen {
Shape::Shape() : inverseYAxis(false) { }
void Shape::addContour(const Contour &cont... | /content/code_sandbox/core/Shape.cpp | c++ | 2016-04-24T13:03:47 | 2024-08-16T15:14:00 | msdfgen | Chlumsky/msdfgen | 3,862 | 2,120 |
```c++
/*
* MULTI-CHANNEL SIGNED DISTANCE FIELD GENERATOR - standalone console program
* your_sha256_hash----------
* A utility by Viktor Chlumsky, (c) 2014 - 2024
*
*/
#ifdef MSDFGEN_STANDALONE
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include <cstdlib>
#include <cstdio>
#include <cmath>
#incl... | /content/code_sandbox/main.cpp | c++ | 2016-04-24T13:03:47 | 2024-08-16T15:14:00 | msdfgen | Chlumsky/msdfgen | 3,862 | 13,410 |
```objective-c
#pragma once
#include <cstdio>
#include "Shape.h"
namespace msdfgen {
/// Deserializes a text description of a vector shape into output.
bool readShapeDescription(FILE *input, Shape &output, bool *colorsSpecified = NULL);
bool readShapeDescription(const char *input, Shape &output, bool *colorsSpecifi... | /content/code_sandbox/core/shape-description.h | objective-c | 2016-04-24T13:03:47 | 2024-08-16T15:14:00 | msdfgen | Chlumsky/msdfgen | 3,862 | 99 |
```c++
#include "DistanceMapping.h"
namespace msdfgen {
DistanceMapping DistanceMapping::inverse(Range range) {
double rangeWidth = range.upper-range.lower;
return DistanceMapping(rangeWidth, range.lower/(rangeWidth ? rangeWidth : 1));
}
DistanceMapping::DistanceMapping() : scale(1), translate(0) { }
Dista... | /content/code_sandbox/core/DistanceMapping.cpp | c++ | 2016-04-24T13:03:47 | 2024-08-16T15:14:00 | msdfgen | Chlumsky/msdfgen | 3,862 | 160 |
```objective-c
#pragma once
#include "Vector2.hpp"
#include "SignedDistance.hpp"
#include "edge-segments.h"
namespace msdfgen {
struct MultiDistance {
double r, g, b;
};
struct MultiAndTrueDistance : MultiDistance {
double a;
};
/// Selects the nearest edge by its true distance.
class TrueDistanceSelector ... | /content/code_sandbox/core/edge-selectors.h | objective-c | 2016-04-24T13:03:47 | 2024-08-16T15:14:00 | msdfgen | Chlumsky/msdfgen | 3,862 | 661 |
```c++
#pragma once
#include "base.h"
namespace msdfgen {
/**
* Represents the range between two real values.
* For example, the range of representable signed distances.
*/
struct Range {
double lower, upper;
inline Range(double symmetricalWidth = 0) : lower(-.5*symmetricalWidth), upper(.5*symmetricalW... | /content/code_sandbox/core/Range.hpp | c++ | 2016-04-24T13:03:47 | 2024-08-16T15:14:00 | msdfgen | Chlumsky/msdfgen | 3,862 | 232 |
```objective-c
#pragma once
#include "BitmapRef.hpp"
namespace msdfgen {
/// Saves the bitmap as a simple RGBA file, which can be decoded trivially.
bool saveRgba(const BitmapConstRef<byte, 1> &bitmap, const char *filename);
bool saveRgba(const BitmapConstRef<byte, 3> &bitmap, const char *filename);
bool saveRgba(c... | /content/code_sandbox/core/save-rgba.h | objective-c | 2016-04-24T13:03:47 | 2024-08-16T15:14:00 | msdfgen | Chlumsky/msdfgen | 3,862 | 160 |
```c++
#define _CRT_SECURE_NO_WARNINGS
#include "save-tiff.h"
#include <cstdio>
#ifdef MSDFGEN_USE_CPP11
#include <cstdint>
#else
namespace msdfgen {
typedef int int32_t;
typedef unsigned uint32_t;
typedef unsigned short uint16_t;
typedef unsigned char uint8_t;
}
#endif
namespace msdfgen {
tem... | /content/code_sandbox/core/save-tiff.cpp | c++ | 2016-04-24T13:03:47 | 2024-08-16T15:14:00 | msdfgen | Chlumsky/msdfgen | 3,862 | 2,071 |
```c++
#pragma once
#include <cmath>
#include <cfloat>
#include "base.h"
namespace msdfgen {
/// Represents a signed distance and alignment, which together can be compared to uniquely determine the closest edge segment.
class SignedDistance {
public:
double distance;
double dot;
inline SignedDistance(... | /content/code_sandbox/core/SignedDistance.hpp | c++ | 2016-04-24T13:03:47 | 2024-08-16T15:14:00 | msdfgen | Chlumsky/msdfgen | 3,862 | 279 |
```c++
#include "edge-selectors.h"
#include "arithmetics.hpp"
namespace msdfgen {
#define DISTANCE_DELTA_FACTOR 1.001
TrueDistanceSelector::EdgeCache::EdgeCache() : absDistance(0) { }
void TrueDistanceSelector::reset(const Point2 &p) {
double delta = DISTANCE_DELTA_FACTOR*(p-this->p).length();
minDistance... | /content/code_sandbox/core/edge-selectors.cpp | c++ | 2016-04-24T13:03:47 | 2024-08-16T15:14:00 | msdfgen | Chlumsky/msdfgen | 3,862 | 2,320 |
```c++
#include "Bitmap.h"
#include <cstdlib>
#include <cstring>
namespace msdfgen {
template <typename T, int N>
Bitmap<T, N>::Bitmap() : pixels(NULL), w(0), h(0) { }
template <typename T, int N>
Bitmap<T, N>::Bitmap(int width, int height) : w(width), h(height) {
pixels = new T[N*w*h];
}
template <typename T... | /content/code_sandbox/core/Bitmap.hpp | c++ | 2016-04-24T13:03:47 | 2024-08-16T15:14:00 | msdfgen | Chlumsky/msdfgen | 3,862 | 806 |
```c++
#include "contour-combiners.h"
#include <cfloat>
#include "arithmetics.hpp"
namespace msdfgen {
static void initDistance(double &distance) {
distance = -DBL_MAX;
}
static void initDistance(MultiDistance &distance) {
distance.r = -DBL_MAX;
distance.g = -DBL_MAX;
distance.b = -DBL_MAX;
}
stat... | /content/code_sandbox/core/contour-combiners.cpp | c++ | 2016-04-24T13:03:47 | 2024-08-16T15:14:00 | msdfgen | Chlumsky/msdfgen | 3,862 | 1,207 |
```c++
#include "save-fl32.h"
#include <cstdio>
namespace msdfgen {
// Requires byte reversal for floats on big-endian platform
#ifndef __BIG_ENDIAN__
template <int N>
bool saveFl32(const BitmapConstRef<float, N> &bitmap, const char *filename) {
if (FILE *f = fopen(filename, "wb")) {
byte header[16] = ... | /content/code_sandbox/core/save-fl32.cpp | c++ | 2016-04-24T13:03:47 | 2024-08-16T15:14:00 | msdfgen | Chlumsky/msdfgen | 3,862 | 338 |
```objective-c
#pragma once
#include "Shape.h"
#include "edge-selectors.h"
namespace msdfgen {
/// Simply selects the nearest contour.
template <class EdgeSelector>
class SimpleContourCombiner {
public:
typedef EdgeSelector EdgeSelectorType;
typedef typename EdgeSelector::DistanceType DistanceType;
ex... | /content/code_sandbox/core/contour-combiners.h | objective-c | 2016-04-24T13:03:47 | 2024-08-16T15:14:00 | msdfgen | Chlumsky/msdfgen | 3,862 | 233 |
```c++
#include "rasterization.h"
#include <vector>
#include "arithmetics.hpp"
namespace msdfgen {
void rasterize(const BitmapRef<float, 1> &output, const Shape &shape, const Projection &projection, FillRule fillRule) {
Scanline scanline;
for (int y = 0; y < output.height; ++y) {
int row = shape.inv... | /content/code_sandbox/core/rasterization.cpp | c++ | 2016-04-24T13:03:47 | 2024-08-16T15:14:00 | msdfgen | Chlumsky/msdfgen | 3,862 | 1,236 |
```c++
#include "Contour.h"
#include "arithmetics.hpp"
namespace msdfgen {
static double shoelace(const Point2 &a, const Point2 &b) {
return (b.x-a.x)*(a.y+b.y);
}
void Contour::addEdge(const EdgeHolder &edge) {
edges.push_back(edge);
}
#ifdef MSDFGEN_USE_CPP11
void Contour::addEdge(EdgeHolder &&edge) {
... | /content/code_sandbox/core/Contour.cpp | c++ | 2016-04-24T13:03:47 | 2024-08-16T15:14:00 | msdfgen | Chlumsky/msdfgen | 3,862 | 854 |
```objective-c
#pragma once
#include "base.h"
namespace msdfgen {
// ax^2 + bx + c = 0
int solveQuadratic(double x[2], double a, double b, double c);
// ax^3 + bx^2 + cx + d = 0
int solveCubic(double x[3], double a, double b, double c, double d);
}
``` | /content/code_sandbox/core/equation-solver.h | objective-c | 2016-04-24T13:03:47 | 2024-08-16T15:14:00 | msdfgen | Chlumsky/msdfgen | 3,862 | 83 |
```c++
#include "sdf-error-estimation.h"
#include <cmath>
#include "arithmetics.hpp"
namespace msdfgen {
void scanlineSDF(Scanline &line, const BitmapConstRef<float, 1> &sdf, const Projection &projection, double y, bool inverseYAxis) {
if (!(sdf.width > 0 && sdf.height > 0))
return line.setIntersections... | /content/code_sandbox/core/sdf-error-estimation.cpp | c++ | 2016-04-24T13:03:47 | 2024-08-16T15:14:00 | msdfgen | Chlumsky/msdfgen | 3,862 | 2,487 |
```c++
#include "msdf-error-correction.h"
#include <vector>
#include "arithmetics.hpp"
#include "Bitmap.h"
#include "contour-combiners.h"
#include "MSDFErrorCorrection.h"
namespace msdfgen {
template <int N>
static void msdfErrorCorrectionInner(const BitmapRef<float, N> &sdf, const Shape &shape, const SDFTransforma... | /content/code_sandbox/core/msdf-error-correction.cpp | c++ | 2016-04-24T13:03:47 | 2024-08-16T15:14:00 | msdfgen | Chlumsky/msdfgen | 3,862 | 2,550 |
```c++
#pragma once
#include "base.h"
namespace msdfgen {
/// Reference to a 2D image bitmap or a buffer acting as one. Pixel storage not owned or managed by the object.
template <typename T, int N = 1>
struct BitmapRef {
T *pixels;
int width, height;
inline BitmapRef() : pixels(NULL), width(0), heigh... | /content/code_sandbox/core/BitmapRef.hpp | c++ | 2016-04-24T13:03:47 | 2024-08-16T15:14:00 | msdfgen | Chlumsky/msdfgen | 3,862 | 302 |
```objective-c
#pragma once
#include "Vector2.hpp"
#include "Range.hpp"
#include "Projection.h"
#include "SDFTransformation.h"
#include "Shape.h"
#include "BitmapRef.hpp"
#include "generator-config.h"
namespace msdfgen {
/// Predicts potential artifacts caused by the interpolation of the MSDF and corrects them by c... | /content/code_sandbox/core/msdf-error-correction.h | objective-c | 2016-04-24T13:03:47 | 2024-08-16T15:14:00 | msdfgen | Chlumsky/msdfgen | 3,862 | 855 |
```objective-c
#pragma once
#include "Shape.h"
#define MSDFGEN_EDGE_LENGTH_PRECISION 4
namespace msdfgen {
/** Assigns colors to edges of the shape in accordance to the multi-channel distance field technique.
* May split some edges if necessary.
* angleThreshold specifies the maximum angle (in radians) to be c... | /content/code_sandbox/core/edge-coloring.h | objective-c | 2016-04-24T13:03:47 | 2024-08-16T15:14:00 | msdfgen | Chlumsky/msdfgen | 3,862 | 292 |
```objective-c
#pragma once
#include "Vector2.hpp"
#include "Shape.h"
#include "Projection.h"
#include "Scanline.h"
#include "BitmapRef.hpp"
namespace msdfgen {
/// Analytically constructs a scanline at y evaluating fill by linear interpolation of the SDF.
void scanlineSDF(Scanline &line, const BitmapConstRef<float... | /content/code_sandbox/core/sdf-error-estimation.h | objective-c | 2016-04-24T13:03:47 | 2024-08-16T15:14:00 | msdfgen | Chlumsky/msdfgen | 3,862 | 625 |
```c++
#include "../msdfgen.h"
#include <vector>
#include "edge-selectors.h"
#include "contour-combiners.h"
#include "ShapeDistanceFinder.h"
namespace msdfgen {
template <typename DistanceType>
class DistancePixelConversion;
template <>
class DistancePixelConversion<double> {
DistanceMapping mapping;
public:
... | /content/code_sandbox/core/msdfgen.cpp | c++ | 2016-04-24T13:03:47 | 2024-08-16T15:14:00 | msdfgen | Chlumsky/msdfgen | 3,862 | 3,755 |
```c++
#pragma once
#include <cmath>
#include "base.h"
namespace msdfgen {
/// Returns the smaller of the arguments.
template <typename T>
inline T min(T a, T b) {
return b < a ? b : a;
}
/// Returns the larger of the arguments.
template <typename T>
inline T max(T a, T b) {
return a < b ? b : a;
}
/// Re... | /content/code_sandbox/core/arithmetics.hpp | c++ | 2016-04-24T13:03:47 | 2024-08-16T15:14:00 | msdfgen | Chlumsky/msdfgen | 3,862 | 430 |
```objective-c
#pragma once
#include "BitmapRef.hpp"
namespace msdfgen {
/// A 2D image bitmap with N channels of type T. Pixel memory is managed by the class.
template <typename T, int N = 1>
class Bitmap {
public:
Bitmap();
Bitmap(int width, int height);
Bitmap(const BitmapConstRef<T, N> &orig);
... | /content/code_sandbox/core/Bitmap.h | objective-c | 2016-04-24T13:03:47 | 2024-08-16T15:14:00 | msdfgen | Chlumsky/msdfgen | 3,862 | 308 |
```objective-c
#pragma once
#include "SDFTransformation.h"
#include "Shape.h"
#include "BitmapRef.hpp"
namespace msdfgen {
/// Performs error correction on a computed MSDF to eliminate interpolation artifacts. This is a low-level class, you may want to use the API in msdf-error-correction.h instead.
class MSDFError... | /content/code_sandbox/core/MSDFErrorCorrection.h | objective-c | 2016-04-24T13:03:47 | 2024-08-16T15:14:00 | msdfgen | Chlumsky/msdfgen | 3,862 | 517 |
```c++
#define _CRT_SECURE_NO_WARNINGS
#include "save-bmp.h"
#include <cstdio>
#ifdef MSDFGEN_USE_CPP11
#include <cstdint>
#else
namespace msdfgen {
typedef int int32_t;
typedef unsigned uint32_t;
typedef unsigned short uint16_t;
typedef unsigned char uint8_t;
}
#endif
#include "pixel-conversio... | /content/code_sandbox/core/save-bmp.cpp | c++ | 2016-04-24T13:03:47 | 2024-08-16T15:14:00 | msdfgen | Chlumsky/msdfgen | 3,862 | 1,414 |
```c++
#include "save-rgba.h"
#include <cstdio>
#include "pixel-conversion.hpp"
namespace msdfgen {
class RgbaFileOutput {
FILE *file;
public:
RgbaFileOutput(const char *filename, unsigned width, unsigned height) {
if ((file = fopen(filename, "wb"))) {
byte header[12] = { byte('R'), byt... | /content/code_sandbox/core/save-rgba.cpp | c++ | 2016-04-24T13:03:47 | 2024-08-16T15:14:00 | msdfgen | Chlumsky/msdfgen | 3,862 | 1,160 |
```objective-c
#pragma once
#include <vector>
#include "Vector2.hpp"
#include "edge-selectors.h"
#include "contour-combiners.h"
namespace msdfgen {
/// Finds the distance between a point and a Shape. ContourCombiner dictates the distance metric and its data type.
template <class ContourCombiner>
class ShapeDistance... | /content/code_sandbox/core/ShapeDistanceFinder.h | objective-c | 2016-04-24T13:03:47 | 2024-08-16T15:14:00 | msdfgen | Chlumsky/msdfgen | 3,862 | 260 |
```objective-c
#pragma once
#include "edge-segments.h"
namespace msdfgen {
/// Container for a single edge of dynamic type.
class EdgeHolder {
public:
/// Swaps the edges held by a and b.
static void swap(EdgeHolder &a, EdgeHolder &b);
inline EdgeHolder() : edgeSegment() { }
inline EdgeHolder(Edge... | /content/code_sandbox/core/EdgeHolder.h | objective-c | 2016-04-24T13:03:47 | 2024-08-16T15:14:00 | msdfgen | Chlumsky/msdfgen | 3,862 | 358 |
```objective-c
#pragma once
#include "BitmapRef.hpp"
namespace msdfgen {
/// Saves the bitmap as a BMP file.
bool saveBmp(const BitmapConstRef<byte, 1> &bitmap, const char *filename);
bool saveBmp(const BitmapConstRef<byte, 3> &bitmap, const char *filename);
bool saveBmp(const BitmapConstRef<byte, 4> &bitmap, const... | /content/code_sandbox/core/save-bmp.h | objective-c | 2016-04-24T13:03:47 | 2024-08-16T15:14:00 | msdfgen | Chlumsky/msdfgen | 3,862 | 152 |
```c++
#include "render-sdf.h"
#include "arithmetics.hpp"
#include "DistanceMapping.h"
#include "pixel-conversion.hpp"
#include "bitmap-interpolation.hpp"
namespace msdfgen {
static float distVal(float dist, DistanceMapping mapping) {
return (float) clamp(mapping(dist)+.5);
}
void renderSDF(const BitmapRef<flo... | /content/code_sandbox/core/render-sdf.cpp | c++ | 2016-04-24T13:03:47 | 2024-08-16T15:14:00 | msdfgen | Chlumsky/msdfgen | 3,862 | 2,317 |
```c++
#include "EdgeHolder.h"
namespace msdfgen {
void EdgeHolder::swap(EdgeHolder &a, EdgeHolder &b) {
EdgeSegment *tmp = a.edgeSegment;
a.edgeSegment = b.edgeSegment;
b.edgeSegment = tmp;
}
EdgeHolder::EdgeHolder(const EdgeHolder &orig) : edgeSegment(orig.edgeSegment ? orig.edgeSegment->clone() : NUL... | /content/code_sandbox/core/EdgeHolder.cpp | c++ | 2016-04-24T13:03:47 | 2024-08-16T15:14:00 | msdfgen | Chlumsky/msdfgen | 3,862 | 354 |
```c++
#include "Scanline.h"
#include <cstdlib>
#include "arithmetics.hpp"
namespace msdfgen {
static int compareIntersections(const void *a, const void *b) {
return sign(reinterpret_cast<const Scanline::Intersection *>(a)->x-reinterpret_cast<const Scanline::Intersection *>(b)->x);
}
bool interpretFillRule(int... | /content/code_sandbox/core/Scanline.cpp | c++ | 2016-04-24T13:03:47 | 2024-08-16T15:14:00 | msdfgen | Chlumsky/msdfgen | 3,862 | 1,017 |
```c++
#include "export-svg.h"
#include <cstdio>
#include "edge-segments.h"
namespace msdfgen {
static void writeSvgCoord(FILE *f, Point2 coord) {
fprintf(f, "%.17g %.17g", coord.x, coord.y);
}
static void writeSvgPathDef(FILE *f, const Shape &shape) {
bool beginning = true;
for (const Contour &c : sha... | /content/code_sandbox/core/export-svg.cpp | c++ | 2016-04-24T13:03:47 | 2024-08-16T15:14:00 | msdfgen | Chlumsky/msdfgen | 3,862 | 607 |
```objective-c
#pragma once
#include "BitmapRef.hpp"
namespace msdfgen {
/// Saves the bitmap as an uncompressed floating-point FL32 file, which can be decoded trivially.
template <int N>
bool saveFl32(const BitmapConstRef<float, N> &bitmap, const char *filename);
}
``` | /content/code_sandbox/core/save-fl32.h | objective-c | 2016-04-24T13:03:47 | 2024-08-16T15:14:00 | msdfgen | Chlumsky/msdfgen | 3,862 | 62 |
```c++
#pragma once
#include "arithmetics.hpp"
#include "Vector2.hpp"
#include "BitmapRef.hpp"
namespace msdfgen {
template <typename T, int N>
static void interpolate(T *output, const BitmapConstRef<T, N> &bitmap, Point2 pos) {
pos -= .5;
int l = (int) floor(pos.x);
int b = (int) floor(pos.y);
int ... | /content/code_sandbox/core/bitmap-interpolation.hpp | c++ | 2016-04-24T13:03:47 | 2024-08-16T15:14:00 | msdfgen | Chlumsky/msdfgen | 3,862 | 222 |
```objective-c
#pragma once
#include <vector>
#include "EdgeHolder.h"
namespace msdfgen {
/// A single closed contour of a shape.
class Contour {
public:
/// The sequence of edges that make up the contour.
std::vector<EdgeHolder> edges;
/// Adds an edge to the contour.
void addEdge(const EdgeHolde... | /content/code_sandbox/core/Contour.h | objective-c | 2016-04-24T13:03:47 | 2024-08-16T15:14:00 | msdfgen | Chlumsky/msdfgen | 3,862 | 246 |
```c++
#pragma once
#include "arithmetics.hpp"
namespace msdfgen {
inline byte pixelFloatToByte(float x) {
return byte(~int(255.5f-255.f*clamp(x)));
}
inline float pixelByteToFloat(byte x) {
return 1.f/255.f*float(x);
}
}
``` | /content/code_sandbox/core/pixel-conversion.hpp | c++ | 2016-04-24T13:03:47 | 2024-08-16T15:14:00 | msdfgen | Chlumsky/msdfgen | 3,862 | 68 |
```objective-c
#pragma once
#include "Vector2.hpp"
#include "SignedDistance.hpp"
#include "EdgeColor.h"
namespace msdfgen {
// Parameters for iterative search of closest point on a cubic Bezier curve. Increase for higher precision.
#define MSDFGEN_CUBIC_SEARCH_STARTS 4
#define MSDFGEN_CUBIC_SEARCH_STEPS 4
/// An a... | /content/code_sandbox/core/edge-segments.h | objective-c | 2016-04-24T13:03:47 | 2024-08-16T15:14:00 | msdfgen | Chlumsky/msdfgen | 3,862 | 1,342 |
```c++
#include "edge-coloring.h"
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <cfloat>
#include <vector>
#include <queue>
#include "arithmetics.hpp"
namespace msdfgen {
/**
* For each position < n, this function will return -1, 0, or 1,
* depending on whether the position is closer to the begi... | /content/code_sandbox/core/edge-coloring.cpp | c++ | 2016-04-24T13:03:47 | 2024-08-16T15:14:00 | msdfgen | Chlumsky/msdfgen | 3,862 | 5,356 |
```objective-c
#pragma once
#include "Range.hpp"
namespace msdfgen {
/// Linear transformation of signed distance values.
class DistanceMapping {
public:
/// Explicitly designates value as distance delta rather than an absolute distance.
class Delta {
public:
double value;
inline explic... | /content/code_sandbox/core/DistanceMapping.h | objective-c | 2016-04-24T13:03:47 | 2024-08-16T15:14:00 | msdfgen | Chlumsky/msdfgen | 3,862 | 161 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.